-2

I am a recent Kubernetes user and would like to know if there is any way to create a cronjob that allows me to delete a specific pod from my cluster. After deleting it, I know it will be recreated and that's exactly what I want ... a refresh.

It is possible?

Thanks.

  • 2
    Yes (you will probably need to use the [Kubernetes API](https://kubernetes.io/docs/reference/#api-client-libraries) or maybe script `kubectl rollout restart`). What have you already tried, and what problems are you encountering? – David Maze Feb 02 '20 at 01:14
  • I actually use crontab, but not to restart pods, but to make some copies for AWS S3, for example. I created a shell script to manually recycle when necessary, but I was unable to run it from a cronjob. Thanks for your comment. – Acacio Demetrio Feb 02 '20 at 01:27
  • 1
    @AcacioDemetrio A Kubernetes cronjob creates a new job on a time-based schedule which in turn creates a pod. The pod runs to completion and exits and is cleared off. This could possibly address your need. I'm not too clear on why you want to recreate a pod but what I will suggest is that you read up on the different types of Kubernetes workloads and most likely you will find one to suit your needs. https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ – Shawlz Feb 02 '20 at 04:17

1 Answers1

1

You could use a Kubernetes CronJob. They work similarly to a regular cronjob, except each invocation creates a pod which is scheduled on an arbitrary node within the cluster rather than on a consistent one (unless you use the Affinity mechanics within Kubernetes).

Since a CronJob creates a pod and a pod can contain arbitrary code, I'll leave the final process of wiring this up as an exercise for the reader, but a good place to start would be the Bitnami kubectl Docker image which can take advantage of in cluster authentication using Service Accounts and RBAC.

Lastly, what you're asking to do sounds like an XY Problem. You may want to take a step back and think about whether or not a different approach or design pattern might work better here.

DWSR
  • 631
  • 6
  • 7