agentleFS
anderson-c-santosanderson-c-santos/claude-skills-network/skills/cloudflare-tunnel/SKILL.md

cloudflare-tunnel

Skill1 starsChanged 5 months agoMITView on GitHub

Use this skill for Cloudflare Tunnel (cloudflared) — zero-trust public exposure without open ports, K3s/Kubernetes HA deployment, ConfigMap-based config management, DNS automation, adding/removing service routes, and Traefik IngressRoute integration. Activate for any cloudflared setup, tunnel routing, or *.yourdomain.com exposure work.

  • Reads credentials
  • Installs packages

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    No open firewall ports. No public IP needed.

    line 16
  2. Distinctive:

    Use Cloudflare Zero Trust Access policies to add auth (SSO, email OTP) in front of any tunnel service.

    line 213
  3. Distinctive:

    No inbound firewall rules needed — all traffic is outbound from your server to Cloudflare.

    line 214

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Cloudflare Tunnel

Core Concept

Cloudflare Tunnel (cloudflared) creates an outbound-only connection from your server to Cloudflare's edge — no inbound ports needed. Traffic flows:

User → Cloudflare Edge → cloudflared daemon → your service

No open firewall ports. No public IP needed. Wildcard domains covered by Cloudflare Universal SSL (single-label only: *.example.com ✓, *.sub.example.com ✗).

Initial Setup

# Install cloudflared
curl -L https://pkg.cloudflare.com/cloudflare-main.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloudflare-main.gpg
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main" | sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt update && sudo apt install cloudflared

# Authenticate (browser login)
cloudflared tunnel login

# Create tunnel
cloudflared tunnel create my-tunnel
# Saves credentials to ~/.cloudflared/<TUNNEL_ID>.json

# Create DNS CNAME pointing to tunnel
cloudflared tunnel route dns my-tunnel service.example.com

Config File Structure

# ~/.cloudflared/config.yml (or ConfigMap in K3s)
tunnel: TUNNEL_ID
credentials-file: /home/nonroot/.cloudflared/TUNNEL_ID.json

ingress:
  - hostname: app1.example.com
    service: http://localhost:3000
  - hostname: app2.example.com
    service: http://localhost:8080
  - hostname: ssh.example.com
    service: ssh://localhost:22
  - service: http_status:404   # catch-all — required at end

K3s Kubernetes HA Deployment

ConfigMap-based config (preferred over hostPath):

# cloudflared-config ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
  name: cloudflared-config
  namespace: apps
data:
  config.yml: |
    tunnel: TUNNEL_ID
    credentials-file: /etc/cloudflared/creds/credentials.json
    ingress:
      - hostname: app.example.com
        service: http://app-service.apps.svc.cluster.local:3000
      - service: http_status:404
---
# Credentials Secret
apiVersion: v1
kind: Secret
metadata:
  name: cloudflared-credentials
  namespace: apps
type: Opaque
stringData:
  credentials.json: |
    {"AccountTag":"...","TunnelSecret":"...","TunnelID":"TUNNEL_ID"}
---
# Deployment — 2 replicas for HA
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cloudflared
  namespace: apps
spec:
  replicas: 2
  selector:
    matchLabels:
      app: cloudflared
  template:
    metadata:
      labels:
        app: cloudflared
    spec:
      containers:
      - name: cloudflared
        image: cloudflare/cloudflared:latest
        args: ["tunnel", "--config", "/etc/cloudflared/config/config.yml", "run"]
        volumeMounts:
        - name: config
          mountPath: /etc/cloudflared/config
        - name: creds
          mountPath: /etc/cloudflared/creds
      volumes:
      - name: config
        configMap:
          name: cloudflared-config
      - name: creds
        secret:
          secretName: cloudflared-credentials
      topologySpreadConstraints:
      - maxSkew: 1
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: DoNotSchedule
        labelSelector:
          matchLabels:
            app: cloudflared

Add a new service route (K3s pattern):

# 1. Register DNS
cloudflared tunnel route dns TUNNEL_ID newservice.example.com

# 2. Edit ConfigMap
kubectl edit cm cloudflared-config -n apps
# Add under ingress (before catch-all):
#   - hostname: newservice.example.com
#     service: http://newservice-svc.apps.svc.cluster.local:PORT

# 3. Rollout
kubectl rollout restart deployment/cloudflared -n apps
kubectl rollout status deployment/cloudflared -n apps

Create K3s IngressRoute for the new service:

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: newservice
  namespace: apps
spec:
  entryPoints: [web]
  routes:
  - match: Host(`newservice.example.com`)
    kind: Rule
    services:
    - name: newservice-svc
      port: PORT

Remove a Service

# 1. Remove from ConfigMap ingress
kubectl edit cm cloudflared-config -n apps

# 2. Rollout
kubectl rollout restart deployment/cloudflared -n apps

# 3. Remove DNS record (via Cloudflare API or dashboard)
# cloudflared does not auto-delete DNS on removal

DNS Automation

# Add DNS CNAME via cloudflared CLI
cloudflared tunnel route dns TUNNEL_ID subdomain.example.com

# Via Docker (no local cloudflared install)
docker run --rm \
  -v ~/.cloudflared:/home/nonroot/.cloudflared:ro \
  cloudflare/cloudflared tunnel route dns TUNNEL_ID subdomain.example.com

Metrics & Health

# cloudflared metrics endpoint (port 2000 by default)
curl http://localhost:2000/metrics

# Check tunnel status
cloudflared tunnel info TUNNEL_ID
cloudflared tunnel list

# K3s — check pod status
kubectl get pods -n apps -l app=cloudflared
kubectl logs -n apps deploy/cloudflared --tail=50

Troubleshooting

SymptomCauseFix
502 Bad GatewayService not running on target portCheck upstream service health
1033 - Tunnel not foundWrong tunnel ID in credentialsRe-run cloudflared tunnel login + recreate
DNS not resolvingCNAME not propagatedCheck cloudflared tunnel route dns output; allow 5 min TTL
Pod crash loopWrong credentials pathVerify Secret mount path matches credentials-file in config
Config changes not appliedDeployment not restartedkubectl rollout restart deployment/cloudflared -n apps

Security Notes

  • Tunnel credentials JSON contains the tunnel secret — store as Kubernetes Secret, never in ConfigMap.
  • Wildcard *.example.com covers only single-label subdomains; multi-level like a.b.example.com requires explicit DNS entry.
  • Use Cloudflare Zero Trust Access policies to add auth (SSO, email OTP) in front of any tunnel service.
  • No inbound firewall rules needed — all traffic is outbound from your server to Cloudflare.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.