Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

255
Visualizações
How to roll back a deployment to a previous revision automatically when deployment has crossed 'progressDeadlineSeconds'?

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.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

follow the below steps.

1. append the --record param to deployment, as shown below
kubectl apply -f <deployment_file>.yaml --record

2. kubectl rollout history deploy <deployment-name> 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
over 4 years ago · Santiago Trujillo Relatório

0

After the kubectl apply command you can check if the deployment rolled out successfully or not and then, if necessary, the kubectl rollout undo command can rollback to the previous revision. Also, you can use the sleep Linux command to wait some time before that.

On Linux:

sleep 900 && \
if [[ $(timeout 5 kubectl rollout status -f <deployment_file>.yaml) != *"successfully rolled out"* ]]; then     
    kubectl rollout undo -f <deployment_file>.yaml
fi > /dev/null 2>&1 &

timeout 5 stops the kubectl rollout status if its stuck after 5 seconds.

> /dev/null 2>&1 & runs the command in the background and without terminal output.

over 4 years ago · Santiago Trujillo Relatório

0

This is the steps which I follow to undo the rollout of a deployment

Here client-depl is the name of the deployment

Step.1 To get the list of history of a specific deployment use this command

kubectl rollout history deploy client-depl

after that you will get output like this.

rollout history deploy image

so let say I want to rollout the deployment to REVISION 1 then use this command

$ kubectl rollout undo deploy client-depl --to-revision=1

after that you will get output like this

deployment rollback image

congratulations you have successfully rollout the deployment to previous version. For any doubt please reply will happy to help you.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda