使用 kustomization.yaml 更改图像标签和名称
Changing image tags and name with kustomization.yaml
根据 official documentation,我应该能够使用一些巧妙的 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
中指定的原始名称)。
所以我的问题是,我做错了什么?
您可以 运行 kustomize build my-kustomization-dir
检查 yaml 中的图像是否被替换 file.This 命令让您看到将在您的集群中应用什么。
您必须删除图像部分下 newName 行中的“-”。应该是这样的,成功了
images:
- name: the-my-app
newName: my.docker.registry.com/my-project/my-app
newTag: test
根据 official documentation,我应该能够使用一些巧妙的 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
中指定的原始名称)。
所以我的问题是,我做错了什么?
您可以 运行 kustomize build my-kustomization-dir
检查 yaml 中的图像是否被替换 file.This 命令让您看到将在您的集群中应用什么。
您必须删除图像部分下 newName 行中的“-”。应该是这样的,成功了
images:
- name: the-my-app
newName: my.docker.registry.com/my-project/my-app
newTag: test