kind: Cannot talk to cluster inside dind container
I am trying to use it on GitLab CI which uses DIND. I am trying to setup cluster inside a Docker container. I have tried the following:
$ docker run --privileged --rm -d --name dind docker:dind
$ docker run --rm -t -i --link dind:docker -e DOCKER_HOST=tcp://docker:2375 ubuntu:artful
Inside container:
$ apt-get update
$ apt-get install --yes golang-go git curl unzip wget apt-transport-https curl ca-certificates
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
$ cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
$ curl -s https://download.docker.com/linux/ubuntu/gpg | apt-key add -
$ echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" > /etc/apt/sources.list.d/docker.list
$ apt-get update
$ apt-get install --yes kubectl docker-ce
$ export GOPATH=/usr/local/go
$ export PATH="${GOPATH}/bin:${PATH}"
$ go get sigs.k8s.io/kind
$ kind create
$ export KUBECONFIG="/root/.kube/kind-config-1"
$ kubectl cluster-info
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
The connection to the server localhost:32771 was refused - did you specify the right host or port?
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
898cd8aeedce kindest/node:v1.11.3 "/usr/local/bin/entr…" 2 minutes ago Up 2 minutes 0.0.0.0:32771->6443/tcp kind-1-control-plane
$ docker exec kind-1-control-plane ps
PID TTY TIME CMD
1 ? 00:00:00 systemd
55 ? 00:00:00 systemd-journal
71 ? 00:00:12 dockerd
88 ? 00:00:00 docker-containe
812 ? 00:00:08 kubelet
1755 ? 00:00:00 ps
$ kind delete
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 36 (30 by maintainers)
Commits related to this issue
- Merge pull request #52 from jayunit100/remove_old_kind Removing the old kind binary install since .11 is released and kube-p… — committed to yankay/kind by k8s-ci-robot 3 years ago
- Merge pull request #52 from esierra-stratio/chore/disable_iam_avoid_creation [EOS-11007] No ejecutar el paso de "IAM security" si se indica --avoid-creation — committed to stg-0/kind by lreciomelero a year ago
I managed to get it working with the following:
So instead of using host’s Docker socket, I do simply a proper dind inside my container.
FYI for future folks finding this issue we now have a contrib repo https://kind.sigs.k8s.io/docs/user/resources/#using-kind-in-ci that documents CI setups such as this.
And thanks for all this work and thank you for all the help.
OK. So I do not know about gitlab.com CI, but on our private GitLab instance I discovered that it seems I am given
docker.sock
mounted into my container from host, I guess. (I have some thoughts about such setup and security of it, but I will not complain at the moment.) So I can simply have one Docker container inside which I do everything. I do the following (in an image with Go and Docker client already installed):So I just install kind and kubectl and then test it out. Sadly, it still does not work but I think this is closer. The output of final commands is is as follows:
So you see that
docker ps
now shows my CI container alongsidekind-1-control-plane
container. I think this is better because it means I should be able to connect directly to stuff inkind-1-control-plane
container. But I am not yet able. Any suggestions here?Oh, I remember. I think I had issues with that in the past. The issue was that from outside, I can see only the dind container, and not any network behind it. So I had to publish ports in Docker containers running through dind, so that they got available on the dind container. So dind container is like host, and you do not have access directly to containers behind.
Which might be also additional problem for me because I want to run then pods on the cluster, which again might not be available from my testing container, because it would again be behind dind container/host.
So currently I run dind as a service container, and then I have my main container in which I would like to run my tests on the kubernetes cluster. I have done this setup in the past for using regular Docker images/containers and it works well.
See a bit about this here as well.
So I am using
--link
just for debugging purposes to simulate what I believe GitLab CI is doing. Otherwise I am targeting Docker executor with docker-in-docker. They have a concept ofservices
and then you connect to those services.