Is there a way to cancel namespace termination in kubernetes?

2.7k views Asked by At

One of my namespace is in Terminating state. While there are many posts that explain how to forcefully delete such namespaces. The ultimate result is that everything in your namespace will be gone. Which is not what you might want especially if that termination was a result of mistake or bug (or may cause downtime of any kind).

Is it possible to tell kubernetes not to try to delete that namespace anymore. Where that state is kept?

Terminating state blocks me from recreating the whole stack with gitops (helm chart installation in such namespace is not possible).

I simply wish to remove the terminating state and my fluxcd controller would fix everything else.

1

There are 1 answers

0
Mikołaj Głodziak On BEST ANSWER

Is there a way to cancel namespace termination in kubernetes?

As far as I know, unfortunately not. Termination is a one-way process. Note how termination pods take place:

  1. You send a command or API call to terminate the Pod.
  2. Kubernetes updates the Pod status to reflect the time after which the Pod is to be considered "dead" (the time of the termination request plus the grace period).
  3. Kubernetes marks the Pod state as "Terminating" and stops sending traffic to the Pod.
  4. Kubernetes send a TERM signal to the Pod, indicating that the Pod should shut down.
  5. When the grace period expires, Kubernetes issues a SIGKILL to any processes still running in the Pod.
  6. Kubernetes removes the Pod from the API server on the Kubernetes Master.

So it is impossible to cancel termination process.

Is it possible to tell kubernetes not to try to delete that namespace anymore.

There is no dedicated solution, but you can try to automate this process with custom scripts. Look at this example in Python and another one in Bash.

See also this question.