1

I am trying to run an external bash script using the below yaml file.

The script is inside the /scripts/run.sh folder. I have also given the defaultMode: 0777

This is the error I get.

sh: 0: Can't open /scripts/run.sh
apiVersion: v1
data:
  script.sh: |-
    echo "Hello world!"
    kubectl get pods
kind: ConfigMap
metadata:
  name: script-configmap
---
apiVersion: batch/v1
kind: Job
metadata:
  labels:
    app: script-job
  name: script-job
spec:
  backoffLimit: 2
  template:
    spec:
      containers:
        - command:
            - sh
            - /scripts/run.sh
          image: 'bitnami/kubectl:1.12'
          name: script
          volumeMounts:
            - name: script-configmap
              mountPath: /scripts
              subPath: run.sh              
              readOnly: false
      restartPolicy: Never
      volumes:
        - name: script-configmap
          configMap:
            name: script-configmap
            defaultMode: 0777
tijko
  • 7,599
  • 11
  • 44
  • 64
jeril
  • 1,109
  • 2
  • 17
  • 35

1 Answers1

6

The file name is script.sh and not run.sh

Try

containers:
    - command:
        - sh
        - /scripts/script.sh
Yuri G.
  • 4,323
  • 1
  • 17
  • 32