我正在尝试将docker映像部署到kubernetes,但是遇到了一个奇怪的问题。下面是我在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}'
}
}
我收到此错误消息
奇怪的是,如果我复制并粘贴此命令并在群集上执行,则图像会更新 kubectl设置映像部署/ nginx部署nginx = account / repo:69 有人可以帮忙,将映像成功构建并推送到Docker Hub,只是我一直坚持将其部署和部署到kubernetes集群,如果还有其他选择,请告诉我,被复制到服务器的deploy.yml文件是如下
spec:
containers:
- name: nginx
image: account/repo:3
ports:
- containerPort: 80
答案 0 :(得分:1)
好吧,如果找到解决方法。如果我在docker文件中更改了这一行
sh "ssh ubuntu@<ip> kubectl apply -f ." to
sh "ssh ubuntu@<ip> kubectl set image deployment/nginx-deployment
nginx=account/repo:${BUILD_NUMBER}"
它可以工作,但是如果根本没有创建任何部署,那么我必须添加这两行使其起作用
sh "ssh ubuntu@<ip> kubectl apply -f ."
sh "ssh ubuntu@<ip> kubectl set image deployment/nginx-deployment
nginx=account/repo:${BUILD_NUMBER}"