Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xcoulon/kubectl-terminate

kubectl-terminate, a kubectl plugin to remove finalizers and finally delete k8s resources
https://github.com/xcoulon/kubectl-terminate

cli kubectl-plugins kubernetes openshift

Last synced: 7 days ago
JSON representation

kubectl-terminate, a kubectl plugin to remove finalizers and finally delete k8s resources

Awesome Lists containing this project

README

        

= kubectl-terminate

image:https://godoc.org/github.com/xcoulon/kubectl-terminate?status.svg["GoDoc", link="https://godoc.org/github.com/xcoulon/kubectl-terminate"]
image:https://goreportcard.com/badge/github.com/xcoulon/kubectl-terminate["Go Report Card", link="https://goreportcard.com/report/github.com/xcoulon/kubectl-terminate"]
image:https://github.com/xcoulon/kubectl-terminate/workflows/CI/badge.svg["CI", link="https://github.com/xcoulon/kubectl-terminate/actions?query=workflow%3ACI"]
image:https://codecov.io/gh/xcoulon/kubectl-terminate/branch/master/graph/badge.svg["Codecov", link="https://codecov.io/gh/xcoulon/kubectl-terminate"]
image:https://img.shields.io/badge/License-Apache%202.0-blue.svg["License", link="https://opensource.org/licenses/Apache-2.0"]

WARNING:: *Use at your own risk!*

Sometimes (hopefully on your dev cluster) you may find yourself with a namespace stuck in `Terminating` phase because one of its child resource has a finalizer, but the operator (or controller) in charge of dealing with this finalizer is already gone (for example, it has been uninstalled). This is quite annoying and sadly the `--force`, `grace-period`, etc. flags won't help. The only way to get rid of the resource is to PATCH it in order to remove the finalizers, then delete it. Doing it with a good old `curl` command is possible, but let's admit it, it's a bit cumbersome 😬

Say hello to `kubectl-terminate` 👋

This command takes care of removing the finalizers and deleting the resource on your behalf, using the connection settings of your choice, i.e, using the `KUBECONFIG` env var if it exists, the `--kubeconfig` flag if specified or the default location (`$HOME` on Linux and macOS and `%USERPROFILE%` on Windows).

And since its name follows the `kubectl-*` pattern, it also works as a plugin for `kubectl` and `oc` (for OpenShift 4 users). Just make sure that the binary is in your `$PATH` and use it with `kubectl terminate pod/cheesecake` or `oc terminate pod/cheesecake` 🎉

== Installation

- run `go install github.com/xcoulon/kubectl-terminate/cmd` and add `$GOPAH/bin` to `$PATH` or move `$GOPAtH/bin/kubectl-terminate` in one of the directories of `$PATH`
- clone this repository, run `make install` and add `$GOPAH/bin` to `$PATH` or move `$GOPAtH/bin/kubectl-terminate` in one of the directories of `$PATH`

== Demo

On your own Kubernetes or OpenShift cluster, you can try it with the following commands:

[source,bash]
----
# create 2 pods called `keep-me` and `delete-me` that don't do anything
$ kubectl run --image radial/busyboxplus --restart=Never keep-me -- sleep 3600
pod/delete-me created

$ kubectl run --image radial/busyboxplus --restart=Never delete-me -- sleep 3600
pod/delete-me created

# patch the `delete-me` pod by adding a custom finalizer
$ kubectl patch pod/delete-me -p '{"metadata":{"finalizers":["demo/block-me"]}}'
pod/delete-me patched

# try to delete it with the regular `delete` command
$ kubectl delete pod/delete-me
pod "delete-me" deleted
^C

# ... but the command blocks and the pod still exists
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
delete-me 0/1 Terminating 0 51s
keep-me 1/1 Running 0 54s

# delete it with the `terminate` command
$ kubectl terminate pod/delete-me
pod "delete-me" terminated

# verify
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
keep-me 1/1 Running 0 82s
----

== Contribution

Feel free to open https://github.com/kubernetes-sigs/krew-index/issues[issues] if you find bugs or require more features. Also, PRs are welcome if you're in the mood for that 🙌

== License

This code is licensed under the https://github.com/xcoulon/kubectl-terminate/blob/master/LICENSE[Apache License, version 2.0].