Skip to content

Commit e6fa85c

Browse files
committed
deploy cloudflared pods
1 parent da6f083 commit e6fa85c

File tree

1 file changed

+93
-58
lines changed
  • src/content/docs/cloudflare-one/connections/connect-networks/deployment-guides

1 file changed

+93
-58
lines changed

src/content/docs/cloudflare-one/connections/connect-networks/deployment-guides/kubernetes.mdx

Lines changed: 93 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -209,64 +209,99 @@ Create a [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/s
209209
tunnel-token Opaque 1 100s
210210
```
211211

212-
## Create pods for cloudflared
213-
214-
The tunnel can be created through the dashboard using [this guide](/cloudflare-one/connections/connect-networks/get-started/create-remote-tunnel/). Instead of running the command to install a connector you will select docker as the environment and copy just the token rather than the whole command. Configure the tunnel to route to k8.example.com from the service [http://web-service:80](http://web-service:80). Create the cloudflared-deployment.yml file with the following content.
215-
216-
```yaml
217-
apiVersion: apps/v1
218-
kind: Deployment
219-
metadata:
220-
labels:
221-
app: cloudflared
222-
name: cloudflared-deployment
223-
namespace: default
224-
spec:
225-
replicas: 2
226-
selector:
227-
matchLabels:
228-
pod: cloudflared
229-
template:
230-
metadata:
231-
creationTimestamp: null
232-
labels:
233-
pod: cloudflared
234-
spec:
235-
securityContext:
236-
sysctls:
237-
- name: net.ipv4.ping_group_range
238-
value: "65532 65532"
239-
containers:
240-
- command:
241-
- cloudflared
242-
- tunnel
243-
- --no-autoupdate
244-
# In a k8s environment, the metrics server needs to listen outside the pod it runs on.
245-
# The address 0.0.0.0:2000 allows any pod in the namespace.
246-
- --metrics
247-
- 0.0.0.0:2000
248-
- run
249-
args:
250-
- --token
251-
- <token value>
252-
image: cloudflare/cloudflared:latest
253-
name: cloudflared
254-
livenessProbe:
255-
httpGet:
256-
# Cloudflared has a /ready endpoint which returns 200 if and only if
257-
# it has an active connection to the edge.
258-
path: /ready
259-
port: 2000
260-
failureThreshold: 1
261-
initialDelaySeconds: 10
262-
periodSeconds: 10
263-
```
264-
265-
This file will be deployed with the following command.
266-
267-
```sh
268-
kubectl create -f cloudflared-deployment.yml
269-
```
212+
## 5. Create pods for cloudflared
213+
214+
1. Create a Kubernetes deployment for a remotely-managed Cloudflare Tunnel:
215+
216+
```yaml title="tunnel.yaml"
217+
apiVersion: apps/v1
218+
kind: Deployment
219+
metadata:
220+
name: cloudflared-deployment
221+
namespace: default
222+
spec:
223+
replicas: 2
224+
selector:
225+
matchLabels:
226+
pod: cloudflared
227+
template:
228+
metadata:
229+
labels:
230+
pod: cloudflared
231+
spec:
232+
securityContext:
233+
sysctls:
234+
# Allows ICMP traffic (ping, traceroute) to resources behind cloudflared.
235+
- name: net.ipv4.ping_group_range
236+
value: "65532 65532"
237+
containers:
238+
- image: cloudflare/cloudflared:latest
239+
name: cloudflared
240+
env:
241+
- name: token_value
242+
valueFrom:
243+
secretKeyRef:
244+
name: tunnel-token
245+
key: token
246+
command:
247+
# Pay attention to the order of commands. For example, --loglevel, --no-autoupdate, and --metrics come before the "run" command, while --token comes after the "run" command.
248+
- cloudflared
249+
- tunnel
250+
- --no-autoupdate
251+
- --loglevel
252+
- debug
253+
- --metrics
254+
- 0.0.0.0:2000
255+
- run
256+
args:
257+
- --token
258+
- $(token_value)
259+
livenessProbe:
260+
httpGet:
261+
# Cloudflared has a /ready endpoint which returns 200 if and only if
262+
# it has an active connection to Cloudflare's network.
263+
path: /ready
264+
port: 2000
265+
failureThreshold: 1
266+
initialDelaySeconds: 10
267+
periodSeconds: 10
268+
```
269+
270+
2. Deploy `cloudflared` to the cluster:
271+
272+
```sh
273+
kubectl create -f tunnel.yaml
274+
```
275+
276+
Kubernetes will install the `cloudflared` image on two pods and run the tunnel using the command `cloudflared tunnel --no-autoupdate --loglevel debug --metrics 0.0.0.0:2000 run --token eyJhIjoiNWFiNGU5Z...`
277+
278+
3. Check the status of your cluster:
279+
280+
```sh
281+
kubectl get all
282+
```
283+
284+
```sh output
285+
NAME READY STATUS RESTARTS AGE
286+
pod/cloudflared-deployment-6d5f9f9666-85l5w 1/1 Running 0 21s
287+
pod/cloudflared-deployment-6d5f9f9666-wb96x 1/1 Running 0 21s
288+
pod/httpbin-deployment-bc6689c5d-b5ftk 1/1 Running 0 3m36s
289+
pod/httpbin-deployment-bc6689c5d-cbd9m 1/1 Running 0 3m36s
290+
291+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
292+
service/httpbin-service LoadBalancer 34.118.225.147 34.75.201.60 80:31967/TCP 3m36s
293+
service/kubernetes ClusterIP 34.118.224.1 <none> 443/TCP 24h
294+
295+
NAME READY UP-TO-DATE AVAILABLE AGE
296+
deployment.apps/cloudflared-deployment 2/2 2 2 22s
297+
deployment.apps/httpbin-deployment 2/2 2 2 3m37s
298+
299+
NAME DESIRED CURRENT READY AGE
300+
replicaset.apps/cloudflared-deployment-6d5f9f9666 2 2 2 22s
301+
replicaset.apps/httpbin-deployment-bc6689c5d 2 2 2 3m37s
302+
```
303+
304+
You should see two `cloudflared` pods and two `httpbin` pods with a `Running` status. If your `cloudflared` pods keep restarting, make sure that your `cloudflared` [parameters](/cloudflare-one/connections/connect-networks/configure-tunnels/cloudflared-parameters/run-parameters/) are in the correct position relative to the `run` command.
270305

271306
## Verify tunnel status
272307

0 commit comments

Comments
 (0)