I want to consult

Hello everybody. Recently I started to study kubernetes and I readed guide in docker and k8s.
I have a question: Can Kubernetes work with docker registry (optional: without some secret and authification) ? And how ?
I want to create custom Image in docker registry and deploy in kubernetes.
Right now I have a problem. And I dont understand what wrong ?
Maybe you have a some article with example ?
My steps:

docker run -d -p 5000:5000 --name registry registry:2
docker pull tomcat
docker image tag tomcat localhost:5000/tomcat
docker push localhost:5000/tomcat
5, My yaml
apiVersion: v1
kind: Pod
metadata:
name: tomcat
spec:
containers:

name: tomcat
image: localhost:5000/tomcat
imagePullSecrets:
name: regcred

kubectl create -f my-test.yaml pod/tomcat created
kubectl get pod
tomcat 0/1 ImagePullBackOff 0 83s
kubectl describe pod tomcat
Name: tomcat
Namespace: default
Priority: 0
Node: pr40/myIP
Start Time: Tue, 01 Oct 2019 22:08:32 +0600
Labels:
Annotations:
Status: Pending
IP: 172.17.3.45
IPs:
IP: 172.17.3.45
Containers:
tomcat:
Container ID:
Image: localhost:5000/tomcat
Image ID:
Port:
Host Port:
State: Waiting
Reason: ImagePullBackOff
Ready: False
Restart Count: 0
Environment:
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-r56nj (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-r56nj:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-r56nj
Optional: false
QoS Class: BestEffort
Node-Selectors:
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message

Normal Scheduled default-scheduler Successfully assigned default/tomcat to pr40
Normal Pulling 29s (x4 over 2m) kubelet, pr40 Pulling image “localhost:5000/tomcat”
Warning Failed 29s (x4 over 2m) kubelet, pr40 Failed to pull image “localhost:5000/tomcat”: rpc error: code = Unknown desc = Error response from daemon: Get http://localhost:5000/v2/: dial tcp [::1]:5000: connect: connection refused
Warning Failed 29s (x4 over 2m) kubelet, pr40 Error: ErrImagePull
Normal BackOff 17s (x6 over 2m) kubelet, pr40 Back-off pulling image “localhost:5000/tomcat”
Warning Failed 5s (x7 over 2m) kubelet, pr40 Error: ImagePullBackOff

Hi,

You didn’t indicate where you’re running the docker container with ‘registry’ in it, vs where your k8s cluster is running. Assuming docker registry is not running on the same node as the pod, the problem is that ‘localhost’ truly means “the current local host”.

In other words, if you’re running the registry on your laptop or a dev machine, “localhost” refers to that machine. When you deploy a pod, “localhost” in the pod likely refers to the node on which that pod is running.

Those two machines are not the same machine, therefore the image cannot be downloaded because there isn’t a registry running on the pod node at port 5000 (instead, that registry is back on your laptop or dev machine)

To resolve your issue you need to expose the docker registry using an ip address or preferably an IP name that the cluster node can reach. You also need to be sure that the docker registry port is open and accessible.

1 Like