Kubernetes 多状态集 pods 通信
Kubernetes multiple stateful sets pods communication
在同一个有状态集 afaik 中,您可以通过直接引用特定的 pods 来进行交互,就像这样 - pod-{0..N-1}.my_service.my_namespace.svc.cluster.local
。
(此处提供更多信息:https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id)。
但是在我的例子中,我有 2 个不同的有状态集,我希望能够从第一个有状态集 statefullset1-pod-0
与第二个有状态集的 statefullset2-pod-0
交互(以及 statefullset1-pod-1
和 statefullset2-pod-1
,依此类推)。可能吗?如果是,能否请您提供示例配置?
However in my case I have 2 different stateful sets, and I want to be able statefullset1-pod-0 from 1st stateful set to interact with statefullset2-pod-0 from 2nd stateful set(and also statefullset1-pod-1 with statefullset2-pod-1, and so on). Is it possible? If yes, can you please provide example configuration?
是的,您的应用可以访问其他 StatefulSet
,因为它可以访问集群中的任何其他服务,请使用该服务的 DNS 名称。例如。如果您在同一个命名空间中创建了服务 statefullset2-pod-0
,如果它是一个 http 服务,您可以使用 http://statefullset2-pod-0
访问它。
请记住,对于 StatefulSet,您有责任自己创建 Pod 身份服务。
StatefulSets currently require a Headless Service to be responsible for the network identity of the Pods. You are responsible for creating this Service.
在同一个有状态集 afaik 中,您可以通过直接引用特定的 pods 来进行交互,就像这样 - pod-{0..N-1}.my_service.my_namespace.svc.cluster.local
。
(此处提供更多信息:https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id)。
但是在我的例子中,我有 2 个不同的有状态集,我希望能够从第一个有状态集 statefullset1-pod-0
与第二个有状态集的 statefullset2-pod-0
交互(以及 statefullset1-pod-1
和 statefullset2-pod-1
,依此类推)。可能吗?如果是,能否请您提供示例配置?
However in my case I have 2 different stateful sets, and I want to be able statefullset1-pod-0 from 1st stateful set to interact with statefullset2-pod-0 from 2nd stateful set(and also statefullset1-pod-1 with statefullset2-pod-1, and so on). Is it possible? If yes, can you please provide example configuration?
是的,您的应用可以访问其他 StatefulSet
,因为它可以访问集群中的任何其他服务,请使用该服务的 DNS 名称。例如。如果您在同一个命名空间中创建了服务 statefullset2-pod-0
,如果它是一个 http 服务,您可以使用 http://statefullset2-pod-0
访问它。
请记住,对于 StatefulSet,您有责任自己创建 Pod 身份服务。
StatefulSets currently require a Headless Service to be responsible for the network identity of the Pods. You are responsible for creating this Service.