4

根据官方文档,我应该能够使用一些漂亮的kustomization语法轻松地覆盖我的 docker 图像的标签和名称。我试图重现这一点。

在我的deployment.yaml我有以下内容:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    service: my-app
  name: my-app
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        service: my-app
    spec:
      imagePullSecrets:
      - name: my-docker-secret
      containers:
      - name: my-app
        image: the-my-app
        imagePullPolicy: Always
        ports:
        - containerPort: 1234
      restartPolicy: Always

在我的kustomization.yaml我有以下内容:

bases:
- ../base
resources:
- deployment.yaml
namespace: my-namespace

images:
- name: the-my-app
- newName: my.docker.registry.com/my-project/my-app
  newTag: test

但是,当我这样做时:

kubectl apply -k my-kustomization-dir

并等待部署启动,然后再做

kubectl describe pod/my-app-xxxxxxxxx-xxxxx

事件如下所示:

Events:
  Type     Reason                  Age                From                                              Message
  ----     ------                  ----               ----                                              -------
  Successfully assigned my-namespace/my-app-xxxxxxxxxx-xxxxx to default-pool-xxxxxxxxxx-xxxxx
  Normal   Pulling                 2s                 kubelet, default-pool-xxxxxxxxxx-xxxxx  pulling image "the-my-app"
  Warning  Failed                  0s                 kubelet, default-pool-xxxxxxxxxx-xxxxx  Failed to pull image "the-my-app": rpc error: code = Unknown desc = Error response from daemon: pull access denied for the-my-app, repository does not exist or may require 'docker login'
  Warning  Failed                  0s                 kubelet, default-pool-xxxxxxxxxx-xxxxx  Error: ErrImagePull
  Normal   BackOff                 0s                 kubelet, default-pool-xxxxxxxxxx-xxxxx  Back-off pulling image "the-my-app"
  Warning  Failed                  0s                 kubelet, default-pool-xxxxxxxxxx-xxxxx  Error: ImagePullBackOff

表明这没有按预期工作(它试图提取 中指定的原始名称deployment.yaml)。

所以我的问题是,我在这里做错了什么?

4

2 回答 2

8

您必须在图像部分下的 newName 行中删除“-”。它应该是这样的,它是有效的。

 images:
 - name: the-my-app
   newName: my.docker.registry.com/my-project/my-app
   newTag: test
于 2020-02-21T07:23:36.917 回答
5

您可以运行kustomize build my-kustomization-dir以检查 yaml 文件中的图像是否被替换。此命令可让您查看将在集群中应用的内容。

于 2020-02-21T05:12:33.070 回答