6

To test that the high-availability mode does what it should, I need to kill the instances during testing, and I need to kill them in such way that they can't report they are disconnecting or similar.

For practical reasons I need to do the testing on smaller environment that does not have a separate node for each pod, so I can't test by turning off the machines, but need to kill the processes instead. I can kill them with docker kill, but that requires logging into the node and finding the docker id of the container. Is there some way to achieve similar effect via exec kill, but sending SIGKILL to process ID 1 is not allowed.

I also see delete being used, but I have some case where there is a difference: when deleting, the container is recreated with clean state, but merely restarting it does not and the deployment I am testing actually looks at the state during start-up and has problem starting up, so I need to test the case where it is not deleted.

Can I forcibly terminate pods without giving them any chance for cleaning up via the kubernetes API/kubectl?

Jan Hudec
  • 265
  • 3
  • 11

1 Answers1

6

You can try to use command

kubectl delete pods <pod> --grace-period=0 --force

The key --grace-period=<seconds> is time, which Kubernetes waits for graceful shutdown of a Pod. If it is 0, SIGKILL will be sent immediately to any process in the Pod. The key --force must be specified for such kind of operation in versions of Kubernetes 1.5 and higher.

For more information, you can check the official documentation.

Artem Golenyaev
  • 253
  • 1
  • 7
  • 1
    Note that the question explicitly states `delete` is *not* appropriate for the purpose. There is a functionally significant difference between the pod being deleted and the process in the container dying. – Jan Hudec Nov 05 '18 at 12:17
  • Yep, but seems there is no other opportunity – Artem Golenyaev Nov 05 '18 at 12:27
  • If there seems to be no other opportunity, then the solution is to implement it, not using something that does not do the right thing. – Jan Hudec Nov 05 '18 at 12:30