edge:waw | CF Pages (SSG) | AI: 2/day
MrocznyBanan@cloud : ~/articles $ ls -la
← cd .. [back to index] chmod 644 2026-11-22-k3s-cloudflare-tunnels.md
$ cat 2026-11-22-k3s-cloudflare-tunnels.md

Zero-Cost Infrastructure: Exposing K3s Clusters with Cloudflare Tunnels

📅 Date: 2026-11-22 🏷️ Category: DEVOPS ⏱ Read time: 4 min Git: #c4f9a12 🤖 AI Verified Post

Historically, exposing internal Kubernetes workloads required public IPv4 addresses, fragile port-forwarding rules, or expensive cloud provider Load Balancers.

With Cloudflare Tunnels (cloudflared), you can close all inbound firewall ports and establish secure, persistent outbound QUIC connections directly to Cloudflare’s global edge network.

1. Architectural Overview

Traffic flows purely outbound. The cloudflared daemon running as a lightweight Kubernetes Deployment connects to the nearest Cloudflare Point of Presence (PoP):

[ Client / Browser ]
          │
          ▼ (HTTPS / Global Anycast / WAF)
   [ Cloudflare Edge ]
          ▲
          │ (Persistent Outbound QUIC Tunnel)
   [ Pod: cloudflared ]
          │
          ▼ (ClusterIP / Internal Ingress)
   [ Service: Grafana / API ]

2. Kubernetes Deployment Configuration

Instead of managing local certificates or dynamic DNS scripts, create a tunnel secret in Cloudflare Zero Trust and mount the credentials:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cloudflared-tunnel
  namespace: networking
spec:
  replicas: 2
  selector:
    matchLabels:
      app: cloudflared
  template:
    metadata:
      labels:
        app: cloudflared
    spec:
      containers:
      - name: cloudflared
        image: cloudflare/cloudflared:latest
        args:
        - tunnel
        - --no-autoupdate
        - run
        - --token
        - $(TUNNEL_TOKEN)
        env:
        - name: TUNNEL_TOKEN
          valueFrom:
            secretKeyRef:
              name: tunnel-credentials
              key: token
        resources:
          limits:
            cpu: 100m
            memory: 128Mi
          requests:
            cpu: 25m
            memory: 64Mi

3. Key Takeaways

  • Zero inbound ports open on your edge firewall or router.
  • DDoS mitigation and edge SSL termination handled automatically by Cloudflare.
  • 100% free under Cloudflare Zero Trust Free plan (up to 50 users).
tags: #kubernetes #k3s #cloudflare #security #homelab
[cd .. back to console]