AI Prompts
⌘+J) for guidance on building your Cloudflare Tunnel stack.Why Cloudflare Tunnel?
- Clusters running on-premises or in private networks
- Development and staging environments
- Services that need Cloudflare’s security features
- Teams that want zero-trust access controls
Prerequisites
Before you start:- A Cloudflare account with a domain added
- A cluster imported into Ankra with the agent connected
- The service you want to expose running in your cluster
Step 1: Create a Cloudflare Tunnel
Log into Cloudflare Dashboard
Navigate to Zero Trust
Create a Tunnel
Name Your Tunnel
my-cluster-tunnel or prod-services.Copy the Tunnel Token
eyJhIjoiNjM...Skip the Connector Setup
Configure Public Hostname
- Subdomain: e.g.,
apporapi - Domain: Select your Cloudflare domain
- Service:
http://your-service.namespace.svc.cluster.local:portYou can add more hostnames later.
Save the Tunnel
Step 2: Create the Stack in Ankra
Open Stack Builder
Name Your Stack
cloudflare-tunnel or similar.Add a Secret Manifest
YOUR_TUNNEL_TOKEN_HERE with the token from Cloudflare.Add a Namespace Manifest
Add the Cloudflared Deployment
Connect Dependencies
Step 3: Deploy and Verify
Save and Deploy
Check Cloudflare Dashboard
Test Your Service
https://app.yourdomain.com). Your service should be accessible.Configuring Routes
You configure which services are exposed in the Cloudflare dashboard, not in Kubernetes.Adding a New Route
- Go to Zero Trust → Networks → Tunnels
- Click your tunnel → Configure
- Go to Public Hostname tab
- Click Add a public hostname
- Configure:
- Subdomain: The subdomain to use
- Domain: Your Cloudflare domain
- Service: The internal Kubernetes service URL
Service URL Format
For Kubernetes services, use this format:http://nginx.default.svc.cluster.local:80http://api-server.backend.svc.cluster.local:3000http://grafana.monitoring.svc.cluster.local:3000
Multiple Services
One tunnel can expose multiple services. Add multiple public hostnames in Cloudflare:High Availability
The example deployment runs 2 replicas for redundancy. For production:Encrypting Secrets with SOPS
If you’re using GitOps to store your Stack configuration, you should encrypt the tunnel token with SOPS to avoid committing secrets in plaintext.Enable SOPS Encryption
Initialize SOPS at Organisation Level
Enable SOPS on Your Cluster
Mark the Token for Encryption
token as an encrypted key.How It Works
- When you save the Stack, Ankra encrypts the
tokenfield using your organisation’s AGE public key - The encrypted manifest is stored in your Git repository (if GitOps is enabled)
- When ArgoCD deploys the Stack, helm-secrets automatically decrypts the value using the private key stored in the cluster
- Your tunnel token never appears in plaintext in Git
Example Encrypted Manifest
After encryption, the Secret looks like this in Git:ENC[...] value is the encrypted token. The sops metadata block contains the encryption parameters.
Access Controls
Cloudflare Tunnel integrates with Cloudflare Access for zero-trust security:- Go to Zero Trust → Access → Applications
- Click Add an application
- Select Self-hosted
- Configure the application URL (your tunnel hostname)
- Add access policies (e.g., require SSO, specific emails, IP ranges)
Troubleshooting
Tunnel Shows as Inactive
Tunnel Shows as Inactive
- Check the cloudflared pods are running:
- Check the logs for errors:
- Verify the token in the secret is correct
502 Bad Gateway
502 Bad Gateway
- Verify the service URL in Cloudflare is correct
- Check the service exists and has endpoints:
- Test connectivity from cloudflared pod:
Connection Timeouts
Connection Timeouts
- Check if the service is responding slowly
- Increase timeout in Cloudflare tunnel settings
- Verify there are no NetworkPolicies blocking traffic
DNS Not Resolving
DNS Not Resolving
- DNS propagation can take a few minutes
- Verify the hostname is configured in the Cloudflare dashboard
- Check that your domain’s nameservers point to Cloudflare
AI Prompts
Press⌘+J to open the AI Assistant and use these prompts:
Basic Cloudflare Tunnel Stack
Basic Cloudflare Tunnel Stack
Expose an Existing Service
Expose an Existing Service
Production Tunnel Setup
Production Tunnel Setup
Troubleshoot Tunnel Issues
Troubleshoot Tunnel Issues