Is it possible to schedule a pod to run for say 24 hours and then remove deployment/statefulset? or need to use jobs?

5/7/2020

We have a bunch of pods running in dev environment. The pods are auto-provisioned by an application on every business action. The problem is that across various namespaces they are accumulating and eating available resources in EKS.

Is there a way without jenkins/k8s jobs to simply put some parameter on the pod manifest to tell it to self destruct say in 24 hours?

-- Aubergine
kubernetes

2 Answers

5/20/2020

If I understood your situation properly, you would like to scale your cluster down in order to save resources.

Kubernetes is featured with the ability to autoscale your application in a cluster. Literally, it means that Kubernetes can start additional pods when the load is increasing and terminate excessive pods when the load is decreasing.

It is possible to downscale the application to zero pods, but, in this case, you will have a delay serving the first request while the pod is starting.

This functionality relies on performance metrics. From the practical side, it means that autoscaling doesn't happen instantly, because it takes some time to performance metrics reach the configured threshold.

The mentioned Kubernetes feature called HPA(horizontal pod autoscale) is described in this document.

In case you are running your cluster on GCP or GKE, you are able to go further and automatically start additional nodes for your cluster when you need more computing capacity and shut down nodes when they are not running application pods anymore.

More information about this functionality can be found following the link.

Last, but not least, you can use tool like Ansible to manage all your kubernetes assets (it can create/manage deployments via playbooks).

If you decide to give it a try, you might find this information useful:

-- Nick
Source: StackOverflow

5/7/2020

Add to your pod.spec:

activeDeadlineSeconds: 86400

After deadline your Pod will be stopped for good with the status DeadlineExceeded

-- Fritz Duchardt
Source: StackOverflow