Good day!
I am facing a strange problem. I have a standard deployment that uses a public image. But when I create it, I get the error ImagePullBackOff
$ kubectl get pods
result
api-gateway-deployment-74968fbf5c-cvqwj 0/1 ImagePullBackOff 0 6h23m
api-gateway-gateway-deployment-74968fbf5c-hpdxb 0/1 ImagePullBackOff 0 6h23m
api-gateway-gateway-deployment-74968fbf5c-rctv6 0/1 ImagePullBackOff 0 6h23m
my deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-gateway-deployment
labels:
app: api-gateway-deployment
spec:
replicas: 3
selector:
matchLabels:
app: api-gateway-deployment
template:
metadata:
labels:
app: api-gateway-deployment
spec:
containers:
- name: api-gateway-node
image: creatorsprodhouse/api-gateway:latest
imagePullPolicy: Always
ports:
- containerPort: 80
I am using the docker driver, is there anything I can do wrong?
minikube start --driver=docker
I think your internet connection is slow. The timeout to pull an image is 120 seconds, so kubectl could not pull the image in under 120 seconds.
First, pull the image via Docker
docker image pull creatorsprodhouse/api-gateway:latest
Then load the downloaded image to minikube
minikube image load creatorsprodhouse/api-gateway:latest
And then everything will work because now kubectl will use the image that is stored locally.
Related
I have pushed some docker images to my private repo on dockerhub, which I am now trying to use to create deployments in a Minikube Kubernetes cluster.
I have done the following:
docker login -u [username] -p [password]
docker tag [mslearn-microservices-pizzabackend] [username]/[mslearn-microservices-pizzabackend]
docker tag [mslearn-microservices-pizzafrontend] [username]/[mslearn-microservices-pizzafrontend]
I can see both the images in my private dockerhub repo. To be able to use them in a deployment, I have done the following:
kubectl create secret docker-registry dockerhub-credentials --docker-server="docker.io" --docker-username="[username]" --docker-password="[password]" --docker-email="[email]"
After that, I try to create a deployment for the first image using the following manifest:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mslearn-microservices-pizzabackend
spec:
replicas: 1
selector:
matchLabels:
app: mslearn-microservices-pizzabackend
template:
metadata:
labels:
app: mslearn-microservices-pizzabackend
spec:
imagePullSecrets:
- name: dockerhub-credentials
containers:
- name: mslearn-microservices-pizzabackend
image: [username]/mslearn-microservices-pizzabackend:latest
ports:
- containerPort: 80
env:
- name: ASPNETCORE_URLS
value: http://*:80
---
apiVersion: v1
kind: Service
metadata:
name: mslearn-microservices-pizzabackend
spec:
type: ClusterIP
ports:
- port: 80
selector:
app: mslearn-microservices-pizzabackend
But when I check the events of the pod that gets created by the deployment, I can see the following:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 18s default-scheduler Successfully assigned default/mslearn-microservices-pizzabackend-79dcd6677d-cgh7z to minikube
Normal BackOff 15s kubelet Back-off pulling image "[username]/mslearn-microservices-pizzabackend:latest"
Warning Failed 15s kubelet Error: ImagePullBackOff
Normal Pulling 3s (x2 over 18s) kubelet Pulling image "[username]/mslearn-microservices-pizzabackend:latest"
Warning Failed 1s (x2 over 16s) kubelet Failed to pull image "[username]/mslearn-microservices-pizzabackend:latest": rpc error: code = Unknown desc = Error response from daemon: pull access denied for [username]/mslearn-microservices-pizzabackend, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
Warning Failed 1s (x2 over 16s) kubelet Error: ErrImagePull
I have tried searching for solutions on the web and I can see that other people have had similiar issues, but none of their solutions have worked for me.
Any suggestions?
I've a K8s cluster on Linode and another VM for operating.
I've installed Docker & K8s on operating VM to build images and do deployment on cluster.
Note: I haven't installed minikube on this VM.
I'm able to build my image but not able to pull that from local registry to k8s pod.
Below are the things I've already done & tried to solve the problem.
Create and push docker image to local registry.
Run docker container from the image, but not getting pulled in K8s.
Created "regcred" secret and used it in deployment yaml.
create image and push with VM's IP(10.128.234.123:5000/app-frontend) and use the same in deployment image reference.
Change image pull policy to IfNotPresent
I get the following error in pod description:
Warning ErrImageNeverPull 11s (x4 over 13s) kubelet Container image "localhost:5000/app-frontend" is not present with pull policy of Never
Warning Failed 11s (x4 over 13s) kubelet Error: ErrImageNeverPull
Below is my deployment yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-frontend
labels:
app: app-frontend
spec:
replicas: 1
selector:
matchLabels:
app: app-frontend
template:
metadata:
labels:
app: app-frontend
spec:
containers:
- name: app-frontend
image: localhost:5000/docker-image
imagePullPolicy: Never
ports:
- containerPort: 80
imagePullSecrets:
- name: regcred
Any help or guidance will be grateful.
In the Docs I see this
While with imagePullPolicy set to Never, never pull the image.
Try this instead
imagePullPolicy: IfNotPresent
Also
image: localhost:5000/docker-image
But in point 4. you specify an IP
I've build docker image locally:
docker build -t backend -f backend.docker
Now I want to create deployment with it:
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-deployment
spec:
selector:
matchLabels:
tier: backend
replicas: 2
template:
metadata:
labels:
tier: backend
spec:
containers:
- name: backend
image: backend
imagePullPolicy: IfNotPresent # This should be by default so
ports:
- containerPort: 80
kubectl apply -f file_provided_above.yaml works, but then I have following pods statuses:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
backend-deployment-66cff7d4c6-gwbzf 0/1 ImagePullBackOff 0 18s
Before that it was ErrImagePull. So, my question is, how to tell it to use local docker images? Somewhere on the internet I read that I need to build images using microk8s.docker but it seems to be removed.
Found docs on how to use private registry: https://microk8s.io/docs/working
First it needs to be enabled:
microk8s.enable registry
Then images pushed to registry:
docker tag backend localhost:32000/backend
docker push localhost:32000/backend
And then in above config image: backend needs to be replaced with image: localhost:32000/backend
I have this basic Dockerfile:
FROM nginx
RUN apt-get -y update && apt install -y curl
In the master node of my Kubernetes cluster I build that image:
docker build -t cnginx:v1 .
docker images shows that the image has been correctly generated:
REPOSITORY TAG IMAGE ID CREATED SIZE
cgninx v1 d3b1b19d069e 39 minutes ago 141MB
I use this deployment referencing this custom image:
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: cnginx
image: cnginx:v1
imagePullPolicy: Never
ports:
- containerPort: 80
nodeSelector:
nodetype: webserver
However the image is not found:
NAME READY STATUS RESTARTS AGE
nginx-deployment-7dd98bd746-lw6tp 0/1 ErrImageNeverPull 0 4s
nginx-deployment-7dd98bd746-szr9n 0/1 ErrImageNeverPull 0 4s
Describe pod info:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 1m default-scheduler Successfully assigned nginx-deployment-7dd98bd746-szr9n to kubenode2
Normal SuccessfulMountVolume 1m kubelet, kubenode2 MountVolume.SetUp succeeded for volume "default-token-bpbpl"
Warning ErrImageNeverPull 9s (x9 over 1m) kubelet, kubenode2 Container image "cnginx:v1" is not present with pull policy of Never
Warning Failed 9s (x9 over 1m) kubelet, kubenode2 Error: ErrImageNeverPull
I have also tried using the default imagePullPolicy, and some other things such as tagging the image with latest...
So, how can I make Kubernetes use a locally generated docker image?
Your PODs are scheduled on your worker nodes. Since you set imagePullPolicy to Never you need to make your image available to both nodes. In other words, you need to build it on both nodes as you did on the master.
As a sidenote, it would be probably easier in the long term if you setup a custom docker registry and push your images there.
I have a two node cluster in AWS:
[centos#node2 sample_code]$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
node1 Ready master 3h v1.9.4+coreos.0
node2 Ready master,node 3h v1.9.4+coreos.0
and i have a simple deployment:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginxpinalabel
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.13
imagePullPolicy: Never
so when i tried to deploy this, i have 3 pods and which ever pods are in node1 are fine but on node2 it shows error:
NAME READY STATUS RESTARTS AGE
nginx-deployment-6c5ff867c5-dtjwr 0/1 ErrImageNeverPull 0 21m
nginx-deployment-6c5ff867c5-jvnvn 0/1 ErrImageNeverPull 0 21m
nginx-deployment-6c5ff867c5-kpzgf 1/1 Running 0 21m
but still i have nginx:1.13 in my registery of node2:
sudo docker images | grep nginx
10.3.5.206:5000/nginx 1.13 3f8a4339aadd 12 weeks ago 108.5 MB
Change the image name from 10.3.5.206:5000/nginx to nginx.