[英]Unable to deploy docker image to GKE using Jenkins
I'm running the Jenkins jenkinsci/blueocean docker image on a Mac and am trying to build and deploy an image to a Kube.netes cluster on GCP using a Jenkins pipeline (GKE plugin v0.8.3) but it fails --the image is built and added to the container registry (DockerHub) successfully but the deployment to GKE fails at the "Deploy to K8s" stage below.Jenkins does not display any error message.我在 Mac 上运行 Jenkins jenkinsci/blueocean docker 图像,并尝试使用 Jenkins 管道(GKE 插件 v0.8.3)构建图像并将其部署到 GCP 上的 Kube.netes 集群,但它失败了——图像是成功构建并添加到容器注册表 (DockerHub),但在下面的“部署到 K8s”阶段部署到 GKE 失败。Jenkins 不显示任何错误消息。 What am I doing wrong?我究竟做错了什么? Any help is much appreciated任何帮助深表感谢
My deployment.yaml file我的deployment.yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: mywebtestApp-deployment
labels:
app: mywebtestApp
spec:
replicas: 3
selector:
matchLabels:
app: mywebtestApp
template:
metadata:
labels:
app: mywebtestApp
spec:
containers:
- name: mywebtestApp
image: <mydockerhub>/<myimagename>:latest
ports:
- containerPort: 80
and my Jenkins file和我的 Jenkins 文件
pipeline {
agent any
environment {
............
stage('Deploy to K8s') {
steps{
echo 'Deployment started ...'
step([$class: 'KubernetesEngineBuilder', projectId: env.PROJECT_ID, clusterName: env.CLUSTER_NAME, location: env.LOCATION, manifestPattern: 'deployment.yaml', credentialsId: env.CREDENTIALS_ID, verifyDeployments: true])
echo "Deployment Finished ..."
}
}
}
}
If you will apply this Deployment
on your cluster you will get error:如果您将在您的集群上应用此Deployment
,您将收到错误消息:
The Deployment "mywebtestApp-deployment" is invalid:
* metadata.name: Invalid value: "mywebtestApp-deployment": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
* spec.template.spec.containers[0].name: Invalid value: "mywebtestApp": a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')
You cannot use capital letters.不能使用大写字母。
You have to change your labels from app: mywebtestApp
to app: mywebtestapp and deployment
name from name: mywebtestApp-deployment
to name: mywebtestApp-deployment
您必须将标签从app: mywebtestApp
为 app: mywebtestapp 并将deployment
名称从name: mywebtestApp-deployment
更改为name: mywebtestApp-deployment
After that changes you will be able to create deployment
.更改之后,您将能够创建deployment
。
$ kubectl apply -f deployment.yaml
deployment.apps/mywebtestapp-deployment created
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.