Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/tunnel/patterns.md
1# Tunnel Patterns23## Docker Deployment45### Token-Based (Recommended)6```yaml7services:8cloudflared:9image: cloudflare/cloudflared:latest10command: tunnel --no-autoupdate run --token ${TUNNEL_TOKEN}11restart: unless-stopped12```1314### Local Config15```yaml16services:17cloudflared:18image: cloudflare/cloudflared:latest19volumes:20- ./config.yml:/etc/cloudflared/config.yml:ro21- ./credentials.json:/etc/cloudflared/credentials.json:ro22command: tunnel run23```2425## Kubernetes Deployment2627```yaml28apiVersion: apps/v129kind: Deployment30metadata:31name: cloudflared32spec:33replicas: 234selector:35matchLabels:36app: cloudflared37template:38metadata:39labels:40app: cloudflared41spec:42containers:43- name: cloudflared44image: cloudflare/cloudflared:latest45args:46- tunnel47- --no-autoupdate48- run49- --token50- $(TUNNEL_TOKEN)51env:52- name: TUNNEL_TOKEN53valueFrom:54secretKeyRef:55name: tunnel-credentials56key: token57```5859## High Availability6061```yaml62# Same config on multiple servers63tunnel: <UUID>64credentials-file: /path/to/creds.json6566ingress:67- hostname: app.example.com68service: http://localhost:800069- service: http_status:40470```7172Run same config on multiple machines. Cloudflare automatically load balances. Long-lived connections (WebSocket, SSH) may drop during updates.7374## Use Cases7576### Web Application77```yaml78ingress:79- hostname: myapp.example.com80service: http://localhost:300081- service: http_status:40482```8384### SSH Access85```yaml86ingress:87- hostname: ssh.example.com88service: ssh://localhost:2289- service: http_status:40490```9192Client: `cloudflared access ssh --hostname ssh.example.com`9394### gRPC Service95```yaml96ingress:97- hostname: grpc.example.com98service: http://localhost:5005199originRequest:100http2Origin: true101- service: http_status:404102```103104## Infrastructure as Code105106### Terraform107108```hcl109resource "random_id" "tunnel_secret" {110byte_length = 32111}112113resource "cloudflare_tunnel" "app" {114account_id = var.cloudflare_account_id115name = "app-tunnel"116secret = random_id.tunnel_secret.b64_std117}118119resource "cloudflare_tunnel_config" "app" {120account_id = var.cloudflare_account_id121tunnel_id = cloudflare_tunnel.app.id122config {123ingress_rule {124hostname = "app.example.com"125service = "http://localhost:8000"126}127ingress_rule { service = "http_status:404" }128}129}130131resource "cloudflare_record" "app" {132zone_id = var.cloudflare_zone_id133name = "app"134value = cloudflare_tunnel.app.cname135type = "CNAME"136proxied = true137}138139output "tunnel_token" {140value = cloudflare_tunnel.app.tunnel_token141sensitive = true142}143```144145### Pulumi146147```typescript148import * as cloudflare from "@pulumi/cloudflare";149import * as random from "@pulumi/random";150151const secret = new random.RandomId("secret", { byteLength: 32 });152153const tunnel = new cloudflare.ZeroTrustTunnelCloudflared("tunnel", {154accountId: accountId,155name: "app-tunnel",156secret: secret.b64Std,157});158159const config = new cloudflare.ZeroTrustTunnelCloudflaredConfig("config", {160accountId: accountId,161tunnelId: tunnel.id,162config: {163ingressRules: [164{ hostname: "app.example.com", service: "http://localhost:8000" },165{ service: "http_status:404" },166],167},168});169170new cloudflare.Record("dns", {171zoneId: zoneId,172name: "app",173value: tunnel.cname,174type: "CNAME",175proxied: true,176});177```178179## Service Installation180181### Linux systemd182```bash183cloudflared service install184systemctl start cloudflared && systemctl enable cloudflared185journalctl -u cloudflared -f # Logs186```187188### macOS launchd189```bash190sudo cloudflared service install191sudo launchctl start com.cloudflare.cloudflared192```193