Home > other >  Unable to Create Pod in Minikube
Unable to Create Pod in Minikube

Time:11-11

I am using minikube to create k8s cluster. I am trying to create a pod. The pod is created but there is an error while pulling my image. When I try to run kubectl describe pod posts, I get the error below, but my image present locally.

Failed to pull image "suresheerf/posts": rpc error: code = Unknown desc = Error response from daemon: pull access denied for suresheerf/posts, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

What's happening here? How to resolve it?

My K8s Pod yaml:

apiVersion: v1
kind: Pod
metadata:
  name: posts
spec:
  containers:
    - name: posts
      image: suresheerf/posts

Also, my terminal screen shot:terminal

CodePudding user response:

Looks to me as if your image is not available to minikube. Minikube runs on VMs and uses its own local Docker daemon.

Make your image available to minikube like this:

  1. Execute eval $(minikube -p minikube docker-env) to point your local shell to minikube's Docker daemon.
  2. Build your image, e.g. docker build -t suresheerf/posts .
  3. Make sure minikube does not try to pull your image from Docker Hub by modifying your Pod yaml by setting imagePullPolicy to Never:
apiVersion: v1
kind: Pod
metadata:
  name: posts
spec:
  containers:
    - name: posts
      image: suresheerf/posts
      imagePullPolicy: Never

CodePudding user response:

Some possible causes for the error are:

  • The image or tag doesn’t exist.
  • You’ve made a typo in the image name or tag.
  • The image registry requires authentication.

Check whether the image name is correct or not. Update the image name and tag correctly.

If you need to pull an image from a private image registry, you need to make sure that you provide Kubernetes with the credentials it will need to pull the image. You can do this by creating a Secret. You have to create a Secret containing the credentials you need to access. Also make sure that you’ve added the Secret in the appropriate namespace. You’ll also need to set the imagePullSecrets field on your Pod. This field tells Kubernetes which Secret it should use, when authenticating to the registry.

Example :

apiVersion: v1
kind: Pod
metadata:
  name: myapp
spec:
  containers:
    - name: posts
      image: <image name>
      imagePullPolicy: Never
  imagePullSecrets:
  - name: the-secret


If Minikube is unable to directly access your local docker repository. There are several methods to resolve this issue. Refer pulling images for information.

One of the simple workarounds is, you can add the image to the Minikube cache using minikube cache add and you need to change the imagePullPolicy inside your yaml file to Never. This way, it will default to using the local image you cached into your minikube. You can reload your cache as well after adding it in.

CodePudding user response:

You have to specify the pod name and the namespace.
In your case you dont have namepsace so it will be simply:

# get the desired pod id
kubectl get pods -A

# copy the pod id and use it
kubectl describe pod <name> 
  • Related