gpt4 book ai didi

kubernetes - Docker for Mac - Kubernetes - 引用本地镜像

转载 作者:行者123 更新时间:2023-12-03 08:22:01 25 4
gpt4 key购买 nike

我正在使用 Docker for Mac 和 Kubernetes 支持,我正在努力创建一个引用本地构建镜像的 Kubernetes 部署。
docker images 的输出:

REPOSITORY  TAG     IMAGE 
test latest 2c3bdb36a5ed

我的 deployment.yaml :
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld-deployment
spec:
selector:
matchLabels:
app: helloworld
replicas: 1
template:
metadata:
labels:
app: helloworld
spec:
containers:
- name: aaa
image: test:latest
ports:
- containerPort: 8080

当我运行时 kubectl apply -f deplyment.yaml Pod 已创建,但是:
helloworld-deployment-764b8b85d8-2c4kl   0/1       ImagePullBackOff   0          
helloworld-deployment-764b8b85d8-rzq7l 0/1 ImagePullBackOff 0

kubectl describe这些 pod 之一给出:
  Normal   Scheduled              20s               default-scheduler            Successfully assigned helloworld-deployment-79f66d97c6-7tj2x to docker-for-desktop
Normal SuccessfulMountVolume 19s kubelet, docker-for-desktop MountVolume.SetUp succeeded for volume "default-token-72f44"
Normal BackOff 16s kubelet, docker-for-desktop Back-off pulling image "test:latest"
Warning Failed 16s kubelet, docker-for-desktop Error: ImagePullBackOff
Normal Pulling 4s (x2 over 19s) kubelet, docker-for-desktop pulling image "test:latest"
Warning Failed 2s (x2 over 17s) kubelet, docker-for-desktop Failed to pull image "test:latest": rpc error: code = Unknown desc = Error response from daemon: pull access denied for test, repository does not exist or may require 'docker login'
Warning Failed 2s (x2 over 17s) kubelet, docker-for-desktop Error: ErrImagePull

有趣的是,如果我尝试运行托管在 dockerhub 上的一些图像,那么一切都很好,
我也尝试使用 skaffold它也像一个魅力......

我看到一些关于 minikube 的类似问题,其中解决方案是使用 minikube docker daemon 来构建图像,以便可以从 Kubernetes 集群中引用它们。

我想避免设置本地存储库,那么如何使其与 Docker 的 Kubernetes 一起使用?

最佳答案

我可以通过设置 imagePullPolicy 来运行本地镜像。至 Never .

例如:

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

(此解决方案归功于 https://github.com/kubernetes/kubernetes/issues/1293#issuecomment-357326426)

关于kubernetes - Docker for Mac - Kubernetes - 引用本地镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50739405/

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