Merge pull request #3363 from skeeey/master
Document for cookie expires annotation
This commit is contained in:
commit
1db9c91af4
4 changed files with 10 additions and 4 deletions
|
@ -11,6 +11,8 @@ Session stickiness is achieved through 3 annotations on the Ingress, as shown in
|
||||||
|nginx.ingress.kubernetes.io/affinity|Sets the affinity type|string (in NGINX only ``cookie`` is possible|
|
|nginx.ingress.kubernetes.io/affinity|Sets the affinity type|string (in NGINX only ``cookie`` is possible|
|
||||||
|nginx.ingress.kubernetes.io/session-cookie-name|Name of the cookie that will be used|string (default to INGRESSCOOKIE)|
|
|nginx.ingress.kubernetes.io/session-cookie-name|Name of the cookie that will be used|string (default to INGRESSCOOKIE)|
|
||||||
|nginx.ingress.kubernetes.io/session-cookie-hash|Type of hash that will be used in cookie value|sha1/md5/index|
|
|nginx.ingress.kubernetes.io/session-cookie-hash|Type of hash that will be used in cookie value|sha1/md5/index|
|
||||||
|
|nginx.ingress.kubernetes.io/session-cookie-expires|The value is a date as UNIX timestamp that the cookie will expire on, it corresponds to cookie Expires directive|number of seconds|
|
||||||
|
|nginx.ingress.kubernetes.io/session-cookie-max-age|Number of seconds until the cookie expires that will correspond to cookie `Max-Age` directive|number of seconds|
|
||||||
|
|
||||||
You can create the ingress to test this
|
You can create the ingress to test this
|
||||||
|
|
||||||
|
@ -37,6 +39,8 @@ Annotations:
|
||||||
affinity: cookie
|
affinity: cookie
|
||||||
session-cookie-hash: sha1
|
session-cookie-hash: sha1
|
||||||
session-cookie-name: INGRESSCOOKIE
|
session-cookie-name: INGRESSCOOKIE
|
||||||
|
session-cookie-expires: 172800
|
||||||
|
session-cookie-max-age: 172800
|
||||||
Events:
|
Events:
|
||||||
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
|
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
|
||||||
--------- -------- ----- ---- ------------- -------- ------ -------
|
--------- -------- ----- ---- ------------- -------- ------ -------
|
||||||
|
@ -50,13 +54,13 @@ Date: Fri, 10 Feb 2017 14:11:12 GMT
|
||||||
Content-Type: text/html
|
Content-Type: text/html
|
||||||
Content-Length: 612
|
Content-Length: 612
|
||||||
Connection: keep-alive
|
Connection: keep-alive
|
||||||
Set-Cookie: INGRESSCOOKIE=a9907b79b248140b56bb13723f72b67697baac3d; Path=/; HttpOnly
|
Set-Cookie: INGRESSCOOKIE=a9907b79b248140b56bb13723f72b67697baac3d; Expires=Sun, 12-Feb-17 14:11:12 GMT; Max-Age=172800; Path=/; HttpOnly
|
||||||
Last-Modified: Tue, 24 Jan 2017 14:02:19 GMT
|
Last-Modified: Tue, 24 Jan 2017 14:02:19 GMT
|
||||||
ETag: "58875e6b-264"
|
ETag: "58875e6b-264"
|
||||||
Accept-Ranges: bytes
|
Accept-Ranges: bytes
|
||||||
```
|
```
|
||||||
In the example above, you can see a line containing the 'Set-Cookie: INGRESSCOOKIE' setting the right defined stickiness cookie.
|
In the example above, you can see a line containing the 'Set-Cookie: INGRESSCOOKIE' setting the right defined stickiness cookie.
|
||||||
This cookie is created by NGINX containing the hash of the used upstream in that request.
|
This cookie is created by NGINX, it contains the hash of the used upstream in that request and has an expires.
|
||||||
If the user changes this cookie, NGINX creates a new one and redirect the user to another upstream.
|
If the user changes this cookie, NGINX creates a new one and redirect the user to another upstream.
|
||||||
|
|
||||||
If the backend pool grows up NGINX will keep sending the requests through the same server of the first request, even if it's overloaded.
|
If the backend pool grows up NGINX will keep sending the requests through the same server of the first request, even if it's overloaded.
|
||||||
|
|
|
@ -6,6 +6,8 @@ metadata:
|
||||||
nginx.ingress.kubernetes.io/affinity: "cookie"
|
nginx.ingress.kubernetes.io/affinity: "cookie"
|
||||||
nginx.ingress.kubernetes.io/session-cookie-name: "route"
|
nginx.ingress.kubernetes.io/session-cookie-name: "route"
|
||||||
nginx.ingress.kubernetes.io/session-cookie-hash: "sha1"
|
nginx.ingress.kubernetes.io/session-cookie-hash: "sha1"
|
||||||
|
nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
|
||||||
|
nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
|
||||||
|
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
|
|
|
@ -57,7 +57,7 @@ local function set_cookie(self, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.cookie_expires and self.cookie_expires ~= "" then
|
if self.cookie_expires and self.cookie_expires ~= "" then
|
||||||
cookie_data.expires = ngx.cookie_time(tonumber(self.cookie_expires))
|
cookie_data.expires = ngx.cookie_time(ngx.time() + tonumber(self.cookie_expires))
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.cookie_max_age and self.cookie_max_age ~= "" then
|
if self.cookie_max_age and self.cookie_max_age ~= "" then
|
||||||
|
|
|
@ -219,7 +219,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
|
||||||
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
||||||
local, _ := time.LoadLocation("GMT")
|
local, _ := time.LoadLocation("GMT")
|
||||||
duration, _ := time.ParseDuration("48h")
|
duration, _ := time.ParseDuration("48h")
|
||||||
expected := time.Date(1970, time.January, 1, 0, 0, 0, 0, local).Add(duration).Format("Mon, 02-Jan-06 15:04:05 MST")
|
expected := time.Now().In(local).Add(duration).Format("Mon, 02-Jan-06 15:04")
|
||||||
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring(fmt.Sprintf("Expires=%s", expected)))
|
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring(fmt.Sprintf("Expires=%s", expected)))
|
||||||
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Max-Age=259200"))
|
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Max-Age=259200"))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue