I am using the following code to kill the container in a pod
from kubernetes.stream import stream
. . .
. . .
# custom function to read downwardAPI generated metadata file which return ns and pod name
namespace_name, pod_name = pod_metadata.pod_info()
# custom function to create CoreV1Api client
v1 = k8s_client.CoreV1Api()
response = v1.list_namespaced_pod(namespace=namespace_name, field_selector=f"metadata.name={pod_name}")
command = 'cmd.exe -c "kill 1"'
command = shlex.split(command)
for pods in response.items:
logger.info(f"Pod Name: {pods.metadata.name}")
for container in pods.status.container_statuses:
if container.ready:
logger.info(f"Shutting down {container.name}")
resp = stream(
v1.connect_get_namespaced_pod_exec,
name=pods.metadata.name,
namespace=namespace_name,
container=container.name,
command=command,
stderr=True,
stdin=True,
stdout=True,
tty=False,
_preload_content=False,
)
resp.close()
The code is obtained from the following link :- https://github.com/kubernetes-client/python/issues/1138 The container I have inside POD are windows one. I am not getting any exception and also I dont see container is being killed. I am loading config from kubeconfig.