Skip to content

Instantly share code, notes, and snippets.

@adrianbumbas
Last active July 28, 2021 02:14
Show Gist options
  • Save adrianbumbas/96347d8de2dc7ba875325bc92f53f6f1 to your computer and use it in GitHub Desktop.
Save adrianbumbas/96347d8de2dc7ba875325bc92f53f6f1 to your computer and use it in GitHub Desktop.
Rollback Kubernetes deployments with Azure DevOps pipelines https://adrianbumbas.com/rollback-kubernetes-deployments-with-azure-devops-pipelines/
- task: Kubernetes@1
name: 'apply'
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'test'
namespace: 'default'
command: 'apply'
arguments: '-f deployment.yaml'
secretType: 'dockerRegistry'
containerRegistryType: 'Azure Container Registry'
outputFormat: "jsonpath={$.metadata.name}"
trigger:
- master
jobs:
- job: Deploy_to_AKS
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Kubernetes@1
name: 'apply'
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'test'
namespace: 'default'
command: 'apply'
arguments: '-f deployment.yaml'
secretType: 'dockerRegistry'
containerRegistryType: 'Azure Container Registry'
outputFormat: "jsonpath={$.metadata.name}"
- task: Kubernetes@1
name: rollout_status
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'test'
namespace: 'default'
command: rollout
arguments: status deployment/$(apply.KubectlOutput)
secretType: 'dockerRegistry'
containerRegistryType: 'Azure Container Registry'
- task: Kubernetes@1
name: rollout_undo
condition: failed()
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'test'
namespace: 'default'
command: rollout
arguments: undo deployment/$(apply.KubectlOutput)
secretType: 'dockerRegistry'
containerRegistryType: 'Azure Container Registry'
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
spec:
replicas: 3
progressDeadlineSeconds: 120
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app: hello-kubernetes
template:
metadata:
labels:
app: hello-kubernetes
spec:
containers:
- name: hello-kubernetes
image: gcr.io/google-samples/hello-app:1.0
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /
port: 8080
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
spec:
replicas: 3
progressDeadlineSeconds: 120
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app: hello-kubernetes
template:
metadata:
labels:
app: hello-kubernetes
spec:
containers:
- name: hello-kubernetes
# change here the image
image: ngnix:latest
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /
port: 8080
- task: Kubernetes@1
name: rollout_status
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'test'
namespace: 'default'
command: rollout
arguments: status deployment/$(apply.KubectlOutput)
secretType: 'dockerRegistry'
containerRegistryType: 'Azure Container Registry'
- task: Kubernetes@1
name: rollout_undo
# conditional execution
condition: failed()
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'test'
namespace: 'default'
command: rollout
arguments: undo deployment/$(apply.KubectlOutput)
secretType: 'dockerRegistry'
containerRegistryType: 'Azure Container Registry'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment