如何从Kubernetes的工作节点中找到主节点 [英] How to find master node from worker node in Kubernetes

查看:1876
本文介绍了如何从Kubernetes的工作节点中找到主节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

简单地说,如何从kubernetes集群中的工作节点中找到主节点?

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

推荐答案

通常可以在kubelet配置文件中找到它:/etc/kubernetes/kubelet.conf

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

如果您有类似 yq 之类的东西,则可以这样获得:

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

yq .clusters[0].cluster.server /etc/kubernetes/kubelet.conf | tr -d "\n\""

这篇关于如何从Kubernetes的工作节点中找到主节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆