Which instance I'm in, a master then which master?

8/27/2018

I can log into a work terminal via a public IP, and list all the nodes by

kubectl get nodes # only gives me internal IPs

and also be able to check the basic info by

kubectl cluster-info

and the basic IP info for the current instance by:

ifconfig # but this gives me public IP not internal

The problem is I have no idea how to determine which node I am currently in: a master? which master (there are several masters) or just a slave? then which slave?

Thanks for the help ;)

-- Hearen
kubernetes

1 Answer

8/27/2018

Some of these commands might show different output based on your Kubernetes cluster, I am showing examples from GKE here.

You can use -owide option to get some additional information:

$kubectl get nodes -owide
NAME                           STATUS    ROLES     AGE       VERSION        EXTERNAL-IP      OS-IMAGE            KERNEL-VERSION   CONTAINER-RUNTIME
gke-test-pool2-772ceaec-0tzf   Ready     <none>    23h       v1.9.7-gke.5   35.200.255.186   Container-Optimized OS from Google   4.4.111+         docker://17.3.2
gke-test-pool2-772ceaec-1722   Ready     <none>    20h       v1.9.7-gke.5   35.200.152.18    Container-Optimized OS from Google   4.4.111+         docker://17.3.2

From the above output you can use:

  • External IP - the IP address of node (Might differ based on your setup)
  • Roles - in this case are empty indicating slave nodes as master nodes don't get listed in GKE.

Also, you can use labels to get some more information:

$ kubectl get --show-labels nodes
NAME                           STATUS    ROLES     AGE       VERSION        LABELS
gke-test-pool2-772ceaec-0tzf   Ready     <none>    23h       v1.9.7-gke.5   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/instance-type=n1-standard-1,beta.kubernetes.io/os=linux,cloud.google.com/gke-nodepool=pool2,cloud.google.com/gke-preemptible=true,failure-domain.beta.kubernetes.io/region=asia-south1,failure-domain.beta.kubernetes.io/zone=asia-south1-b,kubernetes.io/hostname=gke-test-pool2-772ceaec-0tzf
gke-test-pool2-772ceaec-1722   Ready     <none>    20h       v1.9.7-gke.5   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/instance-type=n1-standard-1,beta.kubernetes.io/os=linux,cloud.google.com/gke-nodepool=pool2,cloud.google.com/gke-preemptible=true,failure-domain.beta.kubernetes.io/region=asia-south1,failure-domain.beta.kubernetes.io/zone=asia-south1-b,kubernetes.io/hostname=gke-test-pool2-772ceaec-1722

From this output, you can:

  • The node pool in labels tells me that it is part of pool2 worker/slave pool
  • Hostname in labels might be helpful based on your setup.

You can match above information with ifconfig to figure out the IP of your node. Lastly - it is not necessary that the terminal you are logged in is one of the nodes in the cluster.

Lastly, it could very well be a node which is outside cluster with Kubeconfig and kubectl configured.

-- Vishal Biyani
Source: StackOverflow