Microk8s: how to get the node external-ip, like "minikube ip"?

Using microk8s 1.18 on Ubuntu 20.04.

I’d like to get the external ip of the node. Similar to minikube ip as shown in the Istio Ingress Gateways documentation.

Question: How to get the IP address of the node so to allow remote clients outside of the cluster to access services installed within the cluster? In my example, this address would be 192.168.1.98. Maybe it is possible to grep it from microk8s.kubectl cluster-info
However all I can see is the loopback IP 127.0.0.1.

$ microk8s.kubectl cluster-info

Kubernetes master is running at https://127.0.0.1:16443
Heapster is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/heapster/proxy
CoreDNS is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Grafana is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
InfluxDB is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/monitoring-influxdb:http/proxy

EDIT: Hum maybe I am asking the wrong question? A cluster theoritically has multiple nodes so it’s kind of illogical to ask the cluster to give a node IP address. Maybe I should query the node details and read the info in the Addresses section:

$ microk8s.kubectl describe node $(microk8s.kubectl get nodes --no-headers | cut -f 1 -d " ")

// console output:
Name:               myhostname
Roles:              <none>
... etc ...
Addresses:
  InternalIP:  192.168.1.98
  Hostname:    myhostname
... etc ...

1 Like

MicroK8s will use the default interface. You should be able to locate that with ip route | grep default.
You are right that in a MIcroK8s cluster you will get one IP per node.

In case you look for a kubeconfig file to access the api server, you can use microk8s config [1]

[1] https://microk8s.io/docs/commands#microk8s-config

This command returns the IP address of the router, not the IP of the machine where microk8s is installed. Can you please clarify?

With ip route | grep default you will get the interface used by MicroK8s. You can do an ifconfig of that interface to see more info.

Oh Ok thanks. I did directly ifconfig. But found the output of kubectl describe node more informative (details in initial post).

An easy way to see the IP address of the node is to use the get nodes command with “wide” output; the INTERNAL-IP column contains the IP of the node:

microk8s kubectl get nodes -o wide

NAME          STATUS   ROLES    AGE   VERSION    INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION       CONTAINER-RUNTIME
microk8s-vm   Ready    <none>   35m   v1.18.13   172.27.13.35   <none>        Ubuntu 18.04.5 LTS   4.15.0-130-generic   containerd://1.2.5

i just happened to need to do this and came to the following and thought it might be helpful to share:

microk8s kubectl get node -o json | jq '.items[].status.addresses[] | select(.type=="InternalIP") | .address'

Looks as if at the time of writing this things perhaps have changed a bit with later microk8s versions, ifconfig -a reveals virtual nic vxlan.calico and that ip I’m guessing is the one we want to be using ? I’m not all that familiar with calico but using the command mentioned by @TristanStanic microk8s.kubectl describe node $(microk8s.kubectl get nodes --no-headers | cut -f 1 -d " ") I see the same address on an annotation labelled projectcalico.org/IPv4VXLANTunnelAddr