Docker for Mac - Kubernetes - 参考本地镜像 [英] Docker for Mac - Kubernetes - reference local image
问题描述
我正在使用 Docker for Mac 和 Kubernetes 支持,我正在努力创建一个引用本地构建的映像的 Kubernetes 部署.
I am using Docker for Mac with Kubernetes support and I'm struggling to create a Kubernetes Deployment that references a locally built image.
docker 镜像
的输出:
REPOSITORY TAG IMAGE
test latest 2c3bdb36a5ed
我的部署.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
pods 被创建但是:
When i run kubectl apply -f deplyment.yaml
pods are created but:
helloworld-deployment-764b8b85d8-2c4kl 0/1 ImagePullBackOff 0
helloworld-deployment-764b8b85d8-rzq7l 0/1 ImagePullBackOff 0
这些 Pod 之一的
kubectl describe
给出:
kubectl describe
of one of these pods gives:
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 并且它也很有效......
What is interesting is that if i try to run some image hosted on dockerhub then everything is fine, I also tried to use skaffold and it also works like a charm...
我看到一些关于 minikube 的类似问题,其中解决方案是使用 minikube docker 守护程序来构建图像,以便可以从 Kubernetes 集群中引用它们.
I see some similar issues regarding minikube where the solution is to use the minikube docker daemon to build images so that they can be referenced from the Kubernetes cluster.
我想避免设置本地存储库,那么如何使其与 Docker 的 Kubernetes 一起使用?
I would like to avoid setting up local repo, so how can I make it work with Docker's Kubernetes ?
推荐答案
我能够通过将 imagePullPolicy
设置为 Never
来运行本地图像.
I was able to run a local image by setting the imagePullPolicy
to 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 用于此解决方案)
(Credit to https://github.com/kubernetes/kubernetes/issues/1293#issuecomment-357326426 for this solution)
这篇关于Docker for Mac - Kubernetes - 参考本地镜像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!