Skip to content

Quickstart — Tunnel 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 on a real public hostname through Cloudflare Tunnel — no public LoadBalancer, no open ingress port. This walkthrough is runnable as written against a real Cloudflare account and a zone you control.

  • A Kubernetes cluster, version 1.28 or later — otherwise any; Tunnel Mode has no LoadBalancer or CNI requirement — 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
  • A Cloudflare account and a zone (domain) you control.

  • A Cloudflare API token scoped per Token Scopes’s Tunnel Mode table (Account / Cloudflare Tunnel: Edit, Zone / DNS: Edit, Zone / Zone: Read, Zone / SSL and Certificates: Read, scoped to your account and zone).

Set ZONE=yourdomain.com, ACCOUNT_ID=<your Cloudflare account ID>, and CF_API_TOKEN=<the token above> in your shell for the steps below.

  1. Create the namespace, create a pull Secret for the private GHCR image and chart, and install:

    Terminal window
    kubectl create namespace cloudflare-gateway-controller-system
    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
    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
  2. Terminal window
    kubectl create secret generic cloudflare-api-token \
    --namespace cloudflare-gateway-controller-system \
    --from-literal=api-token="$CF_API_TOKEN"
  3. Terminal window
    cat <<EOF | kubectl apply -f -
    apiVersion: cfgateway.dreamfuselabs.com/v1alpha1
    kind: CloudflareGatewayConfiguration
    metadata:
    name: tunnel-config
    spec:
    mode: tunnel
    accountID: "$ACCOUNT_ID"
    zoneAllowlist: ["$ZONE"]
    credentialSecretRef:
    namespace: cloudflare-gateway-controller-system
    name: cloudflare-api-token
    key: api-token
    EOF
    kubectl wait cloudflaregatewayconfiguration/tunnel-config \
    --for=condition=Accepted --timeout=30s
  4. Terminal window
    cat <<EOF | kubectl apply -f -
    apiVersion: gateway.networking.k8s.io/v1
    kind: GatewayClass
    metadata:
    name: cloudflare-tunnel
    spec:
    controllerName: cfgateway.dreamfuselabs.com/tunnel-controller
    parametersRef:
    group: cfgateway.dreamfuselabs.com
    kind: CloudflareGatewayConfiguration
    name: tunnel-config
    EOF
    kubectl wait gatewayclass/cloudflare-tunnel --for=condition=Accepted --timeout=30s
  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 tunnel 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

    (Note: kubectl create deployment ... -- <args> sets the container’s command, overriding hashicorp/http-echo’s own entrypoint entirely rather than appending flags to it — a plain YAML Deployment with args: is the pattern used here instead, confirmed working against this exact image and tag.)

  6. Replace app below with whatever subdomain you want under your zone.

    Terminal window
    cat <<EOF | kubectl apply -f -
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
    name: my-gateway
    spec:
    gatewayClassName: cloudflare-tunnel
    listeners:
    - name: http
    protocol: HTTP
    port: 80
    hostname: "app.$ZONE"
    ---
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
    name: echo-route
    spec:
    parentRefs:
    - name: my-gateway
    rules:
    - backendRefs:
    - name: echo
    port: 80
    EOF
    kubectl wait gateway/my-gateway --for=condition=Accepted --timeout=30s

    Creating the Gateway auto-provisions a CloudflareTunnel (named after the Gateway) and its managed cloudflared Deployment — there’s no separate CloudflareTunnel object to create by hand. Wait for it to roll out and register real edge connectors:

    Terminal window
    kubectl rollout status deployment/my-gateway --timeout=120s
    kubectl wait cloudflaretunnel/my-gateway --for=condition=Ready --timeout=180s
  7. Terminal window
    curl -sf "https://app.$ZONE"

    Should print hello from tunnel mode. The CloudflareDNSRecord this route auto-created (check kubectl get cloudflarednsrecord) is a proxied CNAME to <tunnel-id>.cfargotunnel.com — Cloudflare’s edge terminates TLS and proxies the request over the tunnel to echo’s ClusterIP, with no inbound port ever opened on the cluster.

Terminal window
kubectl delete httproute echo-route
kubectl delete gateway my-gateway # also deletes the auto-provisioned CloudflareTunnel
kubectl delete deployment,service echo
kubectl delete gatewayclass cloudflare-tunnel
# Wait for the owned CloudflareTunnel/CloudflareDNSRecord objects to actually finish deleting
# (each one's own finalizer deletes the real Cloudflare-side resource first) before deleting
# the configuration they authenticate through — see below for why this order matters.
kubectl wait --for=delete cloudflaretunnel/my-gateway --timeout=60s 2>/dev/null || true
for i in $(seq 1 30); do [ -z "$(kubectl get cloudflarednsrecord -o name 2>/dev/null)" ] && break; sleep 2; done
kubectl delete cloudflaregatewayconfiguration tunnel-config
kubectl delete secret cloudflare-api-token -n cloudflare-gateway-controller-system

Deleting the Gateway deletes its owned CloudflareTunnel and CloudflareDNSRecord objects, which in turn delete the real tunnel and DNS record at Cloudflare (the default deletion policy — see API Reference if you’d rather leave the Cloudflare-side resource in place instead). This cascade is asynchronous, though: Kubernetes garbage-collects owned objects only after their owner is gone, and each one then calls the real Cloudflare delete API from its own finalizer. Deleting the configuration too soon — before that finishes — hits a deliberate tradeoff: if an owned object 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 resource is orphaned, needing manual cleanup. The kubectl wait --for=delete step above closes that race.

  • Routing — configure routes with HTTPRoute and GRPCRoute.
  • Tunnel Tuning — configure gRPC support, replica count, and other per-tunnel cloudflared behavior with CloudflareTunnelPolicy.
  • Access — protect a hostname with Cloudflare Access, identity providers, and service tokens.