Shell script in Kubernetes worker pod

6/22/2021

I have a requirement to run a shell script from worker pod. For that I have created the configMap and loaded as volume. When I applied the configuration, I see a directory in the name of shell script is created is created. Can you help to understand why I see this behavior.

 volumes:
    - name: rhfeed
      configMap: 
        name: rhfeed
        defaultMode: 0777

      volumeMounts:
        - name: rhfeed
          mountPath: /local_path/rh-feed/rh-generator.sh
          subPath: rh-generator.sh
          readOnly: true

drwxrwsrwx 2 root 1000 4096 Jun 22 06:55 rh-generator.sh
-- Aravind
kubernetes
shell

2 Answers

6/22/2021

rh-generator.sh folder created because used have used subPath.

subPath creates a separate folder.

-- mGeek
Source: StackOverflow

6/22/2021

I have just performed a test with ConfigMap serving some static files for the nginx pod and my file was mounted correctly without overriding nor create deleting the content of the directory.

Here's the configMap yaml file:

apiVersion: v1
kind: ConfigMap
metadata:
  name: static-files
data:
  index.html: |
    <html><head><title>File Mounted from ConfigMap</title></head>
    <body><h1>Welcome</h1>
    <p>Hi, This confirm that your yaml with subPath is working fine</p>
    </body></html>

And here the pod yaml file:

➜  ~ cat pod-static-files.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: website
spec:
  volumes:
    - name: static-files
      configMap:
        name: static-files
  containers:
    - name: nginx
      image: nginx
      volumeMounts:
        - name: static-files
          mountPath: /usr/share/nginx/index.html
          subPath: index.html

As you can see below I has mounted the file into the directory without any issues:

➜  ~ keti website bash 
root@website:~# ls /usr/share/nginx/
html  index.html

And here is the content of the /usr/share/nginx/index.html file:

➜ root@website:~# cat /usr/share/nginx/index.html 

<html><head><title>File Mounted from ConfigMap</title></head>
<body><h1>Welcomet</h1>
<p>Hi, This confirm that your yaml with subPath is working fine</p>
</body></html>
-- acid_fuji
Source: StackOverflow