根据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
中指定的原始名称)。
所以我的问题是,我在这里做错了什么?
答案 0 :(得分:2)
您必须在图像部分下的newName行中删除“-”。应该是这样,它是可行的。
images:
- name: the-my-app
newName: my.docker.registry.com/my-project/my-app
newTag: test
答案 1 :(得分:1)
您可以运行kustomize build my-kustomization-dir
来检查图像是否在yaml文件中被替换。此命令使您可以查看将在集群中应用的图像。