Build a pipe from container to cluster

There are valid needs to talk to the Kubernetes cluster from segregated docker containers. It’s possible to do so:

Build the pipe from the container to the host machine

There are several ways to connect the host machine. the container is running together with the host, behaving like on the same subnet. you can access it through the public IP.

otherwise, more elegantly, you can leverage on host.docker.internal to talk to the host

Proxy the resources for the Kubernetes cluster

you can start a Kubernetes proxy to talk to the cluster.

kubectl proxy --port=8080 --disable-filter &

Access to the resources

then to talk to the resources in the cluster from the container, you can do

host.docker.internal:8080/api/v1/namespaces/default/services/pod:{port}/proxy/

This is related to, https://lwpro2.dev/2020/04/03/expose-existing-deployment-with-minikube/, as there is an issue with Kubernetes apiserver proxy, https://github.com/kubernetes/kubernetes/issues/89360, which would strip out the parameter for websocket.

The work around is to use minikube tunnel with LoadBalancer, as in above post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s