|
17 | 17 | The script will wait for 10 events related to namespaces to occur within
|
18 | 18 | the `timeout_seconds` threshold and then move on to wait for another 10 events
|
19 | 19 | 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) |
20 | 61 | """
|
21 | 62 |
|
22 | 63 | from kubernetes import client, config, watch
|
|
0 commit comments