Add POD mode to KubernetesEndpointGroup for fetching pod IP and port#6661
Add POD mode to KubernetesEndpointGroup for fetching pod IP and port#6661
Conversation
Motivation: Instead of relying only on the kubelet-provided `status.addresses[].InternalIP`, we may want to use an IP provided by a CNI (Container Network Interface) such as Calico. In that case, the IP should be obtained from the Node's metadata (e.g., labels or annotations) Modifications: - Added `nodeIpExtractor(Function<Node, String)` to `KubernetesEndopintGroupBuilder` as an extension point. - Make `nodeIpExtrator` and `nodeAddressFilter` mutually exclusive so they cannot be configured at the same time. Result: `KubernetesEndpointGroup` can now be configured to extract a Node IP from labels and annotations.
Motivation:
`KubernetesEndpointGroup` currently only supports `nodeIP:nodePort`
endpoints (NODE_PORT mode), which relies on kube-proxy for load
balancing. For clients running inside a Kubernetes cluster, connecting
directly to `podIP:containerPort` could enable true client-side load
balancing with features like sticky sessions, weighted routing, and
health-aware balancing.
Modifications:
- Add `KubernetesEndpointMode` enum with `NODE_PORT` (default) and
`POD` values
- Modify `KubernetesEndpointGroup` to support `POD` mode:
- Skip Node fetch/watch in POD mode (only needs pods + services RBAC)
- Extract `podIP:containerPort` from pods instead of
`nodeIP:nodePort`
- Reuse `portName` to match `ContainerPort.name` in POD mode
Result:
- Users can now use `KubernetesEndpointGroup` for intra-cluster
communication with true client-side load balancing via `POD` mode
- Closes line#6600
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe PR introduces dual-mode endpoint discovery to KubernetesEndpointGroup: NODE_PORT mode (existing, nodeIP:nodePort for external access) and POD mode (new, podIP:containerPort for intra-cluster communication). Implementation includes a new enum, mode-driven startup/update logic, pod endpoint extraction, and updated builder APIs. Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant KEG as KubernetesEndpointGroup
participant KApi as Kubernetes API
participant NodeW as Node Watcher
participant PodW as Pod Watcher
participant EC as Endpoint Calculator
rect rgba(100, 150, 200, 0.5)
Note over App,EC: NODE_PORT Mode (Existing)
App->>KEG: startup()
KEG->>KApi: fetch nodes
KEG->>KApi: fetch pods by selector
KEG->>NodeW: start watching nodes
KEG->>PodW: start watching pods
KApi-->>NodeW: node changes
NodeW->>KEG: updateNode(node)
KEG->>EC: maybeUpdateEndpoints()
EC->>KEG: nodeIP + nodePort → Endpoint
KApi-->>PodW: pod changes
PodW->>KEG: updatePod(pod)
KEG->>KEG: map pod → node
KEG->>EC: maybeUpdateEndpoints()
EC->>App: Endpoint(nodeIP:nodePort)
end
rect rgba(150, 200, 100, 0.5)
Note over App,EC: POD Mode (New)
App->>KEG: startup()
KEG->>KApi: fetch pods by selector
KEG->>PodW: start watching pods
KApi-->>PodW: pod changes
PodW->>KEG: updatePod(pod)
KEG->>KEG: extract podIP + containerPort
KEG->>EC: maybeUpdateEndpoints()
EC->>App: Endpoint(podIP:containerPort)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
jrhee17
left a comment
There was a problem hiding this comment.
Understood the changes 👍 👍
Motivation:
KubernetesEndpointGroupcurrently only supportsnodeIP:nodePortendpoints (NODE_PORT mode), which relies on kube-proxy for load
balancing. For clients running inside a Kubernetes cluster, connecting
directly to
podIP:containerPortcould enable true client-side loadbalancing with features like sticky sessions, weighted routing, and
health-aware balancing.
Modifications:
KubernetesEndpointModeenum withNODE_PORT(default) andPODvaluesKubernetesEndpointGroupto supportPODmode:podIP:containerPortfrom pods instead ofnodeIP:nodePortportNameto matchContainerPort.namein POD modeResult:
KubernetesEndpointGroupfor intra-clustercommunication with true client-side load balancing via
PODmodeKubernetesEndpointGroup#6600