You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Helm模板中获取API Server的Endpoint URL?

如何获取Kubernetes API Server的公网Endpoint URL?

你执行kubectl cluster-info时能看到公网的API Server地址:

Kubernetes control plane is running at https://api.joseph-rancher-cluster-2.rancher.aveshalabs.io
CoreDNS is running at https://api.joseph-rancher-cluster-2.rancher.aveshalabs.io/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

你提到用kubectl describe svc kubernetes -n default和kubectl config view只能拿到私有IP,这是因为前者查看的是集群内部的Service地址,后者读取的是本地kubeconfig里配置的server地址(通常是集群内部IP)。要获取kubectl cluster-info里展示的公网Endpoint,可以用以下两种方法:

  • 用jsonpath直接提取(推荐,更严谨):

    kubectl cluster-info -o jsonpath='{.controlPlaneEndpoint}'
    
  • 通过文本过滤提取:
    如果你的Kubernetes版本不支持上述jsonpath输出,可以用文本处理工具提取:

    kubectl cluster-info | grep "Kubernetes control plane is running at" | awk '{print $NF}'
    

补充说明:这个公网Endpoint一般是集群部署时配置的外部访问地址(比如Rancher管理的集群会通过Rancher代理或者配置的负载均衡暴露公网地址),kubectl cluster-info会直接读取集群的相关配置展示这个地址,而内部Service和kubeconfig里的地址是供集群内部或本地客户端直接连接集群内部节点用的。

内容的提问来源于stack exchange,提问作者Mridul Gain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 09:25:44