Complete the code to define a Jenkins pipeline stage for canary deployment.
stage('Canary Deployment') { steps { script { sh 'kubectl apply -f [1]' } } }
The canary deployment YAML file is applied to start the canary release.
Complete the code to set the percentage of traffic to route to the canary version.
environment {
CANARY_PERCENT = '[1]'
}Typically, canary deployments start with a small percentage like 10% of traffic.
Fix the error in the command to update the service to route traffic to the canary deployment.
sh 'kubectl patch svc my-service -p "[1]"'
The service selector must point to the canary version to route traffic correctly.
Fill both blanks to define a Jenkins pipeline step that waits for the canary deployment to be ready and then verifies it.
stage('Verify Canary') { steps { sh 'kubectl rollout status deployment/[1]' sh 'curl -f http://[2]/health || exit 1' } }
The rollout status checks the canary deployment named 'canary-app'. The health check uses the canary service URL.
Fill all three blanks to define a Jenkins pipeline snippet that promotes the canary to production by updating the deployment and service selectors.
stage('Promote Canary') { steps { sh 'kubectl patch deployment [1] -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"version\":\"[2]\"}}}}}"' sh 'kubectl patch svc [3] -p "{\"spec\":{\"selector\":{\"version\":\"[2]\"}}}"' } }
The production deployment is patched to use the 'canary' version label. The production service selector is updated to route to the 'canary' version, effectively promoting it.