Skip to content

Quickstart — DNS Mode

Log in to GHCR with a token that has read:packages scope, piping the token on stdin rather than passing it as an argument (avoids it landing in shell history or the process list):

Terminal window
echo "<your-token>" | helm registry login ghcr.io --username <your-github-username> --password-stdin

Create a kubernetes.io/dockerconfigjson Secret from that same login, in the same namespace you install the chart into, and pass it through the chart's existingimagePullSecrets value:

Terminal window
kubectl create secret docker-registry your-pull-secret \
--docker-server=ghcr.io \
--docker-username=<your-github-username> \
--docker-password=<your-token> \
--namespace <your-release-namespace>
imagePullSecrets: [{name: your-pull-secret}]

or, as a Helm --set flag (quoted, since the brackets are otherwise a glob pattern in zsh): --set 'imagePullSecrets[0].name=your-pull-secret'.

Expose a Kubernetes Service through a standard public LoadBalancer and Envoy Gateway’s data plane, with Cloudflare DNS records and Let’s Encrypt certificates managed automatically. This walkthrough is runnable as written against a real Cloudflare account, a zone you control, and a cluster with a working LoadBalancer implementation — a cloud provider’s, or MetalLB on bare-metal/local clusters (see the callout below).

  • A Kubernetes cluster, version 1.28 or later, with Gateway API v1.6.0’s standard CRDs installed:

    Terminal window
    kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.6.0/standard-install.yaml
  • cert-manager, tested against v1.21.3 (see Compatibility for the full tested-version matrix). Install this before the controller (below), not after:

    Terminal window
    kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.21.3/cert-manager.yaml
    kubectl wait --for=condition=Available --timeout=120s deployment --all -n cert-manager

    On GKE Autopilot specifically, this stock manifest fails permanently instead: it hardcodes --leader-election-namespace=kube-system (plus matching RBAC) on the controller and cainjector, and Autopilot’s admission policy denies writes to kube-system for anything but Google-managed components, so cainjector never acquires its lease, never injects the webhook’s CA bundle, and every object creation through the webhook fails with x509: certificate signed by unknown authority indefinitely. Fix it before applying: replace every kube-system reference in the manifest with cert-manager first (e.g. curl -sSL <url> | sed 's/kube-system/cert-manager/g' | kubectl apply -f -).

    The controller checks once, at its own startup, whether cert-manager’s Certificate CRD is registered on the cluster, and keeps that answer for its whole process lifetime — this is deliberate, since it’s what lets the controller start at all on a cluster with no cert-manager (Tunnel Mode has no such dependency). If you install cert-manager after the controller, it won’t notice until you restart it:

    Terminal window
    kubectl rollout restart deployment/cloudflare-gateway-controller \
    -n cloudflare-gateway-controller-system
  • Envoy Gateway, a separate install this project does not manage (the companion pattern — DNS Mode’s GatewayClass and data plane belong entirely to Envoy Gateway, not this controller), configured to recognize this controller’s Gateways:

    1. Gateway API v1.6.0’s standard CRDs (already applied above).

    2. Envoy Gateway v1.8.2’s own CRDs, applied server-side (its EnvoyProxy CRD alone exceeds kubectl apply’s default client-side size limit):

      Terminal window
      kubectl apply --server-side -f https://github.com/envoyproxy/gateway/releases/download/v1.8.2/envoy-gateway-crds.yaml
    3. The Envoy Gateway Helm chart itself, with its own bundled CRDs disabled (step 2 already installed the ones that matter) and its controller name set to the value this project’s DNS-mode reconciler watches for:

      Terminal window
      helm upgrade --install eg oci://docker.io/envoyproxy/gateway-helm --version 1.8.2 \
      -n envoy-gateway-system --create-namespace \
      --set crds.enabled=false \
      --set config.envoyGateway.gateway.controllerName=cfgateway.dreamfuselabs.com/dns-controller
      kubectl -n envoy-gateway-system rollout status deploy/envoy-gateway --timeout=180s
  • A working LoadBalancer implementation on your cluster (a cloud provider’s, or MetalLB — see the callout below for a local kind cluster).

  • A Cloudflare account and a zone (domain) you control.

  • Two Cloudflare API tokens — this project’s own controller and cert-manager’s DNS-01 solver never share one (see Credentials and Secrets for why):

    • The controller’s own, scoped per Token Scopes’s DNS Mode table (Zone / DNS: Edit, Zone / Zone: Read, scoped to your account and zone).
    • A second, separate one for cert-manager’s own ClusterIssuer — see cert-manager’s own token for the exact permission set (the same scope as the controller’s own, in DNS Mode).

Then install the chart itself:

  1. Create the namespace:

    Terminal window
    kubectl create namespace cloudflare-gateway-controller-system
  2. Create the pull Secret in it (the image and chart are private artifacts; there’s no anonymous install path):

    Terminal window
    kubectl create secret docker-registry ghcr-pull \
    --docker-server=ghcr.io \
    --docker-username=<your-github-username> \
    --docker-password=<a token with read:packages scope> \
    --namespace cloudflare-gateway-controller-system
  3. Install the chart from GHCR:

    Terminal window
    helm install cloudflare-gateway-controller oci://ghcr.io/dreamfuse-labs/charts/cloudflare-gateway-controller --version 0.4.0 --namespace cloudflare-gateway-controller-system --set 'imagePullSecrets[0].name=ghcr-pull'
    kubectl rollout status deployment/cloudflare-gateway-controller -n cloudflare-gateway-controller-system

Set ZONE=yourdomain.com, ACCOUNT_ID=<your Cloudflare account ID>, CF_API_TOKEN=<the controller's token above>, and CERT_MANAGER_API_TOKEN=<cert-manager's token above> in your shell for the steps below.

  1. Once for this project’s own controller, once for cert-manager’s DNS-01 solver, each from its own token — see Credentials and Secrets for why cert-manager needs its own copy, in its own namespace, as a separate token from the controller’s own (see cert-manager’s own token for the exact permission set) — never a copy of the controller’s own token, even though they happen to need the same scope here.

    Terminal window
    kubectl create secret generic cloudflare-api-token \
    --namespace cloudflare-gateway-controller-system \
    --from-literal=api-token="$CF_API_TOKEN"
    kubectl create secret generic cloudflare-api-token \
    --namespace cert-manager \
    --from-literal=api-token="$CERT_MANAGER_API_TOKEN"
  2. Create a ClusterIssuer for Let’s Encrypt via Cloudflare DNS-01

    Section titled “Create a ClusterIssuer for Let’s Encrypt via Cloudflare DNS-01”

    Use a real, non-blocklisted contact domain — Let’s Encrypt rejects registration for example.com/.org/.net. $ZONE (a domain you actually control) works.

    Terminal window
    cat <<EOF | kubectl apply -f -
    apiVersion: cert-manager.io/v1
    kind: ClusterIssuer
    metadata:
    name: letsencrypt
    spec:
    acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    email: admin@$ZONE
    privateKeySecretRef:
    name: letsencrypt-key
    solvers:
    - dns01:
    cloudflare:
    apiTokenSecretRef:
    name: cloudflare-api-token
    key: api-token
    selector:
    dnsZones: ["$ZONE"]
    EOF

    Swap in https://acme-staging-v02.api.letsencrypt.org/directory while testing, to avoid Let’s Encrypt’s production rate limits — the staging server issues certificates no browser trusts, but it’s the right choice for working through this quickstart itself. If you do, add -k to the plain curl in the Verify step below too — without it, curl rejects the staging certificate’s unknown issuer and exits 60, even though everything else worked.

  3. Unlike Tunnel Mode, DNS Mode’s GatewayClass.parametersRef belongs entirely to Envoy Gateway, so this configuration attaches to a Gateway via targetRefs instead:

    Terminal window
    cat <<EOF | kubectl apply -f -
    apiVersion: cfgateway.dreamfuselabs.com/v1alpha1
    kind: CloudflareGatewayConfiguration
    metadata:
    name: dns-config
    spec:
    mode: dns
    accountID: "$ACCOUNT_ID"
    zoneAllowlist: ["$ZONE"]
    credentialSecretRef:
    namespace: cloudflare-gateway-controller-system
    name: cloudflare-api-token
    key: api-token
    dnsDefaults:
    proxied: false
    issuerRef:
    name: letsencrypt
    kind: ClusterIssuer
    targetRefs:
    - group: gateway.networking.k8s.io
    kind: Gateway
    name: my-gateway
    namespace: default
    EOF
    kubectl wait cloudflaregatewayconfiguration/dns-config \
    --for=condition=Accepted --timeout=30s
  4. Envoy Gateway itself claims this class — this project’s own reconciler only manages the Cloudflare side (DNS records and certificates) for Gateways that use it.

    Terminal window
    cat <<EOF | kubectl apply -f -
    apiVersion: gateway.networking.k8s.io/v1
    kind: GatewayClass
    metadata:
    name: cloudflare-dns
    spec:
    controllerName: cfgateway.dreamfuselabs.com/dns-controller
    EOF
    kubectl wait gatewayclass/cloudflare-dns --for=condition=Accepted --timeout=60s
  5. Terminal window
    cat <<EOF | kubectl apply -f -
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: echo
    spec:
    replicas: 1
    selector:
    matchLabels: {app: echo}
    template:
    metadata:
    labels: {app: echo}
    spec:
    containers:
    - name: echo
    image: hashicorp/http-echo:1.0.0
    args: ["-listen=:8080", "-text=hello from dns mode"]
    ports: [{containerPort: 8080}]
    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: echo
    spec:
    selector: {app: echo}
    ports: [{port: 80, targetPort: 8080}]
    EOF
    kubectl rollout status deployment/echo --timeout=60s
    cat <<EOF | kubectl apply -f -
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
    name: my-gateway
    spec:
    gatewayClassName: cloudflare-dns
    listeners:
    - name: http
    protocol: HTTP
    port: 80
    hostname: "app.$ZONE"
    - name: https
    protocol: HTTPS
    port: 443
    hostname: "app.$ZONE"
    tls:
    certificateRefs:
    - name: app-tls
    ---
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
    name: echo-route
    spec:
    parentRefs:
    - name: my-gateway
    rules:
    - backendRefs:
    - name: echo
    port: 80
    EOF

    (Note: kubectl create deployment ... -- <args> sets the container’s command, overriding hashicorp/http-echo’s own entrypoint entirely rather than appending flags to it — this is why the example above uses a plain YAML Deployment with args: instead, which appends to the entrypoint the way http-echo expects its flags.)

    Envoy Gateway owns Gateway.status entirely in this mode — wait for it directly:

    Terminal window
    kubectl wait gateway/my-gateway --for=condition=Accepted --timeout=60s
    kubectl wait gateway/my-gateway --for=condition=Programmed --timeout=120s

    Then wait for the address it assigns (a real cloud LB, or a MetalLB-assigned address) to propagate through this project’s own auto-created CloudflareDNSRecord, and for the auto-created Certificate to issue (both are named deterministically from the Gateway name and listener hostname):

    Terminal window
    kubectl wait "$(kubectl get cloudflarednsrecord -o name)" --for=condition=Synced --timeout=60s
    kubectl wait "$(kubectl get certificate -o name)" --for=condition=Ready --timeout=180s
  6. Terminal window
    curl -sf "https://app.$ZONE"

    Should print hello from dns mode. Check kubectl get cloudflaregatewaystatus for this project’s own Cloudflare-side readiness signal — distinct from Gateway.status, which stays entirely Envoy Gateway’s.

Terminal window
kubectl delete httproute echo-route
kubectl delete gateway my-gateway
kubectl delete deployment,service echo
kubectl delete gatewayclass cloudflare-dns
# Wait for the owned CloudflareDNSRecord's Kubernetes garbage collection to actually finish
# (it has its own finalizer that deletes the real Cloudflare-side record first) before deleting
# the configuration it authenticates through.
for i in $(seq 1 30); do [ -z "$(kubectl get cloudflarednsrecord -o name 2>/dev/null)" ] && break; sleep 2; done
kubectl delete cloudflaregatewayconfiguration dns-config
kubectl delete clusterissuer letsencrypt
kubectl delete secret cloudflare-api-token -n cloudflare-gateway-controller-system
kubectl delete secret cloudflare-api-token -n cert-manager

That wait matters: deleting the Gateway deletes the HTTPRoute’s target and the auto-created CloudflareDNSRecord starts an asynchronous delete of its own — Kubernetes garbage-collects an owned object only after its owner is gone, and the object’s own finalizer then calls the real Cloudflare delete API. Deleting dns-config before that finishes hits a deliberate tradeoff: if the CloudflareDNSRecord can no longer resolve its configuration by the time its own deletion runs, there’s no credential left to authenticate a delete call, so its finalizer is removed anyway rather than leaving the object stuck forever — and the real Cloudflare-side record is orphaned, needing manual cleanup. The for loop above closes that race.

This quickstart uses dnsDefaults.proxied: false — a DNS-only record pointing straight at your LoadBalancer’s address — deliberately, so it works end-to-end regardless of whether you’re running on a local kind cluster or a real cloud one. Set it true instead to route traffic through Cloudflare’s edge (orange-cloud), but only on a cluster with a genuinely public LoadBalancer address: Cloudflare’s API refuses to create a proxied record targeting a private IP (error 9003), and a local kind+MetalLB cluster’s LoadBalancer address is always private (Docker’s own VM-based networking model, not a kind-specific limitation) — there, proxied: true reaches Accepted=True but never Synced=True, no matter how long you wait.

  • Routing — configure routes with HTTPRoute and GRPCRoute.
  • Credentials and Secrets — rotate tokens, use GitOps, and scope who can manage a CloudflareGatewayConfiguration.
  • Access — protect a hostname with Cloudflare Access, identity providers, and service tokens.