-
Notifications
You must be signed in to change notification settings - Fork 6
/
consul-template.sh
executable file
·50 lines (42 loc) · 1.3 KB
/
consul-template.sh
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
#!/bin/bash
set -e
# VAULT_TOKEN=$(grep "token " /dev/shm/kubernetes/KUBELET_TOKEN | awk '{print $2}') ROLE=kubelet CN=kubelet bash -x consul-template.sh
cat <<EOF >/tmp/${ROLE}-ca.tpl
{{ with secret "kubernetes/issue/${ROLE}" "common_name=${CN}" "alt_names=${ALT_NAMES}" "ip_sans=${IP_SANS}" "ttl=${TTL}" -}}
{{ range .Data.ca_chain -}}
{{ . }}
{{ end -}}
{{ end -}}
EOF
cat <<EOF >/tmp/${ROLE}-cert.tpl
{{ with secret "kubernetes/issue/${ROLE}" "common_name=${CN}" "alt_names=${ALT_NAMES}" "ip_sans=${IP_SANS}" "ttl=${TTL}" -}}
{{ .Data.certificate }}
{{ end -}}
EOF
cat <<EOF >/tmp/${ROLE}-key.tpl
{{ with secret "kubernetes/issue/${ROLE}" "common_name=${CN}" "alt_names=${ALT_NAMES}" "ip_sans=${IP_SANS}" "ttl=${TTL}" -}}
{{ .Data.private_key }}
{{ end -}}
EOF
cat <<EOF >/tmp/${ROLE}.hcl
template {
source = "/tmp/${ROLE}-cert.tpl"
destination = "/dev/shm/kubernetes/${ROLE}-cert.pem"
}
template {
source = "/tmp/${ROLE}-ca.tpl"
destination = "/dev/shm/kubernetes/${ROLE}-ca.pem"
}
template {
source = "/tmp/${ROLE}-key.tpl"
destination = "/dev/shm/kubernetes/${ROLE}-key.pem"
command = "${COMMAND}"
}
EOF
consul-template \
-config=/tmp/${ROLE}.hcl \
-vault-retry-attempts=5 \
-log-level=info \
-vault-ssl-verify=false \
-vault-renew-token=true \
-vault-token=${VAULT_TOKEN}