Use cURL with inline YAML to create Kubernetes Job in bash script

2/4/2019

I can enter the following from a command prompt to create a Kubernetes job:

curl -ik -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -X POST -H 'Content-Type: application/yaml' --data '
apiVersion: batch/v1
kind: Job
metadata:
  name: c360srv01-job
spec:
  template:
    metadata:
      name: c360srv01
    spec:
      containers:
      - name: c360srv01
        image: joegoldberg/controlm:appimage
        env:
        - name: LOOPCTR
          value: "10"
        - name: STIME
          value: "60"
      restartPolicy: Never
' https://10.96.0.1:443/apis/batch/v1/namespaces/default/jobs

However, I have not been able to convert this to a bash script. I've tried building the command in sections as individual variables that I then concatenate, I've tried build it as one long string, I've also tried putting the YAML into a file and using --data @filename but haven't been able to make any of these work. Any and all suggestions will be greatly appreciated.

-- Joe Goldberg
bash
curl
kubernetes
yaml

0 Answers