Kubernetes配置映射符号链接(..data/):有什么方法可以避免它们?

编程入门 行业动态 更新时间:2024-10-23 18:30:23
本文介绍了Kubernetes配置映射符号链接(..data/):有什么方法可以避免它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我注意到,当我创建并挂载包含一些文本文件的配置映射时,容器会将这些文件视为指向../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

非常感谢 psycotica0 . "rel ="noreferrer"> K8s加拿大队的懈怠使我与子路径(在 configmap文档)

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/):有什么方法可以避免它们?

本文发布于:2023-10-18 10:49:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504014.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   符号   链接   方法   Kubernetes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!