Kubernetes 部署 - 为图像拉取指定多个选项作为后备?

Kubernetes deployment - specify multiple options for image pull as a fallback?

我们所有可能的 docker 注册表(包括 Artifactory、AWS ECR 和 GitLab)都曾经或多次遇到过镜像拉取问题。甚至 DockerHub 偶尔也会出现问题。

在 Kubernetes 部署中是否有一种方法可以指定 pod 可以从多个不同的存储库获取图像,以便在一个存储库出现故障时回退?

如果不行,还有什么办法可以维稳?我见过像 Harbor 和 Trow 这样的东西,但它似乎是一个简单问题的笨拙解决方案。

Is there a way in a Kubernetes deployment to specify that a pod can get an image from multiple different repositories so it can fall back if one is down?

不是真的,不是天生的。如果你将它们放在像 TCP 负载均衡器这样的东西后面,将流量定向到多个注册表,你可能会欺骗 K8s 节点从不同的图像注册表中拉取图像(一次一个)。但这可能需要大量的测试和工作。

If not, what other solutions are there to maintain stability? I've seen things like Harbor and Trow, but it seems like a heavy handed solution to a simple problem.

我想说 Harbor, Quay, and Trow 是您想要更多冗余的方法。

Kubernetes 有 ability 来设置 ImagePullPolicy,你可以将它设置为 Never,如果你想 pre-pull 所有关键图像K8s 节点。您可以将此与某些自动化相关联,以 pre-pull 跨集群和节点的图像。

我实际上已经打开了一个 K8s feature request 看看这个想法是否获得了牵引力。

更新:

如果您使用 containerd or cri-o (or even 有注册表镜像)。您可以配置镜像注册表:

containerd.toml 例子

...
    [plugins.cri.registry]
      [plugins.cri.registry.mirrors]
        [plugins.cri.registry.mirrors."docker.io"]
          endpoint = ["https://registry-1.docker.io"]
        [plugins.cri.registry.mirrors."local.insecure-registry.io"]
          endpoint = ["http://localhost:32000"]
        [plugins.cri.registry.mirrors."gcr.io"]
          endpoint = ["https://gcr.io"]
      [plugins.cri.registry.configs]
        [plugins.cri.registry.configs.auths]
          [plugins.cri.registry.configs.auths."https://gcr.io"]
            auth = "xxxxx...."
...

cri-o.conf example

...
# registries is used to specify a comma separated list of registries to be used
# when pulling an unqualified image (e.g. fedora:rawhide).
registries = [
“registry.example.xyz”,
“registry.fedoraproject.org”
]
...

✌️