简体   繁体   English

获取 Kubernetes statefulset 中 pod 的 IP 地址

[英]Get IP addressses for pods in Kubernetes statefulset

I'm using the C# client API and I'm trying to:我正在使用C# 客户端 API ,我正在尝试:

  1. Get all pods associated with a given StatefulSet获取与给定 StatefulSet 关联的所有 pod
  2. Get the cluster IP address of each pod获取每个pod的集群IP地址

I am aware of Kubernetes.CoreV1.ListNamespacedPodAsync and Kubernetes.AppsV1.ListNamespacedStatefulSetAsync .我知道Kubernetes.CoreV1.ListNamespacedPodAsyncKubernetes.AppsV1.ListNamespacedStatefulSetAsync The part that I'm missing is how to我缺少的部分是如何

  1. Know whether a given pod is associated with the StatefulSet知道给定的 pod 是否与 StatefulSet 相关联
  2. Discover a pod's IP address发现 pod 的 IP 地址

A feature of Kubernetes StatefulSet is Stable Network Identity . Kubernetes StatefulSet 的一个特性是稳定的网络身份 This requires that additional headless Services are created, in addition to the StatefulSet resource.这需要创建额外的无头服务,除了StatefulSet资源。

When this is done, you would typically access these instances by their hostname instead of using IP address directly.完成此操作后,您通常会通过它们的主机名访问这些实例,而不是直接使用 IP 地址。 See Stable Network ID for documentation about this.有关这方面的文档,请参阅稳定网络 ID

Eg after headless Services are created you could access 3 instances on these hostnames例如,在创建无头服务后,您可以访问这些主机名上的 3 个实例

  • my-app-0我的应用程序 0
  • my-app-1我的应用程序 1
  • my-app-2我的应用程序 2

(when accessed from within the same namespace) (从同一命名空间中访问时)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM