How do I delete all these kubernetes k8s_* containers

9/24/2019

New to kubernetes. I was following a tutorial on kubernetes the other day. I forgot what I was doing. Running docker ps shows many containers of k8s*.

$ docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS               NAMES
3ce38bbf370b        f3591b2cb223           "/api-server --kubec…"   3 hours ago         Up 3 hours                              k8s_compose_compose-api-57ff65b8c7-cc6qf_docker_460bc96e-dcfe-11e9-9213-025000000001_6
222239366ae5        eb516548c180           "/coredns -conf /etc…"   3 hours ago         Up 3 hours                              k8s_coredns_coredns-fb8b8dccf-7vp79_kube-system_35ecd610-dcfe-11e9-9213-025000000001_6
0e4a5a5c23bd        eb516548c180           "/coredns -conf /etc…"   3 hours ago         Up 3 hours                              k8s_coredns_coredns-fb8b8dccf-h7tvr_kube-system_35edfd50-dcfe-11e9-9213-025000000001_6
332d3d26c082        9946f563237c           "kube-apiserver --ad…"   3 hours ago         Up 3 hours                              k8s_kube-apiserver_kube-apiserver-docker-desktop_kube-system_7c4f3d43558e9fadf2d2b323b2e78235_4
5778a63798ab        k8s.gcr.io/pause:3.1   "/pause"                 3 hours ago         Up 3 hours                              k8s_POD_kube-apiserver-docker-desktop_kube-system_7c4f3d43558e9fadf2d2b323b2e78235_3
a0a26d6a2d08        2c4adeb21b4f           "etcd --advertise-cl…"   3 hours ago         Up 3 hours                              k8s_etcd_etcd-docker-desktop_kube-system_3773efb8e009876ddfa2c10173dba95e_3
e6038e717c64        ac2ce44462bc           "kube-controller-man…"   3 hours ago         Up 3 hours                              k8s_kube-controller-manager_kube-controller-manager-docker-desktop_kube-system_9c58c6d32bd3a2d42b8b10905b8e8f54_4
10e962e90703        004666307c5b           "/usr/local/bin/kube…"   3 hours ago         Up 3 hours                              k8s_kube-proxy_kube-proxy-pq4f7_kube-system_35ac91f0-dcfe-11e9-9213-025000000001_4
21b4a7aa37d0        953364a3ae7a           "kube-scheduler --bi…"   3 hours ago         Up 3 hours                              k8s_kube-scheduler_kube-scheduler-docker-desktop_kube-system_124f5bab49bf26c80b1c1be19641c3e8_4
d9447c41bc55        k8s.gcr.io/pause:3.1   "/pause"                 3 hours ago         Up 3 hours                              k8s_POD_kube-proxy-pq4f7_kube-system_35ac91f0-dcfe-11e9-9213-025000000001_4
65248416150d        k8s.gcr.io/pause:3.1   "/pause"                 3 hours ago         Up 3 hours                              k8s_POD_kube-controller-manager-docker-desktop_kube-system_9c58c6d32bd3a2d42b8b10905b8e8f54_3
4afff5745b79        k8s.gcr.io/pause:3.1   "/pause"                 3 hours ago         Up 3 hours                              k8s_POD_kube-scheduler-docker-desktop_kube-system_124f5bab49bf26c80b1c1be19641c3e8_3
d6db038ea9b3        k8s.gcr.io/pause:3.1   "/pause"                 3 hours ago         Up 3 hours                              k8s_POD_etcd-docker-desktop_kube-system_3773efb8e009876ddfa2c10173dba95e_3
9ca30180ab45        k8s.gcr.io/pause:3.1   "/pause"                 3 hours ago         Up 3 hours                              k8s_POD_compose-api-57ff65b8c7-cc6qf_docker_460bc96e-dcfe-11e9-9213-025000000001_4
338d226f12d9        a8c3d87a58e7           "/compose-controller…"   3 hours ago         Up 3 hours                              k8s_compose_compose-6c67d745f6-9v5k5_docker_461b37ab-dcfe-11e9-9213-025000000001_3
6e23ff5c4b86        k8s.gcr.io/pause:3.1   "/pause"                 3 hours ago         Up 3 hours                              k8s_POD_coredns-fb8b8dccf-7vp79_kube-system_35ecd610-dcfe-11e9-9213-025000000001_5
258ced5c1498        k8s.gcr.io/pause:3.1   "/pause"                 3 hours ago         Up 3 hours                              k8s_POD_coredns-fb8b8dccf-h7tvr_kube-system_35edfd50-dcfe-11e9-9213-025000000001_4
0ee3d792d79e        k8s.gcr.io/pause:3.1   "/pause"                 3 hours ago         Up 3 hours                              k8s_POD_compose-6c67d745f6-9v5k5_docker_461b37ab-dcfe-11e9-9213-025000000001_4

I also ran kubectl with --namespace provided. When I only execute kubectl get pods, it says no resource found.

$ kubectl get pods --namespace kube-system
NAME                               READY   STATUS    RESTARTS   AGE
coredns-5644d7b6d9-frlhd           1/1     Running   1          9m30s
coredns-5644d7b6d9-xmdtg           1/1     Running   1          9m30s
etcd-minikube                      1/1     Running   1          8m29s
kube-addon-manager-minikube        1/1     Running   1          8m23s
kube-apiserver-minikube            1/1     Running   1          8m42s
kube-controller-manager-minikube   1/1     Running   1          8m22s
kube-proxy-48kxn                   1/1     Running   1          9m30s
kube-scheduler-minikube            1/1     Running   1          8m32s
storage-provisioner                1/1     Running   1          9m27s

I also tried stopping the containers using docker stop. It stopped but few seconds later, the containers started again.

I also ran minikube delete but it only deleted minikube. The command docker ps still showed the containers.

I'd like to start from beginning again.

-- devwannabe
containers
docker
kubectl
kubernetes

2 Answers

9/24/2019

Don't try to delete pause containers.

k8s.gcr.io/pause:3.1   "/pause"

You can bring multiple containers in a k8s pod and they share same network namespace.

The pause containers are meant to be a way to share network namespace.

That's how the k8s pod is created.

For more info, please go through this.

-- mchawre
Source: StackOverflow

9/24/2019

If you want to reset your cluster, you can first list all namespaces using kubectl get namespaces, then delete them using kubectl delete namespaces namespace_name.

However, you can't delete the namespaces default, kube-system, and kube-public as those are protected by the cluster. What you can do is remove all Pods from the default and kube-public namespace using kubectl delete --all pods --namespace=default; kubectl delete --all pods --namespace=kube-public. You shouldn't touch the kube-system namespace as it contains resources that are mandatory for the cluster to function.

-- Alassane Ndiaye
Source: StackOverflow