fix(kube-proxy): honor sessionAffinity=ClientIP for ClusterIP and NodePort#42
Open
indyjonesnl wants to merge 1 commit into
Open
fix(kube-proxy): honor sessionAffinity=ClientIP for ClusterIP and NodePort#42indyjonesnl wants to merge 1 commit into
indyjonesnl wants to merge 1 commit into
Conversation
…ePort iptables-mode kube-proxy now produces sticky DNAT rules for any service with sessionAffinity=ClientIP, regardless of endpoint count, and the recent --set is collapsed into the same rule as DNAT so the match only fires for packets that actually DNAT (correct protocol/port) — matching upstream K8s pkg/proxy/iptables/proxier.go writeServiceToEndpointRules. The api-server now defaults sessionAffinityConfig.clientIP.timeoutSeconds to 10800s (3h) when sessionAffinity is ClientIP and no timeout was given, and clears the config when affinity is switched to None on update, per K8s pkg/apis/core/v1/defaults.go SetDefaults_Service. Adds unit tests covering ClusterIP affinity (multi- and single-endpoint), NodePort affinity, no-affinity service, and the xt_recent-unavailable fallback path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
`Service.spec.sessionAffinity = ClientIP` was ignored by our kube-proxy iptables rules. Traffic was always round-robin across backends, breaking conformance tests that assert client-affinity stickiness within the configured timeout window.
Fix
Translate `sessionAffinity: ClientIP` into iptables `-m recent` rules that record the client source IP on first match and re-route subsequent packets from the same source to the same backend within `sessionAffinityConfig.clientIP.timeoutSeconds` (default 10800s). Applies to both ClusterIP and NodePort services.
Verification
`cargo build --workspace --locked` clean. Depends on #32 for green CI.