This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
k8s-restart-helper.yaml
139 lines (130 loc) · 3.41 KB
/
k8s-restart-helper.yaml
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
133
134
135
136
137
138
139
apiVersion: v1
kind: ServiceAccount
metadata:
name: restart-helper
---
# Allows the service account to:
#
# - Get namespaces.
# - Get/patch our deployments and statefulsets, to allow the
# "restart rollout" command to work.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: restart-helper
rules:
- apiGroups: [ "" ]
resources: [ "namespaces" ]
verbs: [ "get" ]
- apiGroups: [ "apps", "extensions" ]
resources: [ "deployments", "statefulsets" ]
verbs: [ "get", "patch" ]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: restart-helper
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: restart-helper
subjects:
- kind: ServiceAccount
name: restart-helper
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: restart-helper
labels:
app: restart-helper
spec:
replicas: 1
template:
metadata:
annotations:
# Increase to force a restart
bump: bump-1
name: restart-helper
labels:
app: restart-helper
spec:
# Binds to the previously created service account
serviceAccountName: restart-helper
containers:
- name: restart-helper
image: alpine:3.14.0
imagePullPolicy: IfNotPresent
# The port needs to be the same as the one defined in
# qvalet configuration
ports:
- containerPort: 7055
name: http
readinessProbe:
httpGet:
port: 7055
path: /healthz
scheme: HTTP
command:
- sh
- -c
- |
set -ex
QVALET_VERSION="v2.0.0"
QVALET="/qvalet"
KUBECTL="/kubectl"
# Download the required tools
wget -O "$QVALET" "https://github.com/cmaster11/qvalet/releases/download/$QVALET_VERSION/qvalet-linux-amd64"
wget -O "$KUBECTL" "https://dl.k8s.io/release/$(wget -O- https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x "$QVALET"
chmod +x "$KUBECTL"
# Defines the configuration for qvalet
cat << EOF > /config.yaml
listeners:
"/restart/:type/:name":
log: all
return: output
# Command to run, and list of arguments
command: "$KUBECTL"
args:
- rollout
- restart
- "{{ .type }}/{{ .name }}"
EOF
# By using `exec`, we replace the current process with
# qvalet one, which allows the program to receive all
# system signals. Necessary for graceful shutdown
exec $QVALET
restartPolicy: Always
selector:
matchLabels:
app: restart-helper
---
apiVersion: v1
kind: Service
metadata:
name: restart-helper
spec:
selector:
app: restart-helper
ports:
- port: 7055
name: http
---
# Uncomment to use the default ingress resource type
#apiVersion: networking.k8s.io/v1
#kind: Ingress
#metadata:
# name: restart-helper
#spec:
# rules:
# - host: myhost.mydomain.com
# http:
# paths:
# - path: /
# pathType: Prefix
# backend:
# service:
# name: restart-helper
# port:
# number: 7055