简体   繁体   English

无法使用 Jenkins 将 docker 映像部署到 GKE

[英]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.

相关问题 无法在使用“带有 Docker 的 Ubuntu”映像创建的 GKE 集群上部署 pod - Unable to deploy pods on GKE cluster created using 'Ubuntu with Docker' image 如何使用 Terraform 使用来自 Artifact Registry 的 Docker 映像部署 GKE 工作负载? - How do I deploy a GKE Workload with my Docker image from the Artifact Registry using Terraform? 无法使用 CloudSQL Postgres 数据库在 GKE 集群上部署后台 - Unable to deploy backstage on GKE cluster with CloudSQL Postgres database 图片权限在 jenkins docker 代理 - Image permission in jenkins docker agent Jenkins Docker 容器无法访问 GKE Autopilot 中的 docker.sock - Jenkins Docker Container can't access docker.sock in GKE Autopilot 如何在 aws ec2 中使用 jenkins docker 容器设置部署 nodejs 应用程序 - How to setup deploy nodejs app using jenkins docker container in aws ec2 无法使用来自另一个项目的图像部署 Cloud Run 服务 - Unable to deploy a Cloud Run Service using an image from another project 在 Cloud Run 上部署客户端的 docker 映像 - Deploy the docker image of a client on Cloud Run 如何将Docker镜像推送到Jenkins中的ECR? - How to push Docker image to ECR in Jenkins? 云部署对私有 GKE 的访问 - Cloud Deploy Access to Private GKE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM