Created
July 6, 2021 11:31
-
-
Save cmaster11/e0dfad2696d02c5a862bd1d83091fd18 to your computer and use it in GitHub Desktop.
Markdium-Restart Kubernetes deployments using HTTP requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: restart-helper | |
labels: | |
app: restart-helper | |
spec: | |
replicas: 1 | |
template: | |
metadata: | |
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 | |
# go-to-exec configuration | |
ports: | |
- containerPort: 7055 | |
name: http | |
readinessProbe: | |
httpGet: | |
port: 7055 | |
path: /healthz | |
scheme: HTTP | |
command: | |
- sh | |
- -c | |
- | | |
set -ex | |
GOTOEXEC_VERSION="v1.0.5" | |
GOTOEXEC="/gotoexec" | |
KUBECTL="/kubectl" | |
# Download the required tools | |
wget -O "$GOTOEXEC" "https://github.com/cmaster11/go-to-exec/releases/download/$GOTOEXEC_VERSION/gotoexec-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 "$GOTOEXEC" | |
chmod +x "$KUBECTL" | |
# Defines the configuration for go-to-exec | |
cat << EOF > /config.yaml | |
port: 7055 | |
listeners: | |
"/restart/:type/:name": | |
logOutput: true | |
logArgs: true | |
returnOutput: true | |
# Command to run, and list of arguments | |
command: "$KUBECTL" | |
args: | |
# Uncomment to force a specific namespace | |
# - -n | |
# - my-namespace | |
- rollout | |
- restart | |
- "{{ .type }}/{{ .name }}" | |
EOF | |
# By using `exec`, we replace the current process with | |
# go-to-exec one, which allows the program to receive all | |
# system signals. Necessary for graceful shutdown | |
exec $GOTOEXEC | |
restartPolicy: Always | |
selector: | |
matchLabels: | |
app: restart-helper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment