Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you auto destroy a kubernetes pod deployment?

Tags:

I can delete a deployment with the kubectl cli, but is there a way to make my deployment auto-destroy itself once it has finished? For my situation, we are kicking off a long-running process in a Docker container on AWS EKS. When I check the status, it is 'running', and then sometime later the status is 'completed'. So is there any way to get the kubernetes pod to auto destroy once it as finished?

kubectl run some_deployment_name --image=path_to_image
kubectl get pods
  //the above command returns...
some_deployment_name1212-75bfdbb99b-vt622 0/1  Running 2  23s
  //and then some time later...
some_deployment_name1212-75bfdbb99b-vt622 0/1  Completed 2  15m

Once it is complete, I would like for it to be destroyed, without me having to call another command.

like image 361
MattC Avatar asked Oct 05 '18 15:10

MattC


People also ask

How do I destroy Kubernetes deployment?

Destroy Pod The action of deleting the pod is simple. To delete the pod you have created, just run kubectl delete pod nginx . Be sure to confirm the name of the pod you want to delete before pressing Enter. If you have completed the task of deleting the pod successfully, pod nginx deleted will appear in the terminal.

How do you destroy a Kubernetes pod?

Enter the “kubectl delete pod nginx” command in the terminal to delete the pod. Before you execute this command, make sure to confirm the pod's name that you want to destroy. Once you press enter after “kubectl delete pod nginx”, you will see the following output.

Can a pod delete itself?

Pods run on nodes in your cluster. Once created, a Pod remains on its node until its process is complete, the Pod is deleted, the Pod is evicted from the node due to lack of resources, or the node fails. If a node fails, Pods on the node are automatically scheduled for deletion.

Can we delete deployment Kubernetes?

5 Deleting a Service or Deployment. Objects can be deleted easily within Kubernetes so that your environment can be cleaned. Use the kubectl delete command to remove an object.


1 Answers

So the question is about running Jobs and not deployments as in the Kubernetes Deployments abstraction that creates a ReplicaSet but more like Kubernetes Jobs

A Job is created with kubectl run when you specify the --restart=OnFailure option. These jobs are not cleaned up by the cluster unless you delete them manually with kubectl delete <pod-name>. More info here.

If you are using Kubernetes 1.12 or later a new Job spec was introduced: ttlSecondsAfterFinished. You can also use that to clean up your jobs. Another more time-consuming option would be to write your own Kubernetes controller that cleans up regular Jobs.

A CronJob is created if you specify both the --restart=OnFailure and `--schedule="" option. These pods get deleted automatically because they run on a regular schedule.

More info on kubectl run here.

like image 145
Rico Avatar answered Sep 23 '22 19:09

Rico