Created
April 30, 2024 18:06
-
-
Save nickstenning/df84a2a88cc1518d6d5a5c22751a0c6a to your computer and use it in GitHub Desktop.
Running migrations in k8s
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: batch/v1 | |
kind: Job | |
metadata: | |
name: testjob | |
spec: | |
# Never retry this job. | |
backoffLimit: 0 | |
template: | |
spec: | |
containers: | |
- name: migrate | |
image: alpine:3.19 | |
command: ["sh", "-c", "for i in $(seq 20); do echo $i; sleep 1; done; exit 1"] | |
resources: | |
requests: | |
cpu: "1" | |
memory: 512Mi | |
restartPolicy: Never |
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
#!/bin/sh | |
# | |
set -eu | |
kubectl delete job/testjob 2>/dev/null || : | |
kubectl apply -f job.yaml | |
kubectl wait --for=condition=ready pod --selector=job-name=testjob --timeout=10m | |
kubectl logs -f job/testjob | |
if kubectl get job/testjob -o jsonpath='{.status.failed}' | grep -q '0'; then | |
echo "Job succeeded" | |
else | |
echo "Job failed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment