繁体   English   中英

使Kubernetes集群在多个位置搜索图像

[英]Make Kubernetes cluster search for image in multiple places

我只想按名称和摘要引用容器映像,而不要按完整的URI引用。

我已经强烈提及提及Docker映像的Kubernetes对象规范文件。 我们有几个带有多个子目录的私有容器映像存储库(prod,staging,dev)。

我需要一种无需修改Kubernetes对象规范文件即可指定docker映像“搜索前缀”的方法。

示例:我有一个签入的哈希文件,其中包含以下行:

image: something@sha256:2635462354664526623546235645264

首先将映像推送到gcr.io/dev-bucket/commit-hash/something 然后将其复制到gcr.io/staging-bucket/commit-hash/something ,最后复制到gcr.io/prod-bucket/something

我希望能够告诉Kubernetes可能的图像搜索位置/前缀,以便我可以使用该目标文件而无需进行任何更改。 (当文件形成一个高度哈希的树时,修改文件成为一个大问题。)

我认为您可以使用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

请检查带有外部Kubernetes指南的Google Cloud Registry(GCR) ,以及如何从私有注册表中提取映像

不要忘记在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文件即可在不同环境中部署同一映像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM