0

Creating a Cron Job

What does the flag '-c' do in the Kubernetes Cronjob?

kind: CronJob
metadata:
  name: hello
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
panos
  • 328
  • 1
  • 4
  • 16

2 Answers2

1

Community wiki for clearness and further searches.

@François is completely correct. /bin/sh -c comes directly from unix and simply means command you issue after shell. This is NOT a parameter for k8s cronjob :

If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.

You can also check What is /bin/sh -c?

Vit
  • 7,740
  • 15
  • 40
0

The "-c" flag does not belong to the Cronjob, it is used by unix sh executing the command:

/bin/sh -c date; echo Hello from the Kubernetes cluster

So you need to read the documentation for unix sh, not kubernetes.

KubePony
  • 144
  • 1
  • 7
  • I never said that it has to do something with Kubernetes. I just encountered it in Cronjob doc. My question was: what does it do. @Francois response was rather helpful. Thanks for your answer anyway – panos Jan 19 '22 at 13:48