How to fix "Failed to pull image" on microk8s
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.
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
You can host a local registry server if you do not wish to use Docker hub.
- Start a local registry server:
docker run -d -p 5000:5000 --restart=always --name registry registry:2
- Tag your image:
sudo docker tag bulletinboard:1.0 localhost:5000/bulletinboard
- Push it to a local registry:
sudo docker push localhost:5000/bulletinboard
- Change the
yaml
file:
spec:
containers:
- name: bb-site
image: localhost:5000/bulletinboard
- Start deployment
kubectl apply -f bb.yaml