我认为你可以使用imagePullSecrets。
您应该使用 URL 创建一个 docker-registry 密码以及每个阶段/存储桶所需的所有身份验证。
kubectl create secret docker-registry dev-bucket --docker-server=https://hub.docker.com --docker-username=user --docker-email=user@example.com --docker-password=password
然后在创建POD 时,您应该执行以下操作:
apiVersion: v1
kind: Pod
metadata:
name: test-pod
spec:
containers:
- name: test-container
image: <registry_name>/<image_name>:<tagname>
imagePullSecrets:
- name: dev-bucket
请查看Google Cloud Registry (GCR) with external Kubernetes 指南以及如何使用Pull an Image from a Private Registry
不要忘记在 gcloud 中创建服务帐户,并拥有 GCR 权限和服务帐户的密钥。
您应该将tags 添加到您的图片中,这样您就可以将一张图片推送到不同的标签。
编辑:
这是一个例子:
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest
现在我们将为其添加新标签
$ docker tag hello-world gcr.io/project-for-x/hello-world:dev_latest
$ docker push gcr.io/project-for-x/hello-world:dev_latest
The push refers to repository [gcr.io/project-for-x/hello-world]
428c97da766c: Layer already exists
dev_latest: digest: sha256:1a6fd470b9ce10849be79e99529a88371dff60c60aab424c077007f6979b4812 size: 524
$ docker tag hello-world gcr.io/project-for-x/hello-world:stage_latest
$ docker push gcr.io/project-for-x/hello-world:stage_latest
The push refers to repository [gcr.io/project-for-x/hello-world]
428c97da766c: Layer already exists
stage_latest: digest: sha256:1a6fd470b9ce10849be79e99529a88371dff60c60aab424c077007f6979b4812 size: 524
$ docker tag hello-world gcr.io/project-for-x/hello-world:prod_latest
$ docker push gcr.io/project-for-x/hello-world:prod_latest
The push refers to repository [gcr.io/project-for-x/hello-world]
428c97da766c: Layer already exists
prod_latest: digest: sha256:1a6fd470b9ce10849be79e99529a88371dff60c60aab424c077007f6979b4812 size: 524
这在 GCR 中创建了一个 hello-world 文件
General information
Image type Docker Manifest, Schema 2
Media type :application/vnd.docker.distribution.manifest.v2+json
Virtual size :977 B
Uploaded time :October 24, 2018 at 3:07:49 PM UTC+2
Build ID :—
Container classification
Digest: sha256:1a6fd470b9ce10849be79e99529a88371dff60c60aab424c077007f6979b4812
Tags: dev_latest prod_latest stage_latest
Repository: hello-world
Project: project-for-x
这样您就可以只使用一个yaml 文件来在不同的环境中部署相同的映像。