Can not delete pods in Kubernetes
I did face same issue. Run command:
kubectl get deployment
you will get respective deployment to your pod. Copy it and then run command:
kubectl delete deployment xyz
then check. No new pods will be created.
The link provided by the op may be unavailable. See the
update
section
As you specified you created your dgraph
server using this https://raw.githubusercontent.com/dgraph-io/dgraph/master/contrib/config/kubernetes/dgraph-single.yaml, So just use this one to delete the resources you created:
$ kubectl delete -f https://raw.githubusercontent.com/dgraph-io/dgraph/master/contrib/config/kubernetes/dgraph-single.yaml
Update
Basically, this is an explanation for the reason.
Kubernetes has some workloads (those contain PodTemplate in their manifest). These are:
- Pods
- Controllers (basically Pod controllers)
- ReplicationController
- ReplicaSet
- Deployment
- StatefulSet
- DaemonSet
- Job
- CronJob
See, who controls whom:
- ReplicationController -> Pod(s)
- ReplicaSet -> Pod(s)
- Deployment -> ReplicaSet(s) -> Pod(s)
- StatefulSet -> Pod(s)
- DaemonSet -> Pod(s)
- Job -> Pod
- CronJob -> Job(s) -> Pod
a -> b
meansa
creates and controlsb
and the value of field.metadata.ownerReference
inb
's manifest is the reference ofa
. For example,apiVersion: v1 kind: Pod metadata: ... ownerReferences: - apiVersion: apps/v1 controller: true blockOwnerDeletion: true kind: ReplicaSet name: my-repset uid: d9607e19-f88f-11e6-a518-42010a800195 ...
This way, deletion of the parent object will also delete the child object via garbase collection.
So,
a
's controller ensures thata
's currentstatus
matches witha
'sspec
. Say, if one deletesb
, thenb
will be deleted. Buta
is still alive anda
's controller sees that there is a difference betweena
's currentstatus
anda
'sspec
. Soa
's controller recreates a newb
obj to match with thea
's spec.
The ops created a Deployment that created ReplicaSet that further created Pod(s). So here the soln was to delete the root obj which was the Deployment.
$ kubectl get deploy -n {namespace}
$ kubectl delete deploy {deployment name} -n {namespace}
Note Book
Another problem may arise during deletion is as follows: If there is any finalizer in the
.metadata.finalizers[]
section, then only after completing the task(s) performed by the associated controller, the deletion will be performed. If one wants to delete the object without performing the finalizer(s)' action(s), then he/she has to delete those finalizer(s) first. For example,$ kubectl patch -n {namespace} deploy {deployment name} --patch '{"metadata":{"finalizers":[]}}' $ kubectl delete -n {namespace} deploy {deployment name}