Reputation: 1769
I am trying to deploy docker image to kubernetes but hitting a strange issue. Below is the command i am using in jenkinsfile
stage('Deploy to k8s') {
steps{
sshagent(['kops-machine']) {
sh "scp -o StrictHostKeyChecking=no deployment.yml ubuntu@<ip>:/home/ubuntu/"
sh "ssh ubuntu@<ip> kubectl apply -f ."
sh 'kubectl set image deployment/nginx-deployment nginx=account/repo:${BUILD_NUMBER}'
}
}
I am getting this error message
Strange thing is if i copy and paste this command and execute on the cluster, the image gets updated kubectl set image deployment/nginx-deployment nginx=account/repo:69 Can somebody please help, image builds and pushes to docker hub successfully, its just that i am stuck with pulling and deploying to kubernetes cluster, if you have anyother alternatives please let me know, the deployment.yml file which gets copied to the server is as follows
spec:
containers:
- name: nginx
image: account/repo:3
ports:
- containerPort: 80
Upvotes: 0
Views: 212
Reputation: 1769
Ok so if found the work around. if i change this line in my docker file
sh "ssh ubuntu@<ip> kubectl apply -f ." to
sh "ssh ubuntu@<ip> kubectl set image deployment/nginx-deployment
nginx=account/repo:${BUILD_NUMBER}"
It works, but if there is no deployment created at all, then i have to add these two line to make it work
sh "ssh ubuntu@<ip> kubectl apply -f ."
sh "ssh ubuntu@<ip> kubectl set image deployment/nginx-deployment
nginx=account/repo:${BUILD_NUMBER}"
Upvotes: 1