Kubernetes config map symlinks (..data/) : is there a way to avoid them?

后端 未结 2 456
无人共我
无人共我 2021-02-05 09:03

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 .

2条回答
  •  失恋的感觉
    2021-02-05 09:47

    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: |
          
          
          
    

    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
    

    Be careful to not forget subPath, otherwise users.xml will be a directory !

    Back to my initial manifest :

    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)

提交回复
热议问题