I have a set of containers that need to start and stop at specific times periodically. I want to use Kubernetes to manage my containers. I have looked at the Kubernetes documents and I see that there are Cron Jobs. This kind of Job only does half of what I need it to do since my containers will need to stop at a specific time.
I was wondering if there is a way for Kubernetes to start and stop containers at periodic times? If not, is there a work around for me to achieve this functionality?
Lets say you have deployment named nginx
. When you want to stop add cron entry like this.
/usr/bin/kubectl --kubeconfig=/root/.kube/config scale --replicas=0 deployment/nginx
When you want to stop scale the replicas to 1.
/usr/bin/kubectl --kubeconfig=/root/.kube/config scale --replicas=1 deployment/nginx
you may have to check the status with kubectl get deploy nginx
Hope this helps. SR
You can setup a cron job to run kubectl scale --replicas=0 [deployment name]
and kubectl scale --replicas=1 [deployment name]
if you're using deployments or other scalable resources (replicationcontroller, statefulset, etc)
If you're using bare pods (which you shouldn't ;)), you could do the same but with kubectl delete pod
and kubectl apply