How to fix "Failed to pull image" on microk8s

10/30/2019

Im trying to follow the get started docker's tutorials, but I get stuck when you have to work with kuberetes. I'm using microk8s to create the clusters.

My Dockerfile:

FROM node:6.11.5WORKDIR /usr/src/app
COPY package.json .
RUN npm install
COPY . .

CMD [ "npm", "start" ]

My bb.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: bb-demo
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      bb: web
  template:
    metadata:
      labels:
        bb: web
    spec:
      containers:
      - name: bb-site
        image: bulletinboard:1.0
---
apiVersion: v1
kind: Service
metadata:
  name: bb-entrypoint
  namespace: default
spec:
  type: NodePort
  selector:
    bb: web
  ports:
  - port: 8080
    targetPort: 8080
    nodePort: 30001

I create the image with

docker image build -t bulletinboard:1.0 .

And I create the pod and the service with:

microk8s.kubectl apply -f bb.yaml

The pod is created, but, when I look for the state of my pods with

microk8s.kubectl get all

It says:

NAME                           READY   STATUS             RESTARTS   AGE
pod/bb-demo-7ffb568776-6njfg   0/1     ImagePullBackOff   0          11m

NAME                    TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
service/bb-entrypoint   NodePort    10.152.183.2   <none>        8080:30001/TCP   11m
service/kubernetes      ClusterIP   10.152.183.1   <none>        443/TCP          4d

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/bb-demo   0/1     1            0           11m

NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/bb-demo-7ffb568776   1         1         0       11m

Also, when I look for it at the kubernetes dashboard it says:

Failed to pull image "bulletinboard:1.0": rpc error: code = Unknown desc = failed to resolve image "docker.io/library/bulletinboard:1.0": no available registry endpoint: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

Q: Why do I get this error? Im just following the tutorial without skipping anything.

Im already logged with docker.

-- Manu Ruiz Ruiz
docker
kubernetes
microk8s

3 Answers

10/30/2019

You need to push this locally built image to the Docker Hub registry. For that, you need to create a Docker Hub account if you do not have one already.

Once you do that, you need to login to Docker Hub from your command line.

docker login

Tag your image so it goes to your Docker Hub repository.

docker tag bulletinboard:1.0 <your docker hub user>/bulletinboard:1.0

Push your image to Docker Hub

docker push <your docker hub user>/bulletinboard:1.0

Update the yaml file to reflect the new image repo on Docker Hub.

spec: containers: - name: bb-site image: <your docker hub user>/bulletinboard:1.0

re-apply the yaml file

microk8s.kubectl apply -f bb.yaml

-- user1796571
Source: StackOverflow

1/12/2020

You can host a local registry server if you do not wish to use Docker hub.

  1. Start a local registry server:
docker run -d -p 5000:5000 --restart=always --name registry registry:2
  1. Tag your image:
sudo docker tag bulletinboard:1.0 localhost:5000/bulletinboard
  1. Push it to a local registry:
sudo docker push localhost:5000/bulletinboard
  1. Change the yaml file:
spec:
      containers:
      - name: bb-site
        image: localhost:5000/bulletinboard
  1. Start deployment
kubectl apply -f bb.yaml
-- Geebee
Source: StackOverflow

11/13/2019

A suggested solution is to add imagePullPolicy: Never to your Deployment as per the answer here but this didn't work for me, so I followed this guide since I was working in local development.

-- Captain A
Source: StackOverflow