gpt4 book ai didi

docker - 在 k8s 中使用没有注册表设置的本地 docker 镜像

转载 作者:行者123 更新时间:2023-12-02 11:31:14 24 4
gpt4 key购买 nike

我已经根据 official tutorial 设置了单节点 kubernetes .

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

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 驱动程序:
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在我构建图像后,一切正常。

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

最佳答案

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

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

更多相关信息,您可以找到 here .

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 中使用没有注册表设置的本地 docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60228643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com