8

I need to know to which master node my current worker node is connected. I can see the worker nodes by typing "kubectl get nodes" command in the master node, but I need to find the master node from the worker node itself.

In simple words, How to find the master node from the worker node in the kubernetes cluster?

Rico
  • 58,485
  • 12
  • 111
  • 141
AATHITH RAJENDRAN
  • 4,689
  • 8
  • 34
  • 58

5 Answers5

9

You can usually find it on your kubelet config file: /etc/kubernetes/kubelet.conf

$ cat /etc/kubernetes/kubelet.conf
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: REDACTED
    server: https://1.1.1.1:6443 <== here
  name: default-cluster
contexts:
- context:
    cluster: default-cluster
    namespace: default
    user: default-auth
  name: default-context
current-context: default-context
kind: Config
preferences: {}
users:
- name: default-auth
  user:
    client-certificate: /var/lib/kubelet/pki/kubelet-client-current.pem
    client-key: /var/lib/kubelet/pki/kubelet-client-current.pem

If you have something like yq you can get it like this:

yq .clusters[0].cluster.server /etc/kubernetes/kubelet.conf | tr -d "\n\""
Rico
  • 58,485
  • 12
  • 111
  • 141
  • it worked, I can able to find master's IP. but I've seen a comment(somewhere) which showed something like this "node IP: IP of worker(URL like address) master node running at master node's IP" – AATHITH RAJENDRAN Oct 23 '18 at 11:48
  • The kubelet file on GCP clusters is at `/var/lib/kubelet/kubeconfig`. I found it by inspecting `/etc/default/kubelet`. – Alex Feb 02 '23 at 14:26
8

When creating a cluster in GCP and then connect to that cluster with

gcloud container clusters get-credentials kafka-and-zookeepr --zone us-central1-a --project {YOUR_PROJECT_NAME} 

you can issue

kubectl cluster-info   

This will return

Kubernetes master is running at https://xxx.xxx.xxx.xxx
GLBCDefaultBackend is running at https://xxx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/default-http-backend:http/proxy
Heapster is running at https://xxx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/heapster/proxy
KubeDNS is running at https://xxx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://xxx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

NOTE: I have docker installed on my local machine

Adelin
  • 18,144
  • 26
  • 115
  • 175
0

type

kubectl get nodes -o wide

and check the ROLES tab

-1

you may netstat -natp |grep kubelet to find the port also.

keniee van
  • 483
  • 4
  • 5
-1

execute command cat /etc/hosts it will give master node's IP

Peter
  • 405
  • 3
  • 6
  • 14