-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk8s-cloudflared.tf
132 lines (116 loc) · 3.43 KB
/
k8s-cloudflared.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
resource "kubernetes_namespace" "cloudflared" {
metadata {
name = "cloudflared"
annotations = {}
labels = {}
}
}
resource "kubernetes_deployment" "cloudflared" {
metadata {
name = "cloudflared"
namespace = kubernetes_namespace.cloudflared.metadata[0].name
}
spec {
replicas = 2
selector {
match_labels = {
app = "cloudflared"
}
}
template {
metadata {
labels = {
app = "cloudflared"
}
}
spec {
volume {
name = "creds"
secret {
secret_name = "cloudflared"
}
}
volume {
name = "config"
config_map {
name = "cloudflared"
}
}
container {
image = "cloudflare/cloudflared:2021.7.1"
name = "cloudflared"
args = ["tunnel", "--config", "/etc/cloudflared/config/config.yaml", "run"]
liveness_probe {
http_get {
path = "/ready"
port = 2000
}
initial_delay_seconds = 1
period_seconds = 10
failure_threshold = 1
}
volume_mount {
name = "config"
mount_path = "/etc/cloudflared/config"
read_only = true
}
volume_mount {
name = "creds"
mount_path = "/etc/cloudflared/creds"
read_only = true
}
}
}
}
}
}
resource "kubernetes_config_map" "cloudflared" {
metadata {
name = "cloudflared"
namespace = kubernetes_namespace.cloudflared.metadata[0].name
}
data = {
"config.yaml" = <<EOT
# Name of the tunnel you want to run
tunnel: ${cloudflare_argo_tunnel.bootstrap.id}
credentials-file: /etc/cloudflared/creds/credentials.json
# Serves the metrics server under /metrics and the readiness server under /ready
metrics: 0.0.0.0:2000
# Autoupdates applied in a k8s pod will be lost when the pod is removed or restarted, so
# autoupdate doesn't make sense in Kubernetes. However, outside of Kubernetes, we strongly
# recommend using autoupdate.
no-autoupdate: true
# The `ingress` block tells cloudflared which local service to route incoming
# requests to. For more about ingress rules, see
# https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/configuration/ingress
#
ingress:
# - hostname: argocd.${var.domain_name}
# service: http://argocd-server:80
# - hostname: git.${var.domain_name}
# service: http://gitea-http:3000
# This rule sends all requests to nginx ingress controller, which proxies them further to correct services
# - service: http://traefik.kube-system.svc.cluster.local.:80
- hostname: git-ssh.${var.domain_name}
service: ssh://gitea-ssh.gitea.svc.cluster.local.:22
- service: https://nginx-ingress-controller-ingress-nginx-controller.nginx-ingress.svc.cluster.local.:443
originRequest:
noTLSVerify: true
EOT
}
}
resource "kubernetes_secret" "cloudflared" {
metadata {
name = "cloudflared"
namespace = kubernetes_namespace.cloudflared.metadata[0].name
}
data = {
"credentials.json" = jsonencode({
"AccountTag" = var.cloudflare_account_id,
"TunnelID" = cloudflare_argo_tunnel.bootstrap.id,
"TunnelName" = cloudflare_argo_tunnel.bootstrap.name,
"TunnelSecret" = random_id.tunnel_secret.b64_std
})
}
type = "kubernetes.io/secret"
}