Back to blog

Kubernetes in Production: Databases, HTTPS, and Autoscaling

Your first container is running in your managed Kubernetes namespace. A Deployment, a Service, an HTTPRoute, done. But a production-ready application needs more: a database, HTTPS with automatic certificates, and persistent storage, and it has to be able to scale under load.

On a self-managed cluster, that means installing and maintaining several operators and controllers yourself. On an ITSH namespace, it’s a few YAML files.

The examples assume a paid namespace: custom domains and block storage are not available on the free tier.

Automatic HTTPS with Let’s Encrypt

On a self-managed cluster, the path to HTTPS looks like this: install cert-manager, configure a ClusterIssuer, adjust the ingress controller, debug annotations. On ITSH, cert-manager is already installed and preconfigured. You add one annotation to your HTTPRoute to opt in to automatic TLS:

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: myapp
  annotations:
    cert-manager.io/cluster-issuer: "auto"
spec:
  parentRefs:
    - name: default
      namespace: nginx-gateway
      sectionName: https-myapp-example-com
  hostnames:
    - "myapp.example.com"
  rules:
    - backendRefs:
        - name: myapp
          port: 80

The TLS certificate is issued and renewed automatically.

The annotation is purely an opt-in: the controller that creates the gateway listeners only checks whether it is present. Its value does not select an issuer. Which ClusterIssuer signs your certificates is determined by the annotation on the Gateway itself.

Redirecting HTTP to HTTPS

To automatically redirect HTTP requests to HTTPS, add a second HTTPRoute:

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: myapp-redirect
spec:
  parentRefs:
    - name: default
      namespace: nginx-gateway
      sectionName: http
  hostnames:
    - "myapp.example.com"
  rules:
    - filters:
        - type: RequestRedirect
          requestRedirect:
            scheme: https
            statusCode: 301
      backendRefs: []

DNS Setup

A hostname under your namespace’s subdomain needs no DNS record: it resolves as soon as the route exists. DNS only becomes your job with a custom domain. You add it in the portal first and prove that it is yours. Then you point your domain at the gateway. If the domain’s DNS is managed at ITSH, switch on Auto-DNS for it in the portal, and the records are created from your HTTPRoutes. For a domain managed elsewhere, the addresses for the A and AAAA records are listed under Gateway API.

The gateway sets X-Forwarded-For and X-Real-IP with the original client IP. Configure your application to accept those headers only when the connection comes from the gateway, that is, from a private address inside the cluster. If it accepts them from any sender, clients can spoof their own IP.

Databases in Kubernetes: PostgreSQL, MariaDB, and Redis-Compatible Cache

PostgreSQL with CloudNativePG

CloudNativePG runs on the cluster and manages PostgreSQL instances as a Kubernetes resource. Creating a database:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: myapp-db
spec:
  instances: 1
  storage:
    size: 10Gi
    storageClass: hcloud-volumes
  postgresql:
    parameters:
      max_connections: "100"

A dozen lines of YAML for a working PostgreSQL instance. You don’t have to install the operator. The example is a starting point, not a production setup: a single instance with no backup. For production, set instances to 3 and set up a backup to an S3 bucket. The docs show how.

The operator automatically creates a secret called myapp-db-app containing the connection string. Reference it directly in your Deployment:

env:
  - name: DATABASE_URL
    valueFrom:
      secretKeyRef:
        name: myapp-db-app
        key: uri

Redis-Compatible Cache with Dragonfly

For caching or session storage:

apiVersion: dragonflydb.io/v1alpha1
kind: Dragonfly
metadata:
  name: myapp-cache
spec:
  replicas: 1
  resources:
    requests:
      cpu: 100m
      memory: 128Mi
    limits:
      cpu: 500m
      memory: 512Mi

Reachable at redis://myapp-cache:6379. Dragonfly speaks the Redis wire protocol, so most existing Redis clients work unchanged. There are documented behavioral differences in individual commands, so test your application before migrating.

MariaDB is also available as a database option if your application requires MySQL compatibility.

Persistent Storage and Object Storage

Block Storage for Databases and Single-Pod Apps

For workloads that need fast, dedicated storage:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myapp-data
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: hcloud-volumes
  resources:
    requests:
      storage: 20Gi

hcloud-volumes provides block storage from Hetzner Cloud. The storage class is available in paid namespaces only. On the free tier, use nfs-rwx. Volumes can also grow automatically when usage grows. For multi-pod scenarios with a shared filesystem, NFS storage (ReadWriteMany) is also available.

S3 Object Storage

You get the bucket and access key from ITSH Object Storage; endpoint and regions are in the documentation. For S3-compatible object storage, create a secret with your credentials and reference it in your deployment:

env:
  - name: S3_ENDPOINT
    valueFrom:
      secretKeyRef:
        name: s3-credentials
        key: endpoint
  - name: S3_BUCKET
    valueFrom:
      secretKeyRef:
        name: s3-credentials
        key: bucket
  - name: AWS_ACCESS_KEY_ID
    valueFrom:
      secretKeyRef:
        name: s3-credentials
        key: access_key
  - name: AWS_SECRET_ACCESS_KEY
    valueFrom:
      secretKeyRef:
        name: s3-credentials
        key: secret_key

Works with any S3-compatible SDK: AWS SDK, MinIO client, Boto3. Ideal for uploads, media files, and backups.

Autoscaling

Horizontal Pod Autoscaler

For scaling on CPU load, an HPA is all it takes:

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: myapp
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70

At 70% CPU utilization, Kubernetes automatically scales up, to a maximum of 10 replicas. When load drops, it scales back down.

Where CPU utilization is not the right signal, such as queue length or fixed schedules, you create a ScaledObject or ScaledJob with KEDA (Kubernetes Event-Driven Autoscaling). Examples for HPA, KEDA, and VPA are under Autoscaling.

An HTTP service can also drop to 0 replicas when nothing calls it. While it sleeps, you pay nothing for CPU and memory. You switch this on with an annotation on the HTTPRoute, see Scale-to-zero. It cannot be combined with an HPA on the same workload.

Storage Autoscaling

If your database grows beyond its initial size, three annotations on the PVC expand the volume automatically:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myapp-data
  annotations:
    resize.topolvm.io/threshold: "20%"
    resize.topolvm.io/increase: "10Gi"
    resize.topolvm.io/storage_limit: "100Gi"
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: hcloud-volumes
  resources:
    requests:
      storage: 10Gi

storage_limit is what switches expansion on: without it, the volume never grows. threshold is a free space threshold, not a utilization threshold. Expansion kicks in once less than 20% is free, meaning the volume is more than 80% full. It then grows by 10 GiB, up to the limit you set. This works for standalone PVCs and database volumes (CloudNativePG, MariaDB).

With "80%", expansion would start as soon as the volume is 20% full. It would then grow step by step to the limit, and you pay for that storage.

You are billed for the provisioned size, with a minimum of 10 GiB per volume. What that adds up to per month is worked through in What Does Kubernetes Cost for Small Businesses?. Volumes can only grow, never shrink. Like block storage itself, autoresize requires hcloud-volumes and is therefore available in paid namespaces only.

Resource Recommendations with the Vertical Pod Autoscaler

A VPA in recommendation-only mode watches how much CPU and memory your app actually needs and provides recommendations without changing anything:

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: myapp
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  updatePolicy:
    updateMode: "Off"
# After a few minutes: check recommendations
kubectl describe vpa myapp -n my-namespace

You apply the recommendations to your Deployment yourself.

Putting It All Together: A Production-Ready Platform

Say you’re running a SaaS application with an API, background worker, and web frontend.

What runs in your namespace:

  • API Deployment with HPA (2 to 10 replicas depending on load)
  • Worker Deployment for async jobs
  • PostgreSQL via CloudNativePG for the primary database
  • Dragonfly as session and cache layer
  • S3 bucket for user uploads and media
  • HTTPRoute with automatic TLS certificate

What you don’t manage:

  • Cluster updates and node patches
  • cert-manager, gateway controller, monitoring stack
  • Database operators and storage provisioning
  • Network policies and security patches

The portal and kubectl show logs as the container currently holds them. They are not archived, so a log history is something you set up yourself.

You can switch on GitOps per namespace in the portal. ArgoCD then applies what is in your repository: a git push rolls out changes, a git revert takes them back. The repository has to be readable without credentials, see Deploying from Git.

Conclusion

Databases, HTTPS, storage, and autoscaling are plain Kubernetes resources in your namespace, created from YAML. ITSH runs the cluster, the operators, and the updates, and you look after your application.

Configure a namespace and calculate the price

First deployment in the docs