Last active
January 28, 2022 11:57
-
-
Save bantic/7a714ab4be6dfb61a1cada8b597cabe1 to your computer and use it in GitHub Desktop.
Revisions
-
bantic revised this gist
Jan 28, 2022 . No changes.There are no files selected for viewing
-
bantic revised this gist
Jan 28, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ Example showing how to use a StatefulSet in coordination with a CronJob to run a Download k8s.yaml locally and then run: ``` kubectl apply -f k8s.yaml && \ kubectl rollout status statefulset/web && \ sleep 65 && \ for podNum in 0 1 2; do echo -n "Pod $podNum: "; kubectl exec pod/web-$podNum -- ls -1 / | grep cron || echo "<notfound>"; done -
bantic revised this gist
Jan 28, 2022 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,13 +7,13 @@ metadata: spec: selector: matchLabels: app: nginx # has to match .spec.template.metadata.labels serviceName: "nginx" replicas: 3 # by default is 1 template: metadata: labels: app: nginx # has to match .spec.selector.matchLabels spec: containers: - name: nginx @@ -38,5 +38,5 @@ spec: command: - /bin/sh - -c - kubectl exec pod/web-1 -- touch ran-cron restartPolicy: OnFailure -
bantic created this gist
Jan 28, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ Example showing how to use a StatefulSet in coordination with a CronJob to run a scheduled command on a *specific* pod. Download k8s.yaml locally and then run: ``` $ kubectl apply -f k8s.yaml && \ kubectl rollout status statefulset/web && \ sleep 65 && \ for podNum in 0 1 2; do echo -n "Pod $podNum: "; kubectl exec pod/web-$podNum -- ls -1 / | grep cron || echo "<notfound>"; done ``` Expected output: ``` statefulset.apps/web created cronjob.batch/crontest created Waiting for 3 pods to be ready... Waiting for 2 pods to be ready... Waiting for 1 pods to be ready... partitioned roll out complete: 3 new pods have been updated... Pod 0: <notfound> Pod 1: ran-cron // <-- cronjob runs against pod 1 only Pod 2: <notfound> ``` 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ # Slightly modified from the StatefulSet example at # https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/ apiVersion: apps/v1 kind: StatefulSet metadata: name: web spec: selector: matchLabels: app: nginx serviceName: "nginx" replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: alpine:latest command: [ "/bin/sh", "-c", "--" ] args: [ "while true; do sleep 30; done;" ] --- apiVersion: batch/v1beta1 kind: CronJob metadata: name: crontest spec: schedule: "* * * * *" jobTemplate: spec: template: spec: containers: - name: crontest image: alpine/k8s:1.20.7 imagePullPolicy: IfNotPresent command: - /bin/sh - -c - kubectl exec pod/web-1 -- "touch /FROMCRON" restartPolicy: OnFailure