How to find master node from worker node in Kubernetes

大城市里の小女人 提交于 2019-12-04 17:41:26

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\""

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!