Kubernetes配置映射符号链接(..data/):有什么方法可以避免它们? [英] Kubernetes config map symlinks (..data/) : is there a way to avoid them?
问题描述
我注意到,当我创建并挂载包含一些文本文件的配置映射时,容器会将这些文件视为指向../data/myfile.txt
的符号链接.
I have noticed that when I create and mount a config map that contains some text files, the container will see those files as symlinks to ../data/myfile.txt
.
例如,如果我的配置映射名为tc-configs并包含2个名为stripe1.xml和stripe2.xml的xml文件,如果我将此配置映射安装到容器中的/configs,则容器中将包含:
For example, if my config map is named tc-configs and contains 2 xml files named stripe1.xml and stripe2.xml, if I mount this config map to /configs in my container, I will have, in my container :
bash-4.4# ls -al /configs/
total 12
drwxrwxrwx 3 root root 4096 Jun 4 14:47 .
drwxr-xr-x 1 root root 4096 Jun 4 14:47 ..
drwxr-xr-x 2 root root 4096 Jun 4 14:47 ..2018_06_04_14_47_03.291041453
lrwxrwxrwx 1 root root 31 Jun 4 14:47 ..data -> ..2018_06_04_14_47_03.291041453
lrwxrwxrwx 1 root root 18 Jun 4 14:47 stripe1.xml -> ..data/stripe1.xml
lrwxrwxrwx 1 root root 18 Jun 4 14:47 stripe2.xml -> ..data/stripe2.xml
我猜Kubernetes需要这些符号链接以及../data和..timestamp/文件夹,但是我知道某些应用程序如果看到意外的文件或文件夹,则可能无法启动
I guess Kubernetes requires those symlinks and ../data and ..timestamp/ folders, but I know some applications that can fail to startup if they see non expected files or folders
有没有办法告诉Kubernetes不要生成所有这些符号链接并直接挂载文件?
Is there a way to tell Kubernetes not to generate all those symlinks and directly mount the files ?
推荐答案
我认为此解决方案令人满意:在mountPath中指定确切的文件路径,将摆脱指向..data and ..2018_06_04_19_31_41.860238952
I think this solution is satisfactory : specifying exact file path in mountPath, will get rid of the symlinks to ..data and ..2018_06_04_19_31_41.860238952
因此,如果我应用这样的清单:
So if I apply such a manifest :
apiVersion: v1
kind: Pod
metadata:
name: my-lamp-site
spec:
containers:
- name: php
image: php:7.0-apache
volumeMounts:
- mountPath: /var/www/html/users.xml
name: site-data
subPath: users.xml
volumes:
- name: site-data
configMap:
name: users
---
apiVersion: v1
kind: ConfigMap
metadata:
name: users
data:
users.xml: |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<users>
</users>
显然,我在显式地使用 subpath ,并且它们不是ConfigMaps的自动更新魔术"的一部分,我将不再看到任何符号链接:
Apparently, I'm making use of subpath explicitly, and they're not part of the "auto update magic" from ConfigMaps, I won't see any more symlinks :
$ kubectl exec my-lamp-site -c php -- ls -al /var/www/html
total 12
drwxr-xr-x 1 www-data www-data 4096 Jun 4 19:18 .
drwxr-xr-x 1 root root 4096 Jun 4 17:58 ..
-rw-r--r-- 1 root root 73 Jun 4 19:18 users.xml
请注意不要忘记subPath
,否则users.xml将是目录!
Be careful to not forget subPath
, otherwise users.xml will be a directory !
回到我的初始清单:
spec:
containers:
- name: php
image: php:7.0-apache
volumeMounts:
- mountPath: /var/www/html
name: site-data
volumes:
- name: site-data
configMap:
name: users
我会看到这些符号链接回来:
I'll see those symlinks coming back :
$ kubectl exec my-lamp-site -c php -- ls -al /var/www/html
total 12
drwxrwxrwx 3 root root 4096 Jun 4 19:31 .
drwxr-xr-x 3 root root 4096 Jun 4 17:58 ..
drwxr-xr-x 2 root root 4096 Jun 4 19:31 ..2018_06_04_19_31_41.860238952
lrwxrwxrwx 1 root root 31 Jun 4 19:31 ..data -> ..2018_06_04_19_31_41.860238952
lrwxrwxrwx 1 root root 16 Jun 4 19:31 users.xml -> ..data/users.xml
非常感谢
Many thanks to psycotica0 on K8s Canada slack for putting me on the right track with subpath (they are quickly mentioned in configmap documentation)
这篇关于Kubernetes配置映射符号链接(..data/):有什么方法可以避免它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!