I see there are some containers running on my docker desktop app, but when I try docker ps
on CMD I see nothing as result(empty table) and the result of kubectl get pods
is the following:
NAME READY STATUS RESTARTS AGE
client-depl-cdf975567-vzgw6 0/1 ImagePullBackOff 7 (34m ago) 12h
comments-depl-76c5bc6948-6fz4s 0/1 ImagePullBackOff 0 (44m ago) 12h
event-bus-depl-69cfbf58f7-slpjc 0/1 ImagePullBackOff 8 12h
moderation-depl-786f4ffc65-kfwh4 0/1 ImagePullBackOff 1 (40m ago) 12h
posts-depl-5f9b5c5774-wjv59 0/1 ImagePullBackOff 11 12h
query-depl-5d7d567fc7-vclfv 0/1 ImagePullBackOff 8 12h
I don’t know how to stop the running containers and delete all the images? When I try it using the GUI app they create themselves again automatically.
4
Answers
You need to delete the corresponding workload resource (
Deployment
,Statefulset
etc) which are controlling your K8s cluster. Workloads by default come withrestartPolicy
asAlways
, due to which your Pods are getting recreated after deletion.To list the a workload resource, run the following command:
Copy the name of the resource from the printed list and delete it:
you can see all running containers using:
for delete them :
To delete these you might need to delete deployment , daemonset & statefulsets. If you delete a pod it might just deleted that particular pod but replicas in the deployment will re-spin a new pod hence you should be deleting the deployment.
kubectl get deployment -A
lists all the deployment running in your cluster.kubectl get daemonset -A
lists all the daemonset running in your cluster.kubectl get statefulset -A
lists all the statefulset running in your cluster.To delete these use
kubectl delete deployment <deployment-name> -n <namespace>
Similarly replace deployment with statefulset and daemonset to delete that resource.Once this is done to delete unused images use
docker image prune -a
this will delete all unused images from your machine. If you need to remove other docker resources like unused containers, newtworks rundocker system prune -a
docker system prune document
Images could be delete from Docker desktop as well for doing this refer the below screenshot :
Delete all pods in a namespace. Make sure you are connected to the right cluster before running this command :
To see all the running Kubernetes container
for delete them :