使用本地docker镜像而不在k8s中进行注册表设置 [英] Use local docker image without registry setup in k8s

查看:115
本文介绍了使用本地docker镜像而不在k8s中进行注册表设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经根据官方教程设置了单节点kubernetes. .

I've set up single node kubernetes according to official tutorial.

除了官方文档,我还设置了单节点集群:

In addition to official documentation I've set-up single node cluster:

kubectl taint nodes --all node-role.kubernetes.io/master-

撤离限制:

cat << EOF >> /var/lib/kubelet/config.yaml
evictionHard:
  imagefs.available: 1%
  memory.available: 100Mi
  nodefs.available: 1%
  nodefs.inodesFree: 1%
EOF

systemctl daemon-reload
systemctl restart kubelet

并为Docker设置systemd驱动程序:

And set systemd driver for Docker:

cat << EOF > /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF

systemctl daemon-reload
systemctl restart docker

我尝试了以下操作:

docker build -t localhost:5000/my-image .
kubectl run -it --rm --restart=Always --image=localhost:5000/my-image my-image

但是在pod日志中,我看到了ImagePullBackOff.如果我设置本地存储库并在构建映像后执行docker push localhost:5000/my-image,则一切正常.

But in pod logs I see ImagePullBackOff. If I setup local repository and I do docker push localhost:5000/my-image after I build image, then everything is working.

是否可以使用本地映像(在发布docker images之后已经可用)而无需设置本地存储库,推送到该存储库然后从中提取?

Is it is possible to use local images (which are already available after issuing docker images) without needing to setting up local repository, pushing to this repository and then pulling from it?

推荐答案

您只需要将container规范中Pod模板中的imagePullPolicy设置为Never.否则, kubelet 将尝试拉出图像.示例Pod定义可能如下所示:

You simply need to set the imagePullPolicy in your Pod template in the container specification to Never. Otherwise the kubelet will try to pull the image. The example Pod definition may look like this:

apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
    - name: uses-local-image
      image: local-image-name
      imagePullPolicy: Never

有关其更多信息,您可以在此处找到.

More on that you can find here.

默认情况下,kubelet将尝试从指定的列表中提取每个图像 注册表.但是,如果 容器设置为IfNotPresentNever,然后是本地图像 (分别是优先或排他地)使用.

By default, the kubelet will try to pull each image from the specified registry. However, if the imagePullPolicy property of the container is set to IfNotPresent or Never, then a local image is used (preferentially or exclusively, respectively).

如果您要依靠预拉映像代替注册表 身份验证,您必须确保群集中的所有节点都具有相同的 预拉图像.

If you want to rely on pre-pulled images as a substitute for registry authentication, you must ensure all nodes in the cluster have the same pre-pulled images.

这可以用于预加载某些图像以提高速度或作为 替代对私人注册表进行身份验证的方法.

This can be used to preload certain images for speed or as an alternative to authenticating to a private registry.

所有吊舱都将具有对任何预拉图像的读取权限.

All pods will have read access to any pre-pulled images.

这篇关于使用本地docker镜像而不在k8s中进行注册表设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆