<p>I'm working on deploying a docker image in kubernetes. The first time I deployed the container, I used:</p>

<pre><code>kubectl apply -f &lt;deployment_file&gt;.yaml
</code></pre>

<p>and the container was successfully deployed in a pod.</p>

<p>Also, the deployment_file looks something like this:</p>

<pre><code>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

</code></pre>

<p>I have defined the 'progressDeadlineSeconds' attribute in the yaml file above.</p>

<p>To keep a track of the deployment, I used:</p>

<pre><code>kubectl rollout status deployment.v1beta1.apps/publisher
</code></pre>

<p>Now if I want to update the container with a new image, I can again reuse the command</p>

<pre><code>kubectl apply -f &lt;deployment_file&gt;.yaml
</code></pre>

<p>to apply the update.</p>

<p>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'?</p>

<p>Till now I haven't found a way to execute a rollback automatically. Thoughts would be appreciated.</p>

Swastik Gupta
<p>follow the below steps. </p>

<pre><code>1. append the --record param to deployment, as shown below
kubectl apply -f &lt;deployment_file&gt;.yaml --record

2. kubectl rollout history deploy &lt;deployment-name&gt; to check deployment history. for example,
kubectl rollout history deploy mynginx
deployments "mynginx"
REVISION  CHANGE-CAUSE
3         kubectl set image deploy mynginx mynginx=nginx:1.12.2
4         kubectl set image deploy mynginx mynginx=nginx:1.13.8


3. you can rollback to previous version using revision, say to revision 3
kubectl rollout undo deploy mynginx --to-revision=3
</code></pre>
