I'm working on deploying a docker image in kubernetes. The first time I deployed the container, I used:
kubectl apply -f <deployment_file>.yaml
and the container was successfully deployed in a pod.
Also, the deployment_file looks something like this:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: publisher
spec:
replicas: 2
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 300
progressDeadlineSeconds: 900
template:
metadata:
labels:
app: publisher
spec:
containers:
- name: publisher
image: 123dev.azurecr.io/publisher:{{ci-build-number}}
env:
- name: ENVIRONMENT
value: "dev"
ports:
- containerPort: 8080
I have defined the 'progressDeadlineSeconds' attribute in the yaml file above.
To keep a track of the deployment, I used:
kubectl rollout status deployment.v1beta1.apps/publisher
Now if I want to update the container with a new image, I can again reuse the command
kubectl apply -f <deployment_file>.yaml
to apply the update.
But what if applying the update fails due to some reason (let's say the docker image is corrupt), is there a way to automatically trigger a rollback to the previous revision when - pods status is not set to 'running' OR the execution time crosses 'pregressDeadlineSeconds'?
Till now I haven't found a way to execute a rollback automatically. Thoughts would be appreciated.