Getting permission denied on k8s initContainer while running sh file

1/13/2020

I have a k8s YAML file with 2 containers. initContainer and the main container. I am using a volume to mount a script file to be run in initContainer but I am getting permission denied error. Here is the snippet.

  volumes:
  - name: casacm-script
    configMap:
      name: {{ include "oxauth.name" . }}-casacm-script 

and in initContainer I mount it like

 initContainers:
  - name: {{ include "oxauth.name" .}}-init 
    image: gcr.io/cloud-builders/kubectl:latest
    command: 
      - sh
      - -c 
      - /scripts/casacm.sh   
    volumeMounts:
      - name: casacm-script
        mountPath: "/scripts/casacm.sh"
        subPath: casacm.sh
-- Shammir
bash
kubernetes

1 Answer

1/13/2020

Change your volumes to below to add permission.

volumes:
  - name: casacm-script
    configMap:
      name: {{ include "oxauth.name" . }}-casacm-script 
      defaultMode: 0777
-- Arghya Sadhu
Source: StackOverflow