7

我需要知道我当前的工作节点连接到哪个主节点。我可以通过在主节点中键入“kubectl get nodes”命令来查看工作节点,但我需要从工作节点本身找到主节点。

简单来说,kubernetes集群中如何从worker节点中找到master节点?

4

3 回答 3

7

您通常可以在kubelet配置文件中找到它:/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

如果你有类似的东西,yq你可以像这样得到它:

yq .clusters[0].cluster.server /etc/kubernetes/kubelet.conf | tr -d "\n\""
于 2018-10-23T04:31:45.297 回答
5

在 GCP 中创建集群然后使用

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

你可以发出

kubectl cluster-info   

这将返回

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

注意:我在本地机器上安装了 docker

于 2019-07-29T20:39:42.823 回答
0

您也可以 netstat -natp |grep kubelet 来查找端口。

于 2019-03-06T08:24:11.243 回答