Using Kubernetes Python Client with a v2 Docker Registry

7/18/2018

I am using the official Python Kubernetes client to create Pods dynamically:

kube_api.create_namespaced_pod(body=pod_spec, namespace='default')

However it looks like Kubernetes tries to pull the image assuming my local registry is using v1:

Failed to pull image "localhost:5000/foo:bar": rpc error: code = Unknown desc = Error while pulling image: Get http://localhost:5000/v1/repositories/foo/images: dial tcp 127.0.0.1:5000: getsockopt: connection refused

This doesn't work, as my local registry is using v2 and apparently it is not backward compatible.

To fix this I see two solutions:

  • Changing Kubernetes' (or Docker's?) config to change the API to v2. I've been searching a lot but can't find how to do that.

  • Creating a v1 registry. But I couldn't find any docker image for it, and this sounds like a bad solution as v1 is deprecated.

-- MasterScrat
docker-registry
kubernetes
python

1 Answer

7/19/2018

The error message appears to indicate the problem is not with the API version - docker was not even able to connect to your registry (dial tcp 127.0.0.1:5000: getsockopt: connection refused).

This means that your registry is simply not reachable at the given address, most likely because it is not on the same host.

Note that if you are running k8s in anything other than minikube (where everything is on the same host), you probably have multiple hosts and a 'local' registry is not a solution at all - you would have to have a copy of that registry on every host that is part of your cluster.

If you are running minikube (or otherwise have just a single host where kubernetes runs AND that's the same host where you ran the registry), check that the registry is actually on port 5000 and that the port is exposed to the host network (if you started it with a docker command, it should have been with -p 5000:5000 option).

-- Leo K
Source: StackOverflow