I am trying to run a single docker container using kubernetes
cat /path/to/docker/docker.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --live-restore=true --iptables=false --log-opt max-size=100m --log-opt max-file=3 --bip ${FLANNEL_SUBNET} --mtu ${FLANNEL_MTU}
DOCKER_OPTS="--insecure-registry localhost:5000"
i want to create a local registry as i dont want my images to reside on the public repo.
docker run -d -p 5050:5000 --restart=always --name registry registry:2
then i just build my image
docker build -f "Dockerfile" -t localhost:5050/myImage .
docker push localhost:5050/myImage
both of these work and just to be sure, i can run the image as well
docker run -d -p 5000:5000 --name myImage --hostname myImage -v /some/path/to/mount:/some/path/to/mount localhost:5050/myImage
now i try to do
kubectl run myImage --image=localhost:5050/myImage --port=5050
but
kubectl get pods
NAME READY STATUS RESTARTS AGE
myImage-4227318852-r8z9n 0/1 ErrImagePull 0 6s
kubectl logs myImage-4227318852-r8z9n
Error from server (BadRequest): container "myImage" in pod "myImage-4227318852-r8z9n" is waiting to start: trying and failing to pull image
what am i doing wrong?
docker version
Client:
Version: 17.05.0-ce
API version: 1.29
and
kubectl version
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.6", GitCommit:"114f8911f9597be669a747ab72787e0bd74c9359", GitTreeState:"clean", BuildDate:"2017-03-28T13:36:31Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.6", GitCommit:"114f8911f9597be669a747ab72787e0bd74c9359", GitTreeState:"clean", BuildDate:"2017-03-28T13:36:31Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
The problem is that kubernetes is trying to resolve localhost
inside its own container.
To solve the problem, you need to make the registry accessible to kubernetes. This can be done in multiple ways, but one of them is to run the registry inside kubernetes, and then provide a proxy so that it can be accessed outside as well.
This process is described in more detail here: https://blog.hasura.io/sharing-a-local-registry-for-minikube-37c7240d0615
The important steps are as follows:
- Create a registry on minikube
kubectl create -f kube-registry.yaml
(kube-registry.yaml can be found here: https://gist.github.com/coco98/b750b3debc6d517308596c248daf3bb1)
- Map the host port 5000 to minikube registry pod
kubectl port-forward --namespace kube-system \ $(kubectl get po -n kube-system | grep kube-registry-v0 | \ awk '{print $1;}') 5000:5000