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):
echo "<your-token>" | helm registry login ghcr.io --username <your-github-username> --password-stdinCreate 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:
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.
Prerequisites
Section titled “Prerequisites”-
A Kubernetes cluster, version 1.28 or later — otherwise any; Tunnel Mode has no
LoadBalanceror 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.
-
Install the chart
Section titled “Install the chart”Create the namespace, create a pull Secret for the private GHCR image and chart, and install:
Terminal window kubectl create namespace cloudflare-gateway-controller-systemkubectl 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-systemhelm 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 -
Store the credential
Section titled “Store the credential”Terminal window kubectl create secret generic cloudflare-api-token \--namespace cloudflare-gateway-controller-system \--from-literal=api-token="$CF_API_TOKEN" -
Create a CloudflareGatewayConfiguration
Section titled “Create a CloudflareGatewayConfiguration”Terminal window cat <<EOF | kubectl apply -f -apiVersion: cfgateway.dreamfuselabs.com/v1alpha1kind: CloudflareGatewayConfigurationmetadata:name: tunnel-configspec:mode: tunnelaccountID: "$ACCOUNT_ID"zoneAllowlist: ["$ZONE"]credentialSecretRef:namespace: cloudflare-gateway-controller-systemname: cloudflare-api-tokenkey: api-tokenEOFkubectl wait cloudflaregatewayconfiguration/tunnel-config \--for=condition=Accepted --timeout=30s -
Create the GatewayClass
Section titled “Create the GatewayClass”Terminal window cat <<EOF | kubectl apply -f -apiVersion: gateway.networking.k8s.io/v1kind: GatewayClassmetadata:name: cloudflare-tunnelspec:controllerName: cfgateway.dreamfuselabs.com/tunnel-controllerparametersRef:group: cfgateway.dreamfuselabs.comkind: CloudflareGatewayConfigurationname: tunnel-configEOFkubectl wait gatewayclass/cloudflare-tunnel --for=condition=Accepted --timeout=30s -
Deploy a backend
Section titled “Deploy a backend”Terminal window cat <<EOF | kubectl apply -f -apiVersion: apps/v1kind: Deploymentmetadata:name: echospec:replicas: 1selector:matchLabels: {app: echo}template:metadata:labels: {app: echo}spec:containers:- name: echoimage: hashicorp/http-echo:1.0.0args: ["-listen=:8080", "-text=hello from tunnel mode"]ports: [{containerPort: 8080}]---apiVersion: v1kind: Servicemetadata:name: echospec:selector: {app: echo}ports: [{port: 80, targetPort: 8080}]EOFkubectl rollout status deployment/echo --timeout=60s(Note:
kubectl create deployment ... -- <args>sets the container’scommand, overridinghashicorp/http-echo’s own entrypoint entirely rather than appending flags to it — a plain YAMLDeploymentwithargs:is the pattern used here instead, confirmed working against this exact image and tag.) -
Create a Gateway and HTTPRoute
Section titled “Create a Gateway and HTTPRoute”Replace
appbelow with whatever subdomain you want under your zone.Terminal window cat <<EOF | kubectl apply -f -apiVersion: gateway.networking.k8s.io/v1kind: Gatewaymetadata:name: my-gatewayspec:gatewayClassName: cloudflare-tunnellisteners:- name: httpprotocol: HTTPport: 80hostname: "app.$ZONE"---apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata:name: echo-routespec:parentRefs:- name: my-gatewayrules:- backendRefs:- name: echoport: 80EOFkubectl wait gateway/my-gateway --for=condition=Accepted --timeout=30sCreating the
Gatewayauto-provisions aCloudflareTunnel(named after the Gateway) and its managedcloudflaredDeployment — there’s no separateCloudflareTunnelobject to create by hand. Wait for it to roll out and register real edge connectors:Terminal window kubectl rollout status deployment/my-gateway --timeout=120skubectl wait cloudflaretunnel/my-gateway --for=condition=Ready --timeout=180s -
Verify
Section titled “Verify”Terminal window curl -sf "https://app.$ZONE"Should print
hello from tunnel mode. TheCloudflareDNSRecordthis route auto-created (checkkubectl get cloudflarednsrecord) is a proxied CNAME to<tunnel-id>.cfargotunnel.com— Cloudflare’s edge terminates TLS and proxies the request over the tunnel toecho’sClusterIP, with no inbound port ever opened on the cluster.
Cleanup
Section titled “Cleanup”kubectl delete httproute echo-routekubectl delete gateway my-gateway # also deletes the auto-provisioned CloudflareTunnelkubectl delete deployment,service echokubectl 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 || truefor i in $(seq 1 30); do [ -z "$(kubectl get cloudflarednsrecord -o name 2>/dev/null)" ] && break; sleep 2; done
kubectl delete cloudflaregatewayconfiguration tunnel-configkubectl delete secret cloudflare-api-token -n cloudflare-gateway-controller-systemDeleting 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.
Next steps
Section titled “Next steps”- Routing — configure routes with
HTTPRouteandGRPCRoute. - Tunnel Tuning — configure gRPC support, replica count, and other
per-tunnel
cloudflaredbehavior withCloudflareTunnelPolicy. - Access — protect a hostname with Cloudflare Access, identity providers, and service tokens.