gitlab + GKE + AutoDevops自动部署部署失败。错误:资源/名称形式的参数必须具有单个资源和名称。如何发现错误?

时间:2019-09-11 12:50:07

标签: kubernetes deployment gitlab-ci

我是gitlab CI的新手。因此,我尝试使用https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml,通过自定义聊天https://gitlab.com/aidamir/citest/tree/master/chart将简单的测试django应用程序部署到gitlab项目的kubernetes集群。一切顺利,但是最后一刻,它显示了来自kubectl的错误消息,但它失败了。这是管道的输出:

Running with gitlab-runner 12.2.0 (a987417a)
  on docker-auto-scale 72989761
Using Docker executor with image registry.gitlab.com/gitlab-org/cluster-integration/auto-deploy-image:v0.1.0 ...
Running on runner-72989761-project-13952749-concurrent-0 via runner-72989761-srm-1568200144-ab3eb4d8...
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/myporject/kubetest/.git/
Created fresh repository.
From https://gitlab.com/myproject/kubetest
 * [new branch]      master     -> origin/master
Checking out 3efeaf21 as master...

Skipping Git submodules setup
Authenticating with credentials from job payload (GitLab Registry)
$ auto-deploy check_kube_domain
$ auto-deploy download_chart
Creating /root/.helm 
Creating /root/.helm/repository 
Creating /root/.helm/repository/cache 
Creating /root/.helm/repository/local 
Creating /root/.helm/plugins 
Creating /root/.helm/starters 
Creating /root/.helm/cache/archive 
Creating /root/.helm/repository/repositories.yaml 
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com 
Adding local repo with URL: http://127.0.0.1:8879/charts 
$HELM_HOME has been configured at /root/.helm.
Not installing Tiller due to 'client-only' flag having been set
"gitlab" has been added to your repositories
No requirements found in /builds/myproject/kubetest/chart/charts.
No requirements found in chart//charts.
$ auto-deploy ensure_namespace
NAME                           STATUS    AGE
kubetest-13952749-production   Active    46h
$ auto-deploy initialize_tiller
Checking Tiller...
Tiller is listening on localhost:44134
Client: &version.Version{SemVer:"v2.14.0", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}
[debug] SERVER: "localhost:44134"

Kubernetes: &version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.7-gke.24", GitCommit:"2ce02ef1754a457ba464ab87dba9090d90cf0468", GitTreeState:"clean", BuildDate:"2019-08-12T22:05:28Z", GoVersion:"go1.11.5b4", Compiler:"gc", Platform:"linux/amd64"}
Server: &version.Version{SemVer:"v2.14.0", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}

$ auto-deploy create_secret
Create secret...
secret "gitlab-registry" deleted
secret/gitlab-registry replaced
$ auto-deploy deploy
secret "production-secret" deleted
secret/production-secret replaced
Deploying new release...
Release "production" has been upgraded.
LAST DEPLOYED: Wed Sep 11 11:12:21 2019
NAMESPACE: kubetest-13952749-production
STATUS: DEPLOYED

RESOURCES:
==> v1/Deployment
NAME               READY  UP-TO-DATE  AVAILABLE  AGE
production-djtest  1/1    1           1          46h

==> v1/Job
NAME                        COMPLETIONS  DURATION  AGE
djtest-update-static-auik5  0/1          3s        3s

==> v1/PersistentVolumeClaim
NAME               STATUS  VOLUME  CAPACITY  ACCESS MODES  STORAGECLASS  AGE
nginx-storage-pvc  Bound   nfs     10Gi      RWX           3s

==> v1/Pod(related)
NAME                                READY  STATUS             RESTARTS  AGE
djtest-update-static-auik5-zxd6m    0/1    ContainerCreating  0         3s
production-djtest-5bf5665c4f-n5g78  1/1    Running            0         46h

==> v1/Service
NAME               TYPE       CLUSTER-IP  EXTERNAL-IP  PORT(S)   AGE
production-djtest  ClusterIP  10.0.0.146  <none>       5000/TCP  46h


NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace kubetest-13952749-production -l "app.kubernetes.io/name=djtest,app.kubernetes.io/instance=production" -o jsonpath="{.items[0].metadata.name}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl port-forward $POD_NAME 8080:80

error: arguments in resource/name form must have a single resource and name
ERROR: Job failed: exit code 1

请帮助我找到错误消息的原因。

我确实从图像注册表中查看了自动部署脚本。gitlab.com/ gitlab-org / cluster-integration / auto-deploy-image:v0.1.0。有一个设置变量可以禁用推出状态检查

  if [[ -z "$ROLLOUT_STATUS_DISABLED" ]]; then
    kubectl rollout status -n "$KUBE_NAMESPACE" -w "$ROLLOUT_RESOURCE_TYPE/$name"
  fi

因此设置

variables: 
   ROLLOUT_STATUS_DISABLED: "true"

防止作业失败。但是我仍然没有答案,为什么脚本不能与我的自定义聊天一起使用?。当我从笔记本电脑执行状态检查命令时,它没有显示任何错误。

kubectl rollout status -n kubetest-13952749-production -w "deployment/production-djtest"
deployment "production-djtest" successfully rolled out

我也发现了对类似问题的投诉 https://gitlab.com/gitlab-com/support-forum/issues/4737,但该帖子上没有任何活动。

这是我的gitlab-ci.yaml:

image: alpine:latest

variables:
  POSTGRES_ENABLED: "false"
  DOCKER_DRIVER: overlay2
  ROLLOUT_RESOURCE_TYPE: deployment
  DOCKER_TLS_CERTDIR: ""  # https://gitlab.com/gitlab-org/gitlab-runner/issues/4501

stages:
  - build
  - test
  - deploy  # dummy stage to follow the template guidelines
  - review
  - dast
  - staging
  - canary
  - production
  - incremental rollout 10%
  - incremental rollout 25%
  - incremental rollout 50%
  - incremental rollout 100%
  - performance
  - cleanup

include:
   - template: Jobs/Deploy.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml


variables:
   CI_APPLICATION_REPOSITORY: eu.gcr.io/myproject/django-test


2 个答案:

答案 0 :(得分:3)

  

错误:资源/名称形式的参数必须具有单个资源和名称

您链接到的该问题的状态为Closed (moved),因为它是从issue 66016转移而来的,我相信这是真正的答案:

  

请尝试将以下内容添加到您的.gitlab-ci.yml中:

variables:
  ROLLOUT_RESOURCE_TYPE: deployment

使用公正 Jobs/Deploy.gitlab-ci.yml省略了the variables: block from Auto-DevOps.gitlab-ci.yml,它可以正确设置该变量

对于您而言,我认为您只需要将variables:移到顶部,因为(afaik)一个人不能有两个顶层variables:块。我真的很惊讶您的.gitlab-ci.yml通过验证


另外,如果您还没有看到,可以将TRACE变量设置为switch auto-deploy into set -x mode,这对于查看确切的操作非常有用。我相信您的命令正在尝试运行rollout status /whatever-name,并且仅用斜杠表示,它不知道名称是什么。

答案 1 :(得分:0)

我在不同的上下文中遇到了这个错误。传递多个资源类型时不应该有空格。

kubectl get deploy, rs, po -l app=mynginx # 错

kubectl get deploy,rs,po -l app=mynginx # 对