Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

Docker for Mac - Kubernetes - reference local image

I am using Docker for Mac with Kubernetes support and I'm struggling to create a Kubernetes Deployment that references a locally built image.

Output of docker images:

REPOSITORY  TAG     IMAGE 
test        latest  2c3bdb36a5ed

My 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

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

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

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...

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.

I would like to avoid setting up local repo, so how can I make it work with Docker's Kubernetes ?

question from:https://stackoverflow.com/questions/50739405/docker-for-mac-kubernetes-reference-local-image

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I was able to run a local image by setting the imagePullPolicy to Never.

For example:

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

(Credit to https://github.com/kubernetes/kubernetes/issues/1293#issuecomment-357326426 for this solution)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...