39

Am using minikube to test out the deployment and was going through this link

And my manifest file for deployment is like

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: webapp
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: webapp
    spec:
      containers:
      - name: webapp
        imagePullPolicy: Never # <-- here we go!
        image: sams
        ports:
        - containerPort: 80

and after this when I tried to execute the below commands got output

user@usesr:~/Downloads$ kubectl create -f mydeployment.yaml --validate=false

deployment "webapp" created

user@user:~/Downloads$ kubectl get deployments

NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
----     --------   -------   ----------   ---------   ----              
webapp    1         1         1            0           9s

user@user:~/Downloads$ kubectl get pods

NAME                     READY     STATUS              RESTARTS   AGE
----     --------   -------   ----------   ---------   ----              
webapp-5bf5bd94d-2xgs8   0/1       ErrImageNeverPull   0          21s

I tried to pull images even from Docker-Hub by removing line imagePullPolicy: Never from the deployment.yml But getting the same error. Can anyone help me here to identify where and what's going wrong?

Updated the question as per the comment

kubectl describe pod $POD_NAME
Name:           webapp-5bf5bd94d-2xgs8
Namespace:      default
Node:           minikube/10.0.2.15
Start Time:     Fri, 31 May 2019 14:25:41 +0530
Labels:         app=webapp
            pod-template-hash=5bf5bd94d
Annotations:    <none>
Status:         Pending
IP:             172.17.0.4
Controlled By:  ReplicaSet/webapp-5bf5bd94d
Containers:
  webapp:
    Container ID:   
    Image:          sams
    Image ID:       
    Port:           80/TCP
    State:          Waiting
      Reason:       ErrImageNeverPull
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-wf82w (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-wf82w:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-wf82w
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
             node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason             Age                From               Message
  ----     ------             ----               ----               -------
  Normal   Scheduled          18m                default-scheduler  Successfully assigned default/webapp-5bf5bd94d-2xgs8 to minikube
  Warning  ErrImageNeverPull  8m (x50 over 18m)  kubelet, minikube  Container image "sams" is not present with pull policy of Never
  Warning  Failed             3m (x73 over 18m)  kubelet, minikube  Error: ErrImageNeverPull    

docker images:

REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
----------                             ---                 --------            -------             ----
<none>                                 <none>              723ce2b3d962        3 hours ago         1.91GB
bean_ben501/sams                       latest              c7c4a04713f4        4 hours ago         278MB
sams                                   latest              c7c4a04713f4        4 hours ago         278MB
sams                                   v1                  c7c4a04713f4        4 hours ago         278MB
<none>                                 <none>              b222da630bc3        4 hours ago         1.91GB
mcr.microsoft.com/dotnet/core/sdk      2.2-stretch         e4747ec2aaff        9 days ago          1.74GB
mcr.microsoft.com/dotnet/core/aspnet   2.2-stretch-slim    f6d51449c477        9 days ago          260MB

Prateek Naik
  • 2,522
  • 4
  • 18
  • 38

4 Answers4

56

When using a single VM for Kubernetes, it’s useful to reuse Minikube’s built-in Docker daemon. Reusing the built-in daemon means you don’t have to build a Docker registry on your host machine and push the image into it. Instead, you can build inside the same Docker daemon as Minikube, which speeds up local experiments.

The following command does the magic eval $(minikube docker-env) Then you have to rebuild your image again.

for imagePullPolicy: Never the images need to be on the minikube node.

This answer provide details

local-images-in minikube docker environment

Heyman
  • 449
  • 4
  • 13
Suresh Vishnoi
  • 17,341
  • 8
  • 47
  • 55
22

You need to use eval $(minikube docker-env) in your current terminal window. This will use the minikube docker-env for the current session.

The image needs to be on the minikube virtual machine. So now you need to build your image again.

But be careful ! Don't use sudo when building the image. It won't use the minikube docker-env.

After you close the terminal, everything will be as it was before.

Then, use imagePullPolicy: Never in the manifest file to use the local image registry.

Example:

apiVersion: v1
kind: Pod
metadata:
  name: demo
spec:
  containers:
  - name: demo
    image: demo
    imagePullPolicy: Never # <-- here
    ports:
    - containerPort: 3000
Tomas Lukac
  • 1,923
  • 2
  • 19
  • 37
  • same issue.I'm a windows user can you help? – Sherry Jain Jul 11 '20 at 12:28
  • 7
    Additional upvote for this: `But be careful ! Don't use sudo when building the image. It won't use the minikube docker-env.` – artona Mar 10 '21 at 14:26
  • So - if we don't want add our user to the docker group as it's a security risk, we're s.o.l.? (since we can't run docker without sudo) – Taylor Gronka Apr 10 '21 at 00:53
  • 1
    "But be careful ! Don't use sudo when building the image. It won't use the minikube docker-env." This could have saved me 5 hours. – adam sranko Oct 02 '22 at 23:32
0

Check your

kubectl version 

Be sure the client version is up to date with the daemon(Server) version. Read below quote from the official docs

You must use a kubectl version that is within one minor version difference of your cluster. For example, a v1.2 client should work with v1.1, v1.2, and v1.3 master. Using the latest version of kubectl helps avoid unforeseen issues.

Heyman
  • 449
  • 4
  • 13
0

If you are looking at this question, but are using k3s, instead of the given minikube solution, you can use this solution, or from the rancher docs. Add a --docker flag to the setup for k3s.

curl -sfL https://get.k3s.io | sh -s - --docker

kingledion
  • 2,263
  • 3
  • 25
  • 39