You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/cloudflare-one/connections/connect-networks/deployment-guides/kubernetes.mdx
+93-58Lines changed: 93 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -209,64 +209,99 @@ Create a [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/s
209
209
tunnel-token Opaque 1 100s
210
210
```
211
211
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...`
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.
0 commit comments