Skip to content

Add POD mode to KubernetesEndpointGroup for fetching pod IP and port#6661

Open
ikhoon wants to merge 3 commits intoline:mainfrom
ikhoon:k8s-iptype
Open

Add POD mode to KubernetesEndpointGroup for fetching pod IP and port#6661
ikhoon wants to merge 3 commits intoline:mainfrom
ikhoon:k8s-iptype

Conversation

@ikhoon
Copy link
Contributor

@ikhoon ikhoon commented Mar 10, 2026

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:

ikhoon added 2 commits March 10, 2026 15:00
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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 65bc4926-7672-4d31-8beb-9f467f485e92

📥 Commits

Reviewing files that changed from the base of the PR and between 2df24d1 and 44a34a4.

📒 Files selected for processing (5)
  • .gitignore
  • kubernetes/src/main/java/com/linecorp/armeria/client/kubernetes/endpoints/KubernetesEndpointGroup.java
  • kubernetes/src/main/java/com/linecorp/armeria/client/kubernetes/endpoints/KubernetesEndpointGroupBuilder.java
  • kubernetes/src/main/java/com/linecorp/armeria/client/kubernetes/endpoints/KubernetesEndpointMode.java
  • kubernetes/src/test/java/com/linecorp/armeria/client/kubernetes/endpoints/KubernetesEndpointGroupMockServerTest.java

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Configuration
.gitignore
Added ignore rule for Claude-related settings file (.claude/settings.local.json).
Mode Definition
kubernetes/src/main/java/com/linecorp/armeria/client/kubernetes/endpoints/KubernetesEndpointMode.java
New public enum introducing NODE_PORT and POD discovery modes with corresponding RBAC and endpoint resolution documentation.
Core Implementation
kubernetes/src/main/java/com/linecorp/armeria/client/kubernetes/endpoints/KubernetesEndpointGroup.java
Major refactor introducing mode-driven logic: replaced nodeAddressFilter with nodeIpExtractor Function; added podToEndpoint map for POD mode; refactored startup to handle NODE_PORT (nodes/pods/watchers) vs. POD (pods-only/watchers); added pod IP extraction and container port resolution; implemented mode-aware endpoint calculation and watcher behavior.
Builder API
kubernetes/src/main/java/com/linecorp/armeria/client/kubernetes/endpoints/KubernetesEndpointGroupBuilder.java
Added public methods mode(KubernetesEndpointMode) and nodeIpExtractor(Function<Node, String>); replaced nodeAddressFilter field with nodeIpExtractor; updated documentation for mode-specific port-name semantics; wired new parameters to KubernetesEndpointGroup constructor.
Test Coverage
kubernetes/src/test/java/com/linecorp/armeria/client/kubernetes/endpoints/KubernetesEndpointGroupMockServerTest.java
Added comprehensive test cases for annotation-based node IPs, POD mode basic functionality, port-name filtering in POD mode, and pods without IP addresses; introduced helper methods for constructing test pods with specific IPs and named container ports.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Two paths now diverge in the cluster's wood,
NODE_PORT for roads far outside where it should,
POD mode hops swift through the net, racing fast,
Watchers and endpoints dance—a dual-mode forecast!
With ports named and extracted with grace so refined,
Kubernetes routes are now beautifully aligned. 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 24.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding POD mode to KubernetesEndpointGroup for fetching pod IP and port, which is the primary objective of the pull request.
Description check ✅ Passed The description is well-structured and directly related to the changeset, explaining motivation, modifications, and results of adding POD mode support.
Linked Issues check ✅ Passed The PR successfully implements all key requirements from issue #6600: introduces KubernetesEndpointMode enum with POD mode, extracts podIP:containerPort from pods, supports portName matching, and enables client-side load balancing within clusters.
Out of Scope Changes check ✅ Passed All changes are directly related to adding POD mode support. The refactoring of nodeAddressFilter to nodeIpExtractor is a necessary enabler for the feature, and the .gitignore update is a minor supporting change.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ikhoon ikhoon marked this pull request as ready for review March 11, 2026 04:50
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood the changes 👍 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a way to fetch Pod IP and port in KubernetesEndpointGroup

2 participants