Skip to content

Commit 2b40cdf

Browse files
add documentation for the server & client side timeout
1 parent 44b2325 commit 2b40cdf

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Diff for: examples/pod_namespace_watch.py

+41
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,47 @@
1717
The script will wait for 10 events related to namespaces to occur within
1818
the `timeout_seconds` threshold and then move on to wait for another 10 events
1919
related to pods to occur within the `timeout_seconds` threshold.
20+
21+
---
22+
23+
[INFO] Timeout settings
24+
25+
There are two inputs available in the client, that could be used to set connection timeouts:
26+
1. timeout_seconds
27+
2. _request_timeout
28+
29+
a) Sever-side timeout ("kwargs['timeout_seconds'] = n")
30+
31+
- The value of the argument `timeout_seconds`, n (which is time duration in seconds) is consumed at the server side, and is included in the request URL to the server. For eg. ~
32+
"https://localhost:6443/api/v1/namespaces/default/pods?labelSelector=app%3Ddemo&timeoutSeconds=100&watch=True."
33+
34+
- If the `timeout_seconds` value is set, for ex: "kwargs['timeout_seconds'] = 3600", then the server timeout will be equal to 1 hour, as determined by the following expression ~
35+
"timeout = time.Duration(3600) * time.seconds" -> "timeout = 1 hour"
36+
37+
Refer: https://github.com/kubernetes/apiserver/blob/92392ef22153d75b3645b0ae339f89c12767fb52/pkg/endpoints/handlers/get.go#L255
38+
39+
- If the `timeout_seconds` value is not set, then the connection timeout will be a randomized value (in seconds) between 0 and `minRequestTimeout`, to spread out load. It is determined by the following expression ~
40+
"timeout = time.Duration(float64(minRequestTimeout) * (rand.Float64() + 1.0))",
41+
42+
Where `minRequestTimeout` indicates the minimum number of seconds a handler must keep a request open before timing it out. The default value of `minRequestTimeout` is 1800 seconds.
43+
44+
Refer: https://github.com/kubernetes/apiserver/blob/92392ef22153d75b3645b0ae339f89c12767fb52/pkg/endpoints/handlers/get.go#L258
45+
https://github.com/kubernetes/kubernetes/blob/release-1.1/docs/admin/kube-apiserver.md
46+
47+
- In case of a network outage, the timeout value will have no effect & the client will hang indefinitely without raising any exception. It is recommended to set this timeout value to a higher number such as 3600 seconds (1 hour).
48+
49+
b) Client-side timeout ("kwargs['_request_timeout'] = n")
50+
51+
- The value of the argument `_request_timeout`, n (which is time duration in seconds) is set to the socket used for the connection.
52+
53+
- The argument `_request_timeout` can accept 2 types of input values, i.e. either in integer (int) type, or a tuple with a length of 2. In case of the tuple input type, the first value will be ignored.
54+
55+
- In case of network outage, leading to dropping all packets with no RST/FIN, the timeout value (in seconds) determined by the `request_timeout` argument, would be the time duration for how long the client will wait before realizing & dropping the connection.
56+
57+
- When the timeout happens, an exception will be raised, for ex ~
58+
"urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='localhost', port=6443): Read timed out."
59+
60+
- It is recommended to set this timeout value to a low number (for ex ~ maybe 60 seconds)
2061
"""
2162

2263
from kubernetes import client, config, watch

0 commit comments

Comments
 (0)