I see the following containers running on Docker Desktop application:
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.
CodePudding user response:
You need to delete the corresponding workload resource (Deployment
, Statefulset
etc) which are controlling your K8s cluster. Workloads by default come with restartPolicy
as Always
, due to which your Pods are getting recreated after deletion.
To list the a workload resource, run the following command:
# kubectl get <workload-resource name> -A
# -A flag prints the resources present in all namespaces.
kubectl get deploy -A
kubectl get daemonset -A
kubectl get stateful -A
Copy the name of the resource from the printed list and delete it:
kubectl delete <resource-type> <resource-name>
kubectl delete deploy client-depl
CodePudding user response:
you can see all running containers using:
kubectl get deploy -A
for delete them :
kubectl delete deploy client-depl
CodePudding user response:
To see all the running Kubernetes container
kubectl get po -o jsonpath='{range .items[*]}{"pod: "}{.metadata.name}{"\n"}{range .spec.containers[*]}{"\tname: "}{.name}{"\n\timage: "}{.image}{"\n"}{end}'
for delete them :
kubectl delete deploy deployment-obj
CodePudding user response:
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 run docker system prune -a
Delete all pods in a namespace. Make sure you are connected to the right cluster before running this command :
kubectl delete --all pods --namespace=foo