简体   繁体   中英

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. What am I doing wrong? Any help is much appreciated

My deployment.yaml file

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

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:

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

After that changes you will be able to create deployment .

$ kubectl apply -f deployment.yaml
deployment.apps/mywebtestapp-deployment created

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM