dockerkuberneteskind

Exposing a kubernetes pod via service in kind kubernetes cluster


I'm following the tutorial here (https://kubernetes.io/docs/tutorials/hello-minikube/) to test a local development setup for kubernetes. However, I am using kind, instead of minikube.

At the moment, I am stuck on step 3:

minikube service hello-node

which is supposed to expose a LoadBalancer service.

However, kind doesn't seem to have such a command, and I am wondering how I would expose the service from the tutorial.

My set up is a WSL2 distro with docker, kind, and kubectl. My current port bridges are:

$ docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                       NAMES
b62c43ac3b2e        kindest/node:v1.17.0   "/usr/local/bin/entr…"   49 minutes ago      Up 49 minutes       127.0.0.1:32769->6443/tcp   kind-control-plane
$ kubectl cluster-info
Kubernetes master is running at https://127.0.0.1:32769
KubeDNS is running at https://127.0.0.1:32769/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

and

$ kubectl get services
NAME         TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
hello-node   LoadBalancer   10.96.65.157   <pending>     8080:31578/TCP   46m
kubernetes   ClusterIP      10.96.0.1      <none>        443/TCP          51m

Solution

  • LoadBalancer type service internally creates NodePort. So you can access it via http://NODEIP:31578 where 31578 is the NodePort as you can see in output of kubectl get service. To get NODEIP you can use kubectl get nodes -o wide

    If you look at the output of minikube service hello-node it's has got the same NODEIP and NODEPORT. Unfortunately there is no equivalent command in kind and so you need to use the method described above.

    EXTERNAL-IP will be pending because there is no cloud(AWS, GCP, Azure) like implementation in local kind cluster. If you really want to make LoadBalancer type service work you can use metallb as loadbalancer implementation. In this way you will have EXTERNAL-IP assigned instead of pending and you can use that IP to access the pod.

    Here is a guide on how to make metallb with kind work.