Kubernetes and CronJobs

Recently I was doing a recap of what was hidden in the managed version of Kubernetes. One of these examples is how Kubernetes is taking care of CronJobs, answer is pretty straightforward and is done by the component called Kubernetes controller manager. The Kubernetes controller manager is responsible for watching changes and achieving the desired state. It’s done by interacting with Kubernetes API Server, internally Kubernetes controller managers are not constantly retrieving the list of resources because it will slow down the API Server. Kubernetes controller manager uses the informer concept, so when it starts it polls all the data from API Server and stores it in the local cache, and then synchronizes the state by using events only.

Let’s get back to CronJob, it’s one of the supported controllers running inside the Kubernetes controller manager. Starting the Kubernetes controller manager you decide which controllers to enable/disable. Maybe it’s not a super valuable test by disabling the CronJob controller and proving that CronJob won’t bet triggered ;) In my test, I will use kind with kubeadm customization to disable cronjob:

$ cat kind.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: ClusterConfiguration
    controllerManager:
      extraArgs:
        controllers: "*,bootstrapsigner,tokencleaner,-cronjob"
- role: worker
$ kind create cluster --config kind.yaml
$ kubectl get cronjobs
NAME    SCHEDULE    SUSPEND   ACTIVE   LAST SCHEDULE   AGE
hello   * * * * *   False     0        <none>          2m27s

It’s not too hard to guess… cronjob is not working.

comments powered by Disqus

powered by Hugo and Noteworthy theme