Kubernetes¶
The K8s class reads and changes Kubernetes objects such as pods, stateful sets, config maps
and ingresses. The Customizer uses it when it runs inside a Kubernetes cluster.
k8s
¶
Kubernetes Module to implement functions to read / write Kubernetes objects.
This includes Pods, Stateful Sets, Config Maps, ...
https://github.com/kubernetes-client/python https://github.com/kubernetes-client/python/blob/master/kubernetes/README.md https://github.com/kubernetes-client/python/tree/master/examples
Classes:
| Name | Description |
|---|---|
K8s |
Provides an interface to interact with the Kubernetes API. |
K8s
¶
K8s(
kubeconfig_file: str | None = None,
namespace: str = "default",
logger: Logger = default_logger,
)
Provides an interface to interact with the Kubernetes API.
This class can run both in-cluster and locally using kubeconfig. It offers methods to interact with Kubernetes namespaces, pods, and various API objects like CoreV1, AppsV1, and NetworkingV1.
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
Logger
|
Logger for the class. |
_core_v1_api |
CoreV1Api
|
API client for Kubernetes Core V1. |
_apps_v1_api |
AppsV1Api
|
API client for Kubernetes Apps V1. |
_networking_v1_api |
NetworkingV1Api
|
API client for Kubernetes Networking V1. |
_namespace |
str
|
The namespace in which operations are performed. |
Initialize the Kubernetes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kubeconfig_file
|
str | None
|
Path to a kubeconfig file. Defaults to None. |
None
|
namespace
|
str
|
The Kubernetes name space. Defaults to "default". |
'default'
|
logger
|
Logger
|
The logger object. Defaults to default_logger. |
default_logger
|
Methods:
| Name | Description |
|---|---|
get_core_v1_api |
Return Kubernetes Core V1 API object. |
get_apps_v1_api |
Return Kubernetes Apps V1 API object. |
get_networking_v1_api |
Return Kubernetes Networking V1 API object. |
get_namespace |
Return Kubernetes Namespace. |
get_pod |
Get a pod in the configured namespace (the namespace is defined in the class constructor). |
list_pods |
List all Kubernetes pods in a given namespace. |
wait_pod_condition |
Wait for the pod to reach a defined condition (e.g. "Ready"). |
exec_pod_command |
Execute a command inside a Kubernetes Pod (similar to kubectl exec on command line). |
exec_pod_command_interactive |
Execute a command inside a Kubernetes pod (similar to kubectl exec on command line). |
delete_pod |
Delete a pod in the configured namespace (the namespace is defined in the class constructor). |
get_config_map |
Get a config map in the configured namespace (the namespace is defined in the class constructor). |
list_config_maps |
List all Kubernetes Config Maps in the current namespace. |
find_config_map |
Find a Kubernetes Config Map based on its name. |
replace_config_map |
Replace a Config Map with a new specification. |
get_stateful_set |
Get a Kubernetes Stateful Set based on its name. |
get_stateful_set_scale |
Get the number of replicas for a Kubernetes Stateful Set. |
patch_stateful_set |
Patch a Stateful set with new values. |
scale_stateful_set |
Scale a stateful set to a specific number of replicas. |
get_service |
Get a Kubernetes Service with a defined name in the current namespace. |
list_services |
List all Kubernetes Service in the current namespace. |
patch_service |
Patch a Kubernetes Service with an updated spec. |
get_ingress |
Get a Kubernetes Ingress with a defined name in the current namespace. |
patch_ingress |
Patch a Kubernetes Ingress with an updated spec. |
update_ingress_backend_services |
Update a backend service and port of a Kubernetes Ingress. |
verify_pod_status |
Verify if a pod is in a 'Ready' state by checking the status of its containers. |
verify_pod_deleted |
Verify if a pod is deleted within the specified timeout. |
restart_deployment |
Restart a Kubernetes deployment using rolling restart. |
restart_stateful_set |
Enterprise-grade zero-downtime rolling restart of a stateful set. |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
get_core_v1_api
¶
Return Kubernetes Core V1 API object.
Returns:
| Name | Type | Description |
|---|---|---|
object |
CoreV1Api
|
Kubernetes API object |
get_apps_v1_api
¶
Return Kubernetes Apps V1 API object.
Returns:
| Name | Type | Description |
|---|---|---|
object |
AppsV1Api
|
Kubernetes API object |
get_networking_v1_api
¶
Return Kubernetes Networking V1 API object.
Returns:
| Name | Type | Description |
|---|---|---|
object |
NetworkingV1Api
|
Kubernetes API object |
get_namespace
¶
Return Kubernetes Namespace.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Kubernetes namespace |
get_pod
¶
Get a pod in the configured namespace (the namespace is defined in the class constructor).
See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#read_namespaced_pod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod_name
|
str
|
The name of the Kubernetes pod in the current namespace. |
required |
Returns:
| Type | Description |
|---|---|
V1Pod
|
V1Pod (object) or None if the call fails. |
V1Pod
|
|
V1Pod
|
|
V1Pod
|
|
V1Pod
|
|
V1Pod
|
|
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
list_pods
¶
List all Kubernetes pods in a given namespace.
The list can be further restricted by specifying a field or label selector.
See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#list_namespaced_pod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_selector
|
str
|
Filter result based on fields. Defaults to "". |
''
|
label_selector
|
str
|
Filter result based on labels. Defaults to "". |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
V1PodList
|
V1PodList (object) or None if the call fails |
|
V1PodList
|
Properties can be accessed with the "." notation (this is an object not a dict!): |
|
V1PodList
|
|
|
V1PodList
|
|
|
V1PodList
|
|
|
V1PodList
|
|
|
See |
V1PodList
|
https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1PodList.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
wait_pod_condition
¶
Wait for the pod to reach a defined condition (e.g. "Ready").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod_name
|
str
|
The name of the Kubernetes pod in the current namespace. |
required |
condition_name
|
str
|
The name of the condition, e.g. "Ready". |
required |
sleep_time
|
int
|
The number of seconds to wait between repetitive status checks. Defaults to 30. |
30
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
exec_pod_command
¶
exec_pod_command(
pod_name: str,
command: list,
max_retry: int = 3,
time_retry: int = 10,
container: str | None = None,
timeout: int = 60,
) -> str | None
Execute a command inside a Kubernetes Pod (similar to kubectl exec on command line).
See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#connect_get_namespaced_pod_exec
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod_name
|
str
|
The name of the Kubernetes pod in the current namespace. |
required |
command
|
list
|
A list of command and its parameters, e.g. ["/bin/bash", "-c", "pwd"] The "-c" is required to make the shell executing the command. |
required |
max_retry
|
int
|
The maximum number of attempts to execute the command. Defaults to 3. |
3
|
time_retry
|
int
|
Wait time in seconds between retries. Defaults to 10. |
10
|
container
|
str | None
|
The container name if the pod runs multiple containers inside. Defaults to None. |
None
|
timeout
|
int
|
Timeout duration that is waited for any response in seconds. Defaults to 60. |
60
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Response of the command or None if the call fails. |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
exec_pod_command_interactive
¶
exec_pod_command_interactive(
pod_name: str,
commands: list,
timeout: int = 30,
write_stderr_to_error_log: bool = True,
) -> str | None
Execute a command inside a Kubernetes pod (similar to kubectl exec on command line).
Other than exec_pod_command() method above this is an interactive execution using stdin and reading the output from stdout and stderr. This is required for longer running commands. It is currently used for restarting the spawner of Archive Center. The output of the command is pushed into the logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod_name
|
str
|
The name of the Kubernetes pod in the current namespace |
required |
commands
|
list
|
A list of command and its parameters, e.g. ["/bin/bash", "/etc/init.d/spawner restart"] Here we should NOT have a "-c" parameter! |
required |
timeout
|
int
|
Timeout duration that is waited for any response. Defaults to 30. Each time a response is found in stdout or stderr we wait another timeout duration to make sure we get the full output of the command. |
30
|
write_stderr_to_error_log
|
bool
|
Flag to control if output in stderr should be written to the debug or the error log stream. Defaults to True (write to error log). |
True
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Response of the command or None if the call fails. |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
delete_pod
¶
Delete a pod in the configured namespace (the namespace is defined in the class constructor).
See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#delete_namespaced_pod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod_name
|
str
|
The name of the Kubernetes pod in the current namespace. |
required |
Returns:
| Type | Description |
|---|---|
V1Pod | None
|
V1Pod (object) or None if the call fails. |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
get_config_map
¶
Get a config map in the configured namespace (the namespace is defined in the class constructor).
See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#read_namespaced_config_map
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_map_name
|
str
|
The name of the Kubernetes config map in the current namespace. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
V1ConfigMap |
object
|
Kubernetes Config Map object that includes these fields: - api_version: The Kubernetes API version. - metadata: A V1ObjectMeta object representing metadata about the V1ConfigMap object, such as its name, labels, and annotations. - data: A dictionary containing the non-binary data stored in the ConfigMap, where the keys represent the keys of the data items and the values represent the values of the data items. - binary_data: A dictionary containing the binary data stored in the ConfigMap, where the keys represent the keys of the binary data items and the values represent the values of the binary data items. Binary data is encoded as base64 strings in the dictionary values. |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
list_config_maps
¶
list_config_maps(
field_selector: str | None = None,
label_selector: str | None = None,
) -> V1ConfigMapList
List all Kubernetes Config Maps in the current namespace.
The list can be filtered by providing field selectors and label selectors. See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#list_namespaced_config_map
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_selector
|
str | None
|
To filter the result based on fields. Defaults to None. |
None
|
label_selector
|
str | None
|
To filter result based on labels. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
V1ConfigMapList
|
V1ConfigMapList (object) or None if the call fails |
|
V1ConfigMapList
|
Properties can be accessed with the "." notation (this is an object not a dict!): |
|
V1ConfigMapList
|
|
|
V1ConfigMapList
|
|
|
V1ConfigMapList
|
|
|
V1ConfigMapList
|
|
|
See |
V1ConfigMapList
|
https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1ConfigMapList.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
find_config_map
¶
Find a Kubernetes Config Map based on its name.
This is just a wrapper method for list_config_maps() that uses the name as a field selector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_map_name
|
str
|
The name of the Kubernetes Config Map to search for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
object |
V1ConfigMapList
|
V1ConfigMapList (object) or None if the call fails. |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
replace_config_map
¶
Replace a Config Map with a new specification.
See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#replace_namespaced_config_map
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_map_name
|
str
|
The name of the Kubernetes Config Map to replace. |
required |
config_map_data
|
dict
|
The updated specification of the Config Map. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
V1ConfigMap |
object
|
Updated Kubernetes Config Map object or None if the call fails. See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1ConfigMap.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
get_stateful_set
¶
Get a Kubernetes Stateful Set based on its name.
See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/AppsV1Api.md#read_namespaced_stateful_set
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sts_name
|
str
|
The name of the Kubernetes stateful set |
required |
Returns:
| Name | Type | Description |
|---|---|---|
V1StatefulSet |
object
|
Kubernetes Stateful Set object or None if the call fails. See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1StatefulSet.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
get_stateful_set_scale
¶
Get the number of replicas for a Kubernetes Stateful Set.
See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/AppsV1Api.md#read_namespaced_stateful_set_scale
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sts_name
|
str
|
The name of the Kubernetes Stateful Set. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
V1Scale |
object
|
Kubernetes Scale object or None if the call fails. See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1Scale.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
patch_stateful_set
¶
Patch a Stateful set with new values.
See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/AppsV1Api.md#patch_namespaced_stateful_set
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sts_name
|
str
|
The name of the Kubernetes stateful set in the current namespace. |
required |
sts_body
|
dict
|
The patch body. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
V1StatefulSet |
object
|
The patched Kubernetes Stateful Set object or None if the call fails. See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1StatefulSet.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
scale_stateful_set
¶
Scale a stateful set to a specific number of replicas.
It uses the class method patch_stateful_set() above.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sts_name
|
str
|
The name of the Kubernetes stateful set in the current namespace. |
required |
scale
|
int
|
The number of replicas (pods) the stateful set shall be scaled to. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
V1StatefulSet |
object
|
Kubernetes Stateful Set object or None if the call fails. See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1StatefulSet.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
get_service
¶
Get a Kubernetes Service with a defined name in the current namespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_name
|
str
|
The name of the Kubernetes Service in the current namespace. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
V1Service |
object
|
Kubernetes Service object or None if the call fails This is NOT a dict but an object - then you have to use the "." syntax to access to returned elements. See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1Service.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
list_services
¶
List all Kubernetes Service in the current namespace.
The list can be filtered by providing field selectors and label selectors. See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#list_namespaced_service
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_selector
|
str
|
To filter result based on fields. Defaults to "". |
''
|
label_selector
|
str
|
To filter result based on labels. Defaults to "". |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
V1ServiceList |
object
|
A list of Kubernetes Services or None if the call fails. Properties can be accessed with the "." notation (this is an object not a dict!): - api_version: The Kubernetes API version. - items: A list of V1Service objects, each representing a service. You can access the fields of a V1Service object using dot notation, for example, service.metadata.name to access the name of the service - kind: The Kubernetes object kind, which is always "ServiceList". - metadata: Additional metadata about the pod list, such as the resource version. See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1ServiceList.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
patch_service
¶
Patch a Kubernetes Service with an updated spec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_name
|
str
|
The name of the Kubernetes Service in the current namespace. |
required |
service_body
|
dict
|
The new / updated Service body spec. (will be merged with existing values) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
V1Service |
object
|
The patched Kubernetes Service or None if the call fails. This is NOT a dict but an object - you have to use the "." syntax to access to returned elements See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1Service.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
get_ingress
¶
Get a Kubernetes Ingress with a defined name in the current namespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ingress_name
|
str
|
The name of the Kubernetes Ingress in the current namespace. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
V1Ingress |
object
|
Kubernetes Ingress or None if the call fails This is NOT a dict but an object - then you have to use the "." syntax to access to returned elements. See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1Ingress.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
patch_ingress
¶
Patch a Kubernetes Ingress with an updated spec.
See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/NetworkingV1Api.md#patch_namespaced_ingress
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ingress_name
|
str
|
The name of the Kubernetes Ingress in the current namespace. |
required |
ingress_body
|
dict
|
The new / updated ingress body spec. (will be merged with existing values) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
V1Ingress |
object
|
The patched Kubernetes Ingress object or None if the call fails This is NOT a dict but an object - you have to use the "." syntax to access to returned elements See: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1Ingress.md |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
update_ingress_backend_services
¶
update_ingress_backend_services(
ingress_name: str,
hostname: str,
service_name: str,
service_port: int,
path: str = "/",
) -> V1Ingress
Update a backend service and port of a Kubernetes Ingress.
This method updates the backend service and port for a specific hostname and path in a Kubernetes Ingress. It supports multiple paths configured for a host.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ingress_name
|
str
|
The name of the Kubernetes Ingress in the current namespace. |
required |
hostname
|
str
|
The hostname that should get an updated backend service / port. |
required |
service_name
|
str
|
The new backend service name. |
required |
service_port
|
int
|
The new backend service port. |
required |
path
|
str
|
The path to match for the backend service update. Defaults to "/". |
'/'
|
Returns:
| Name | Type | Description |
|---|---|---|
V1Ingress |
object
|
The updated Kubernetes Ingress object or None if the call fails. |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 | |
verify_pod_status
¶
verify_pod_status(
pod_name: str,
timeout: int = 1800,
total_containers: int = 1,
ready_containers: int = 1,
retry_interval: int = 30,
) -> bool
Verify if a pod is in a 'Ready' state by checking the status of its containers.
This function waits for a Kubernetes pod to reach the 'Ready' state, where a specified number
of containers are ready. It checks the pod status at regular intervals and reports the status
using logs. If the pod does not reach the 'Ready' state within the specified timeout,
it returns False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod_name
|
str
|
The name of the pod to check the status for. |
required |
timeout
|
int
|
The maximum time (in seconds) to wait for the pod to become ready. Defaults to 1800. |
1800
|
total_containers
|
int
|
The total number of containers expected to be running in the pod. Defaults to 1. |
1
|
ready_containers
|
int
|
The minimum number of containers that need to be in a ready state. Defaults to 1. |
1
|
retry_interval
|
int
|
Time interval (in seconds) between each retry to check pod readiness. Defaults to 30. |
30
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Returns |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | |
verify_pod_deleted
¶
Verify if a pod is deleted within the specified timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod_name
|
str
|
The name of the pod to check. |
required |
timeout
|
int
|
Maximum time to wait for the pod to be deleted (in seconds). Defaults to 300. |
300
|
retry_interval
|
int
|
Time interval between retries (in seconds). Defaults to 30. |
30
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the pod is deleted, False otherwise. |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
restart_deployment
¶
restart_deployment(
deployment_name: str,
force: bool = False,
wait: bool = False,
wait_timeout: int = 1800,
) -> bool
Restart a Kubernetes deployment using rolling restart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment_name
|
str
|
Name of the Kubernetes deployment. |
required |
force
|
bool
|
If True, all pod instances will be forcefully deleted. Defaults to False. |
False
|
wait
|
bool
|
If True, wait for the deployment to be ready again. Defaults to False. |
False
|
wait_timeout
|
int
|
Maximum time to wait for the deployment to be ready again (in seconds). Defaults to 1800. |
1800
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful, False otherwise. |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 | |
restart_stateful_set
¶
restart_stateful_set(
sts_name: str,
wait: bool = True,
wait_timeout: int = 1800,
endpoint_service_name: str | None = None,
) -> bool
Enterprise-grade zero-downtime rolling restart of a stateful set.
Guarantees: - Zero-downtime traffic handling (via readiness probes) - Kubernetes-native rollout - Deterministic state transitions - Traffic draining via Service endpoints - Readiness-gated pod rotation - Failure detection - Rollout completion validation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sts_name
|
str
|
Name of the stateful set. |
required |
wait
|
bool
|
Whether to wait for rollout completion. Defaults to True. |
True
|
wait_timeout
|
int
|
Max seconds to wait. Defaults to 1800. |
1800
|
endpoint_service_name
|
str | None
|
Service name for endpoint gating. Defaults to None (no endpoint gating). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful, False otherwise |
Source code in packages/pyxecm/src/pyxecm_customizer/k8s.py
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 | |