This directory contains practical examples for the Cloudflare Operator, organized by functionality and use cases.
此目录包含 Cloudflare Operator 的实用示例,按功能和使用场景组织。
examples/
├── 01-basic/ # Basic examples / 基础示例
│ ├── credentials/ # API credentials setup
│ ├── tunnel/ # Tunnel creation
│ ├── dns/ # DNS record management
│ └── service-binding/ # Service binding to tunnels
│
├── 02-private-network/ # Private network access / 私有网络访问
│ ├── virtual-network/ # Virtual network configuration
│ ├── network-route/ # Network routing
│ └── private-service/ # Private service exposure
│
├── 03-zero-trust/ # Zero Trust Access / 零信任访问
│ ├── access-application/ # Access application configuration
│ ├── access-group/ # Access group management
│ ├── identity-provider/ # Identity provider setup
│ └── service-token/ # Service token for M2M auth
│
├── 04-gateway/ # Gateway & Security / 网关与安全
│ ├── gateway-rule/ # Gateway rules
│ ├── gateway-list/ # Gateway lists
│ └── gateway-configuration/ # Gateway configuration
│
├── 05-device/ # Device Management / 设备管理
│ ├── device-policy/ # Device settings policy
│ └── device-posture/ # Device posture rules
│
└── scenarios/ # Complete Scenarios / 完整场景
├── web-app-exposure/ # Expose web application
├── kubernetes-private-access/ # K8s private network access
└── multi-cluster-access/ # Multi-cluster setup
- A Kubernetes cluster (v1.28+)
- Cloudflare account with Zero Trust enabled
- Cloudflare API Token with appropriate permissions
- Kubernetes 集群 (v1.28+)
- 启用 Zero Trust 的 Cloudflare 账户
- 具有适当权限的 Cloudflare API Token
# Edit the secret file with your API token
# 编辑 secret 文件,填入你的 API token
vim examples/01-basic/credentials/api-secret.yaml
# Apply the secret
# 应用 secret
kubectl apply -f examples/01-basic/credentials/api-secret.yaml# Edit tunnel configuration
# 编辑隧道配置
vim examples/01-basic/tunnel/tunnel.yaml
# Apply the tunnel
# 应用隧道
kubectl apply -f examples/01-basic/tunnel/tunnel.yaml
# Check tunnel status
# 检查隧道状态
kubectl get tunnel -w# Apply service binding
# 应用服务绑定
kubectl apply -f examples/01-basic/service-binding/
# Check binding status
# 检查绑定状态
kubectl get tunnelbindingExpose a web application through Cloudflare Tunnel with automatic DNS and TLS.
通过 Cloudflare Tunnel 暴露 Web 应用,自动配置 DNS 和 TLS。
kubectl apply -f examples/scenarios/web-app-exposure/Enable WARP clients to access Kubernetes services via private IPs.
允许 WARP 客户端通过私有 IP 访问 Kubernetes 服务。
kubectl apply -f examples/scenarios/kubernetes-private-access/Connect multiple Kubernetes clusters through Cloudflare network.
通过 Cloudflare 网络连接多个 Kubernetes 集群。
kubectl apply -f examples/scenarios/multi-cluster-access/| Resource | API Version | Scope |
|---|---|---|
| Tunnel | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| ClusterTunnel | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| TunnelBinding | networking.cfargotunnel.com/v1alpha1 |
Namespaced |
| VirtualNetwork | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| NetworkRoute | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| PrivateService | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| DNSRecord | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| CloudflareDomain | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| Resource | API Version | Scope |
|---|---|---|
| AccessApplication | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| AccessGroup | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| AccessIdentityProvider | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| AccessServiceToken | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| GatewayRule | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| GatewayList | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| GatewayConfiguration | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| DeviceSettingsPolicy | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| DevicePostureRule | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| WARPConnector | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| Resource | API Version | Scope |
|---|---|---|
| R2Bucket | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| R2BucketDomain | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| R2BucketNotification | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| Resource | API Version | Scope |
|---|---|---|
| ZoneRuleset | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| TransformRule | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| RedirectRule | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| Resource | API Version | Scope |
|---|---|---|
| OriginCACertificate | networking.cloudflare-operator.io/v1alpha2 |
Namespaced |
| DomainRegistration | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| Resource | API Version | Scope |
|---|---|---|
| TunnelIngressClassConfig | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
| TunnelGatewayClassConfig | networking.cloudflare-operator.io/v1alpha2 |
Cluster |
The operator uses a Unified Sync Architecture with six layers:
Operator 采用统一同步架构,包含六层:
K8s Resources → Resource Controllers → Core Services → SyncState CRD → Sync Controllers → Cloudflare API
| Layer | Description / 描述 |
|---|---|
| K8s Resources | Your CRDs (Tunnel, DNSRecord, etc.) / 你的 CRD (Tunnel, DNSRecord 等) |
| Resource Controllers | Lightweight, validate and register config / 轻量级,验证并注册配置 |
| Core Services | Business logic, manage SyncState / 业务逻辑,管理 SyncState |
| SyncState CRD | Shared state with optimistic locking / 共享状态,乐观锁 |
| Sync Controllers | Debounce, aggregate, call API / 防抖、聚合、调用 API |
| Cloudflare API | Single sync point / 唯一同步点 |
This architecture eliminates race conditions when multiple resources (e.g., Tunnel + Ingress + TunnelBinding) update the same Cloudflare configuration.
此架构消除了多个资源(如 Tunnel + Ingress + TunnelBinding)更新同一 Cloudflare 配置时的竞态条件。
Check the sync state of your resources:
检查资源的同步状态:
# View all sync states / 查看所有同步状态
kubectl get cloudflaresyncstate
# View specific sync state / 查看特定同步状态
kubectl describe cloudflaresyncstate tunnel-config-<tunnel-id>
# Watch sync status changes / 观察同步状态变化
kubectl get cloudflaresyncstate -w-
Replace placeholder values (e.g.,
<your-account-id>,<your-domain>) with your actual values -
将占位符值(如
<your-account-id>、<your-domain>)替换为实际值 -
Ensure your API token has the required permissions for each resource type
-
确保你的 API token 具有每种资源类型所需的权限
-
Check resource status with
kubectl describe <resource> <name>for troubleshooting -
使用
kubectl describe <resource> <name>检查资源状态以进行故障排除 -
For detailed architecture, see Unified Sync Architecture
-
详细架构请参阅统一同步架构