简体   繁体   English

k8s:使 k8s 可以访问本地图像

[英]k8s: make local image accessible for k8s

I've just installed a k8s cluster (k3d).我刚刚安装了一个 k8s 集群(k3d)。

I'm just playing with that and I'm running against the first newbie issue: How to load our local created images.我只是在玩这个,我正在解决第一个新手问题:如何加载我们本地创建的图像。

I mean, I've just created a docker image tagged as quarkus/feedly:v1 .我的意思是,我刚刚创建了一个quarkus/feedly:v1镜像,标记为quarkus/feedly:v1

  1. How could I make it accessible for k8s cluster?如何使其可用于 k8s 集群?
  2. Which is the default k8s container runtime?哪个是默认的 k8s 容器运行时?
  3. Does exist any interaction with my k8s cluster and my local docker?我的 k8s 集群和我的本地 docker 是否存在任何交互? I mean, Have each k8s node installed a docker/rkt/containerd runtime?我的意思是,每个 k8s 节点都安装了 docker/rkt/containerd 运行时吗?
  4. Could I create a docker registry inside kubernetes, as a manifest?我可以在 kubernetes 中创建一个 docker 注册表作为清单吗? How could I make that kubernetes make access to it?我怎样才能让 kubernetes 访问它?

I've deployed my manifest and I'm getting these events:我已经部署了我的清单,并且收到了这些事件:

Failed to pull image "quarkus/feedly:0.0.1-SNAPSHOT": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/quarkus/feedly:0.0.1-SNAPSHOT": failed to resolve reference "docker.io/quarkus/feedly:0.0.1-SNAPSHOT": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed无法拉取图像“quarkus/feedly:0.0.1-SNAPSHOT”:rpc 错误:代码 = 未知描述 = 无法拉取和解压图像“docker.io/quarkus/feedly:0.0.1-SNAPSHOT”:无法解析参考“docker.io/quarkus/feedly:0.0.1-SNAPSHOT”:拉取访问被拒绝,存储库不存在或可能需要授权:服务器消息:不足范围:授权失败

I know it's a normal error since quarkus registry doesn't exist.我知道这是一个正常错误,因为 quarkus 注册表不存在。

Any helping code over there?那里有帮助代码吗?

Here are some pointers :这里有一些提示:

  1. To make your image accessible through your k8s cluster, you need to use a registry that is accessible from your cluster node.要通过 k8s 集群访问您的映像,您需要使用可从集群节点访问的注册表。 So either, create an account on the docker hub and use this one, or install a local image registry and use it.因此,要么在 docker hub 上创建一个帐户并使用这个帐户,要么安装一个本地映像注册表并使用它。
  2. Docker is the default container runtime used by a majority of k8s distribution. Docker 是大多数 k8s 发行版使用的默认容器运行时。 However, you can use any OCI compatible runtime (containerd for example).但是,您可以使用任何 OCI 兼容的运行时(例如,containerd)。 rkt is no longer a living project, so i advise not to use it. rkt 不再是一个活项目,所以我建议不要使用它。
  3. Well, it depends on the k8s distribution you're using.好吧,这取决于您使用的 k8s 发行版。 Anyway, each nodes on the cluster need a container runtime installed on it.无论如何,集群上的每个节点都需要在其上安装一个容器运行时。 It is mandatory.这是强制性的。
  4. Deploying a Docker registry as a kubernetes resource is probably not a good idea, as you'll have to much configuration to make it work.将 Docker 注册表部署为 kubernetes 资源可能不是一个好主意,因为您必须进行大量配置才能使其工作。 However, the best solution is to deploy a docker registry inside one of your node and then call it using the node IP.但是,最好的解决方案是在您的节点之一内部署 docker 注册表,然后使用节点 IP 调用它。 You have a configuration example in the official doc .您在官方文档中有一个配置示例。 By the way, Docker provide a registry as a Docker image , so the installation is pretty simple.顺便说一下,Docker 提供了一个注册表作为Docker 镜像,所以安装非常简单。

Hope this helps !希望这可以帮助 !

If you are using k3d, and this is just for playing around ( Not Production intended ) and for any reason don't want to use any of the many Container Registries that are out there such:如果您使用的是 k3d,并且这只是为了玩耍(不是用于生产),并且出于任何原因不想使用现有的许多容器注册表中的任何一个,例如:

You could add registries by specifying them in a registries.yaml您可以通过在registries.yaml指定它们来添加registries.yaml

k3d cluster create mycluster --volume "/home/YOU/my-registries.yaml:/etc/rancher/k3s/registries.yaml"

and create your own registry locally using docker:并使用 docker 在本地创建您自己的注册表:

docker volume create local_registry
docker container run -d --name registry.localhost -v local_registry:/var/lib/registry --restart always -p 5000:5000 registry:2

👆Notice, what it does is to create the registry using this image: 👆注意,它的作用是使用此图像创建注册表:

From DockerHub 🤷‍♂️ which is one of the docker registries you avoided来自 DockerHub 🤷‍♂️,这是您避免使用的 Docker 注册表之一

Here you can find more information on how to set it up: https://k3d.io/usage/guides/registries/在这里您可以找到有关如何设置的更多信息: https : //k3d.io/usage/guides/registries/

And finally, please remember that when you get your images from a private registry, you have to tell K8s the authentication information for your private registry, so it can download the image.... otherwise it will give you this error:最后,请记住,当您从私有注册中心获取图像时,您必须告诉 K8s 您私有注册中心的身份验证信息,以便它可以下载图像....否则它会给您这个错误:

...pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed ...拉取访问被拒绝,存储库不存在或可能需要授权:服务器消息:不足范围:授权失败

You can find more documentation on how to set this up here:您可以在此处找到有关如何设置的更多文档:

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

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