This is a follow-up to
Resolving Kubernetes Services from Host when using kind.
In the previous post we modified the host’s DNS configuration (
/etc/resolv.conf) and the host’s
IP routes to communicate to the kind cluster from our host.
There are scenarios where modifying the host environment isn’t ideal,
such as running integration tests on a local development laptop. Also, this method isn’t limited
Fortunately, we can run a Docker container configured to communicate with the kubernetes services running in a kind cluster with a few steps.
By the end of this post we’ll run a Docker container that can make requests to
To get caught up with where the previous post left off, run the following commands:
This will create a kubernetes cluster using kind (v0.8.1) running a hello pod and service.
First let’s spin up a Docker container by running:
This will create a container named
docker-kind-demo using the
curlimages/curl:7.71.0 image. A
few notable arguments:
--cap-add NET_ADMIN- enables modifying the IP routes within the running container (which we’ll do soon)
--dns 10.96.0.10- adds
10.96.0.10(IP Address of
kube-dnsservice in the cluster) to the container’s
--dns-search cluster.local- enables querying requests such as
--net kind- connects this container to the same Docker network as the kind cluster’s Docker container
cat, so that the container doesn’t immediately terminate.
We’ll need to instruct our Docker container to direct traffic to our kind cluster. Let’s get the IP Address of the Docker container running the kind cluster by running:
For me the output is
172.18.0.2, but yours may be different. Please note what the output is
and use that instead of
172.18.0.2 in the next command:
This will instruct our container to direct traffic destined for a kubernetes service (
to be directed through
ip route addcommand requires running as root, so we set
--user 0on this command only. We could have created the container with the root user, but then all commands by default in the container would have been ran as root.
Finally we can successfully run:
Now we have a Docker container capable of communicating with Kubernetes services in a kind cluster without messing with the host.
We’ve created a Kubernetes cluster via kind running a hello service. We then ran a Docker container configured to successfully communicate with services running in the kind cluster.
I’m a huge fan of using kind for development. Do you have any recommended tools for Kubernetes development? Feel free to reach out on Twitter.