Kitloft

All tools / Kubernetes examples

Caddy reverse proxy on Kubernetes

Caddy as an in-cluster reverse proxy in front of another Service, with its Caddyfile in a ConfigMap.

Customize names, versions →

caddy.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: caddy-config
  namespace: default
data:
  Caddyfile: |
    {
        auto_https off
        admin off
    }
    :80 {
        encode zstd gzip
        respond /healthz "ok" 200
        reverse_proxy my-app:8080
    }
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: caddy
  namespace: default
  labels:
    app: caddy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: caddy
  template:
    metadata:
      labels:
        app: caddy
    spec:
      containers:
        - name: caddy
          image: caddy:2.10
          ports:
            - name: http
              containerPort: 80
          readinessProbe:
            httpGet:
              path: /healthz
              port: http
          resources:
            requests:
              cpu: 50m
              memory: 32Mi
            limits:
              memory: 128Mi
          volumeMounts:
            - name: config
              mountPath: /etc/caddy
      volumes:
        - name: config
          configMap:
            name: caddy-config
---
apiVersion: v1
kind: Service
metadata:
  name: caddy
  namespace: default
spec:
  selector:
    app: caddy
  ports:
    - name: http
      port: 80
      targetPort: http

How to use it

Commands
kubectl apply -f caddy.yaml
kubectl -n default get pods -w

Prefer Docker Compose? See the Caddy reverse proxy Docker Compose version.