-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add session affinity to custom load balancing #2341
Conversation
/assign @aledbf |
Codecov Report
@@ Coverage Diff @@
## master #2341 +/- ##
==========================================
+ Coverage 37.81% 37.97% +0.16%
==========================================
Files 72 72
Lines 5144 5158 +14
==========================================
+ Hits 1945 1959 +14
Misses 2902 2902
Partials 297 297
Continue to review full report at Codecov.
|
/approve |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aledbf, zrdaley The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@zrdaley thanks! |
What this PR does / why we need it:
This PR adds session affinity through cookies to the lua custom load balancing module when dynamic configuration is enabled.
This implementation mimics the current implementation used for sticky sessions in
kubernetes/ingress-nginx
when dynamic configuration is not enabled (k8 documentation on sticky sessions)Which issue this PR fixes:
N/A
Special notes for your reviewer:
Test coverage
Two new unit tests were added in
test/e2e/lua/dynamic_configuration.go
. These tests cover dynamically enabled session affinity when an ingress is defined in one two ways (See A and B below). Additionally, the pre-existing tests intest/e2e/annotations/affinity.go
ensure that session affinity still works when dynamic configuration is disabled.A. Default backend
Note: Session affinity will not be enabled when using method A. This is because the session affinity annotation being appended to an upstream is dependent on the location. (see code here)
B. Using Rules
Low Level Implementation Details
kubernetes/ingress-nginx
implementationsticky-{{ $upstream.name }}
upstream is defined in the nginx template (see code)sticky-{{ $upstream.name }}
and use the upstream defined in step i.New custom Lua implementation
<IP>:<Port>
string and hashed using the session-cookie-hash annotation value (default is "md5")sticky-sessions
sticky-sessions
stores the following key value pairs: **<IP>:<Port>
string of the upstream to be forwarded tosticky-sessions
***Any of custom load balancing algorithms can be to balance with session affinity. Defaulting to round robin is just to be consistent with nginx-sticky-module-ng used for session affinity when dynamic configuration is not enabled.