Last active
July 19, 2020 18:16
-
-
Save erkanerol/528eab81c0db1cdcc3b9a13560d58047 to your computer and use it in GitHub Desktop.
A deployment example which shows deployments do not restart pods in Crashloopbackoff state
This file contains 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
# USAGE: kubectl apply -f demo-deployment.yaml | |
# Wait 1 minute | |
# Observe all pods are in CrashLoopBackOff state | |
# Observe deployment controller does not restart pods | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: crashloopbackoff-demo | |
labels: | |
status: crashloopbackoff | |
spec: | |
replicas: 3 | |
selector: | |
matchLabels: | |
status: crashloopbackoff | |
template: | |
metadata: | |
labels: | |
status: crashloopbackoff | |
spec: | |
initContainers: | |
# computes the current time and store into the shared volume | |
- name: init-container | |
image: busybox:1.28 | |
command: ['sh', '-c', 'date +%s > /tmp/shared/start-time'] | |
volumeMounts: | |
- name: time-storage | |
mountPath: /tmp/shared | |
# loads start time from file created by init container | |
# removes the file so restarted containers will fail immediately | |
# waits 1 minute and crash | |
# shortly -> enters CrashLoopBackOff after 1 minute. | |
containers: | |
- name: main-container | |
image: busybox:1.28 | |
command: ['sh', '-c', 'start=$(cat /tmp/shared/start-time) && rm /tmp/shared/start-time && while true; do current=$(date +%s); let diff="$current - $start"; echo $diff; [[ "$diff" -gt 60 ]] && exit 1; sleep 2; done'] | |
volumeMounts: | |
- name: time-storage | |
mountPath: /tmp/shared | |
volumes: | |
- name: time-storage | |
emptyDir: {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment