I try to deploy one docker image that I build and is not on a public or private registry.
I use the imagePullPolicy: IfNotPresent
for the Kubernetes deployment.
I use kubeadm v1.12 the error:
Normal Scheduled 35s default-scheduler Successfully assigned default/test-777dd9bc96-chgc7 to ip-10-0-1-154
Normal SandboxChanged 32s kubelet, ip-10-0-1-154 Pod sandbox changed, it will be killed and re-created.
Normal BackOff 30s (x3 over 31s) kubelet, ip-10-0-1-154 Back-off pulling image "test_kube"
Warning Failed 30s (x3 over 31s) kubelet, ip-10-0-1-154 Error: ImagePullBackOff
Normal Pulling 15s (x2 over 34s) kubelet, ip-10-0-1-154 pulling image "test"
Warning Failed 13s (x2 over 33s) kubelet, ip-10-0-1-154 Failed to pull image "test": rpc error: code = Unknown desc = Error response from daemon: pull access denied for test_kube, repository does not exist or may require 'docker login'
Warning Failed 13s (x2 over 33s) kubelet, ip-10-0-1-154 Error: ErrImagePull
My deployment file:
apiVersion: apps/v1beta1
kind: Deployment
vmetadata:
name: test-kube
spec:
template:
metadata:
labels:
app: test
spec:
containers:
- name: test
image: test
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
env:
- name: SECRET-KUBE
valueFrom:
secretKeyRef:
name: secret-test
key: username
docker images]
REPOSITORY TAG
test latest
test test
In the deployment file i tried with
image: test and with image: test:test
The same error:
Error: ErrImagePull
You should have a docker private registry on the master node of the kubernetes cluster so that if the pod is deployed on a node to pull the image from there. You can find the steps to create a Kubernetes cluster with docker private registry at: Kubernetes cluster with docker private registry
6. Creating a docker private registry on master node
# Set basic auth.
rm -f /auth/*
mkdir -p /auth
docker run --entrypoint htpasswd registry:2 -Bbn test test > /auth/htpasswd
docker rm registry -f
# Set certificates auth.
rm -f /certs/*
mkdir -p /certs
openssl genrsa 1024 > /certs/registrykey.pem
chmod 400 /certs/registrykey.pem
openssl req -new -x509 -nodes -sha1 -days 365 -key /certs/registrykey.pem -out /certs/registry.pem -subj "/C=/ST=/L=/O=/OU=/CN=registry.com" > /dev/null 2>&1
docker run -d -e REGISTRY_HTTP_ADDR=0.0.0.0:5000 -p 5000:5000 --restart=always --name registry -v `pwd`/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd -v `pwd`/certs:/certs -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.pem -e REGISTRY_HTTP_TLS_KEY=/certs/registrykey.pem registry:2
# Create secret to be used in "imagePullSecrets" section of a pod
kubectl create secret docker-registry regsecret --docker-server=192.168.147.3:5000 --docker-username=test --docker-password=test --namespace=kube-system
# Push image in private registry.
docker tag test-image:latest 192.168.147.3:5000/test-image
docker push 192.168.147.3:5000/test-image
7. YAML example for pod with image from private registry
apiVersion: v1
kind: Pod
metadata:
name: test-site
labels:
app: web
spec:
containers:
- name: test
image: 192.168.147.3:5000/test-image:latest
ports:
- containerPort: 8000
imagePullPolicy: Always
imagePullSecrets:
- name: regsecret
OR
Details of creating secret and usage:
A Kubernetes cluster uses the Secret of docker-registry type to authenticate with a container registry to pull a private image.
Create this Secret, naming it regcred:
kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
where:
<your-registry-server> is your Private Docker Registry FQDN. (https://index.docker.io/v1/ for DockerHub)
<your-name> is your Docker username.
<your-pword> is your Docker password.
<your-email> is your Docker email.
Then create a pod that uses that secret:
apiVersion: v1
kind: Pod
metadata:
name: private-reg
spec:
containers:
- name: private-reg-container
image: <your-private-image>
imagePullSecrets:
- name: regcred
For the local image use case please see this post: