gateway-cloudflare

by CNAP Technologies

Helm chartv1.0.0App 0.8.1Verified publisher

Cloudflare Tunnel Gateway for Kubernetes Gateway API

About this chart

Cloudflare Gateway Chart

Deploys a Cloudflare Tunnel Gateway for Kubernetes Gateway API.

This chart installs the cloudflare-kubernetes-gateway controller and creates a Gateway resource for routing traffic through Cloudflare Tunnels.

Features

  • Zero-trust access: Traffic goes through Cloudflare's edge, no public IPs needed
  • Automatic tunnels: Controller manages Cloudflare Tunnels automatically
  • DDoS protection: Cloudflare's edge provides built-in protection
  • SSL at edge: Cloudflare handles TLS termination

Prerequisites

  • Kubernetes 1.24+
  • Gateway API CRDs v1.0+
  • Cloudflare account with:
    • Account ID
    • API token with "Account Cloudflare Tunnel Edit" and "Zone DNS Edit" permissions

Install Gateway API CRDs

kubectl apply -k github.com/kubernetes-sigs/gateway-api//config/crd?ref=v1.0.0

Installation

Quick Start

helm install cloudflare-gateway . \
  --set cloudflare.accountId=your-account-id \
  --set cloudflare.apiToken=your-api-token

With values file

# values.yaml
cloudflare:
  accountId: 'your-account-id'
  apiToken: 'your-api-token'

gateway:
  name: my-gateway
  listeners:
    - name: http
      protocol: HTTP
      port: 80
helm install cloudflare-gateway . -f values.yaml

Using the Fork with Improvements

The lwijnsma/cloudflare-kubernetes-gateway fork includes improvements over the original. To use it:

controller:
  image:
    repository: ghcr.io/lwijnsma/cloudflare-kubernetes-gateway
    tag: 'latest'  # Or specific version

Values

KeyTypeDefaultDescription
cloudflare.accountIdstring""Cloudflare account ID
cloudflare.apiTokenstring""Cloudflare API token
cloudflare.existingSecretstring""Use existing secret for credentials
controller.enabledbooltrueDeploy the controller
controller.image.repositorystringghcr.io/pl4nty/cloudflare-kubernetes-gatewayController image
controller.image.tagstring""Image tag (defaults to appVersion)
controller.namespacestringcloudflare-gatewayController namespace
controller.replicasint1Controller replicas
controller.resourcesobjectSee values.yamlResource limits
gatewayClass.namestringcloudflareGatewayClass name
gateway.enabledbooltrueCreate Gateway resource
gateway.namestringcloudflare-gatewayGateway name
gateway.namespacestring""Gateway namespace (defaults to release namespace)
gateway.listenerslist[{name: http, protocol: HTTP, port: 80}]Gateway listeners
gateway.infrastructure.disableDeploymentboolfalseDisable per-gateway cloudflared

Creating HTTPRoutes

After installing, create HTTPRoutes to expose services:

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: my-app
spec:
  parentRefs:
    - name: cloudflare-gateway
      namespace: cloudflare-gateway  # Or your gateway namespace
  hostnames:
    - myapp.example.com
  rules:
    - backendRefs:
        - name: my-service
          port: 8080

Or use the CNAP httproute chart:

helm install my-route ../httproute \
  --set parentRef.name=cloudflare-gateway \
  --set parentRef.namespace=cloudflare-gateway \
  --set 'hostnames[0]=myapp.example.com' \
  --set backendRef.name=my-service \
  --set backendRef.port=8080

DNS Configuration

The controller automatically creates DNS records in Cloudflare when HTTPRoutes are created. Ensure your API token has "Zone DNS Edit" permission for the zones you want to use.

Troubleshooting

Check controller logs

kubectl logs -n cloudflare-gateway deployment/cloudflare-gateway-controller

Check Gateway status

kubectl get gateway -n cloudflare-gateway
kubectl describe gateway cloudflare-gateway -n cloudflare-gateway

Check HTTPRoute status

kubectl get httproute
kubectl describe httproute my-app

Integration with CNAP

When using this chart through CNAP:

  1. Add this chart as a helm source to your product/template
  2. Configure Cloudflare credentials via CNAP's secrets management
  3. CNAP will discover the Gateway for use with the "Expose externally" feature

References

Deploy gateway-cloudflare with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has gateway-cloudflare on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartgateway-cloudflare is pinned at v1.0.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply