Created
May 16, 2024 08:14
-
-
Save keyan1603/e1a0552394f7b85e984dc5eb2e838dd4 to your computer and use it in GitHub Desktop.
Jenkins script to gracefully rollout nodes when the deployment strategy is rollout deployment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
agent any | |
stages{ | |
stage('Logging into AWS ECR'){ | |
steps{ | |
bat 'aws eks --region us-east-1 update-kubeconfig --name eks-cluster-name' | |
bat 'aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin xxxxxxxxxxx.xxx.ecr.us-east-1.amazonaws.com' | |
} | |
} | |
stage('Cordon all nodes') { | |
steps { | |
bat 'powershell -command \"kubectl get nodes | ForEach-Object{($_.Split(\\\"" "\\\"))[0]} | where {$_ -ne \\\""NAME"\\\"} | ForEach-Object{(kubectl cordon $_)}\"' | |
} | |
} | |
stage('Rollout Master node') { | |
steps { | |
bat 'powershell -command \"kubectl get deployments -n kube-system| ForEach-Object{($_.Split(\\\"" "\\\"))[0]} | where {$_ -ne \\\""NAME"\\\"} | ForEach-Object{(kubectl -n kube-system rollout restart deployment $_)}\"' | |
bat 'powershell -command \"kubectl get deployments -n kubernetes-dashboard| ForEach-Object{($_.Split(\\\"" "\\\"))[0]} | where {$_ -ne \\\""NAME"\\\"} | ForEach-Object{(kubectl -n kubernetes-dashboard rollout restart deployment $_)}\"' | |
} | |
} | |
stage('Rollout Worker nodes') { | |
steps { | |
bat 'powershell -command \"kubectl get deployments | ForEach-Object{($_.Split(\\\"" "\\\"))[0]} | where {$_ -ne \\\""NAME"\\\"} | ForEach-Object{(kubectl rollout restart deployment $_)}\"' | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment