Flag '-c' in kubernetes cronjobs command/args

1/19/2022

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
args
command
kubernetes
kubernetes-cronjob

2 Answers

1/19/2022

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
Source: StackOverflow

2/18/2022

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
Source: StackOverflow