Is it possible to tell Kubernetes to just throw away my current pod and recreate it again every 48 hours? Is there some type of a scheduler on Google Cloud Kubernetes? Or can I just configure my deployment this way? I have a Node.js application containerized with Docker running inside of a Kubernetes cluster on Google Cloud Platform. Thank you in advance!
Did you try CronJobs ?
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: your_app_name
image: your_image
args:
- your
- args
restartPolicy: OnFailure
It's official Kubernetes docs under cron jobs.
Also, here is a cron schedule expression editor that might be useful: crontab.guru.
From what I understand, there are two ways to achieve this. I'm assuming your app is running as a deployment in kubernetes, so deleting pod should create a new one.
True "Kubernetes way" to resolve this issue - is to design ReadinessProbe
/LivenessProbe
for your app's deployment/statefulset/pod. Once your Pod
fall down correct probes will handle it and your Pod
will be recreated fully automatically
P.S: you are the one who knows your app better then anyone. Try out to resolve "every 48h issues" and then make the right probes. Good luck!
Link: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/