0

I am using Azure DevOps (Pipelines -> Pipelines) to create my CD pipeline to release to production. I understand that using Pipelines releases (Pipelines -> Releases) I am able to select and redeploy a previous release version. I would like to know if it is possible to do so using kubectl task rollout undo command in my Azure pipelines and how can I go about doing it. I appreciate if you could share your knowledge on this if you have previously encountered this.

The following is my kubectl task code in my Azure pipelines:

           - task: Kubernetes@1
            inputs:
              connectionType: 'Azure Resource Manager'
              azureSubscriptionEndpoint: 'Azure subscription 1(xxxxxxx-xxx-xxxxx-xxxxxxx)'
              azureResourceGroup: 'rg'
              kubernetesCluster: 'kc'
              command: 'apply'
              useConfigurationFile: true
              configuration: '$(Pipeline.Workspace)/manifests/'
              secretType: 'dockerRegistry'
              containerRegistryType: 'Azure Container Registry'

          - task: Kubernetes@1
            name: rollout_status
            inputs:
              connectionType: 'Azure Resource Manager'
              azureSubscriptionEndpoint: 'Azure subscription 1(xxxxxxx-xxx-xxxxx-xxxxxxx)'
              azureResourceGroup: 'rg'
              kubernetesCluster: 'kc'
              command: 'rollout'
              arguments: 'status deployment/deployment-name'
              secretType: 'dockerRegistry'
              containerRegistryType: 'Azure Container Registry'
          
          - task: Kubernetes@1
            name: rollout_undo
            condition: failed()
            inputs:
              connectionType: 'Azure Resource Manager'
              azureSubscriptionEndpoint: 'Azure subscription 1(xxxxxxx-xxx-xxxxx-xxxxxxx)'
              azureResourceGroup: 'rg'
              kubernetesCluster: 'kc'
              command: 'rollout'
              arguments: 'undo deployment/deployment-name'
              secretType: 'dockerRegistry'
              containerRegistryType: 'Azure Container Registry'
Richard Rodjues
  • 207
  • 1
  • 6
  • 23
  • Hi @Richard Rodjues. Is there any update about this ticket? Feel free to let me know if the answers could give you some help. Just a remind of [this](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). – Kevin Lu-MSFT Oct 15 '20 at 01:18
  • Yes, your answer does provide me with some understanding on kubernetes deployments revision. However, from the blog link you posted I would like to name my revision in the kubernetes deploymnt.yaml file. How should I go about it? I have tried adding the following in my deployment.yaml file but it's not working as intended: ```annotations:``` ```deployment.kubernetes.io/revision: "2"``` – Richard Rodjues Oct 20 '20 at 08:03
  • Hi @Richard Rodjues. For name the revision in kubernetes, it seems to be a new question about kubernetes. I suggest that you could create a new ticket about it. Then you will get more effective help. Please check if the answer could solve the question in this ticket. If it could work, you may consider accepting it. – Kevin Lu-MSFT Oct 20 '20 at 08:27

1 Answers1

0

From the Yaml sample, it should be able to roll back if the rollout_status step fails.

To rollback to a certain version, you could try to use the following command:

kubectl rollout undo deployment/deployment-name --to-revision=2

Please refer to this Blog:

By default Kubernetes stores the last 10 ReplicaSets and lets you roll back to any of them.

So you could add the parameter (--to-revision=x) to arguments to specify the revision.

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • 1
    I understand that kubernetes deployments keeps up to the last 10 replica sets in AKS, and does it mean if I specify the following parameter ```--to-revision=2```, it will roll back to the 2nd replica set? – Richard Rodjues Oct 20 '20 at 08:07
  • @RichardRodjues. Yes. You are right. You could use this command: `kubectl rollout history deployment/deployment-name` to get existing revisions.Then you can determine what you need – Kevin Lu-MSFT Oct 20 '20 at 08:12