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

时间:2020-09-22 18:14:59

标签: jenkins-pipeline google-kubernetes-engine

我正在Mac上运行Jenkins jenkinsci / blueocean docker映像,并尝试使用Jenkins管道(GKE插件v0.8.3)在GCP上将映像构建并将其部署到Kubernetes集群上,但是失败了-该映像已成功构建并添加到容器注册表(DockerHub),但在下面的“部署到K8s”阶段,部署到GKE失败。Jenkins不显示任何错误消息。我究竟做错了什么?任何帮助都非常感激

我的deployment.yaml文件

$('.task-header').click(clickFunction)

function clickFunction () {
  let headerGroupNumber = this.getAttribute('data-headergroup')
  if ($('.task-description').is(":visible")) {
    $(".task-description[data-headergroup='" + headerGroupNumber +"']").hide()
  } else {
     $(".task-description[data-headergroup='" + headerGroupNumber +"']").show()
  } 
}

和我的Jenkins文件

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 

1 个答案:

答案 0 :(得分:0)

如果您将此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])?')

您不能使用大写字母。

您必须将标签从app: mywebtestApp更改为应用程序:mywebtestapp和deployment的名称从name: mywebtestApp-deployment更改为name: mywebtestApp-deployment

更改之后,您将可以创建deployment

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