gitlab + GKE + AutoDevops 自动部署部署失败. 错误:资源/名称表单中的参数必须具有单个资源和名



我是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

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

我确实从映像 registry.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

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

您链接到的该问题的状态Closed (moved),因为它是从问题 66016 中移出的,我认为这是真正的答案:

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

variables:
ROLLOUT_RESOURCE_TYPE: deployment

使用Jobs/Deploy.gitlab-ci.yml会从正确设置该变量的Auto-DevOps.gitlab-ci.yml中省略variables:

在您的情况下,我认为您只需要将该variables:移动到顶部,因为(afaik(不能有两个顶级variables:块。我真的很惊讶你的.gitlab-ci.yml通过了验证


另外,如果您还没有看到,您可以设置TRACE变量以将自动部署切换到set -x模式,这对于准确了解它正在尝试做什么非常有帮助。我相信你的命令试图运行rollout status /whatever-name,只有一个斜杠,它不知道那是什么名字。

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

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

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