我需要从worker pod运行shell脚本。为此,我创建了configMap并作为卷加载。当我应用配置时,我看到一个名为shell的目录被创建了。你能帮助我理解我为什么看到这种行为吗。
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
由于使用而创建的rh-generator.sh
文件夹已使用subPath
。
subPath
创建一个单独的文件夹。
我刚刚用为nginx
pod提供一些静态文件的ConfigMap
执行了一个测试,我的文件被正确装载,没有覆盖或创建删除目录的内容。
这是configMap
yaml文件:
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>
这里是pod
yaml文件:
➜ ~ 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
正如你在下面看到的,我已经将文件安装到目录中,没有任何问题:
➜ ~ keti website bash
root@website:~# ls /usr/share/nginx/
html index.html
这是/usr/share/nginx/index.html
文件的内容:
➜ 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>