Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigMaps and Secrets mounted with subPath do not update when changed #50345

Closed
thesandlord opened this issue Aug 8, 2017 · 35 comments
Closed
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. sig/storage Categorizes an issue or PR as relevant to SIG Storage.

Comments

@thesandlord
Copy link
Contributor

/kind bug

What happened:

I wanted to mount a ConfigMap and a Secret directly as a file and didn't want to mount it as a full directory, so I used subPath to do so:

        volumeMounts:
          - name: my-config
            mountPath: /usr/src/app/config/config.json
            subPath: config.json
          - name: my-secret
            mountPath: /usr/src/app/secret/secret.json
            subPath: secret.json
      volumes:
      - name: my-config
        configMap:
          name: my-config
      - name: my-secret
        secret:
          secretName: my-secret

When the pod is created, it mounts the ConfigMap and Secret correctly. However, if I change them, the updates are not projected into the currently running pods. New pods get the updated file. According to the documentation, changes to a ConfigMap should be automatically propagated to running containers that mount them.

However, if I don't use subPath and instead mount the ConfigMap and Secret as a directory:

        volumeMounts:
          - name: my-config
            mountPath: /usr/src/app/config
          - name: my-secret
            mountPath: /usr/src/app/secret
      volumes:
      - name: my-config
        configMap:
          name: my-config
      - name: my-secret
        secret:
          secretName: my-secret

Then the files are updated inside the container when the underlying ConfigMap and Secret are updated and everything works as expected.

Anything else we need to know?:

In both cases, the files are being updated on the host VM. @kelseyhightower and I tried to debug this, and the only conclusion we could come up with is that subPath is using a different method to mount the files (I think it is using symlinks), and these either aren't or can't be updated for whatever reason.

Action:
The behavior that files mounted with subPath don't get updated needs to be documented, or it needs to be fixed so that subPath mounts are updated when the underlying ConfigMap or Secret changes.

Environment: GKE

  • Kubernetes version (use kubectl version): 1.6.7
  • Cloud provider or hardware configuration**: GKE n1-standard-1
  • OS (e.g. from /etc/os-release): Container-Optimized OS 59 9460.64.0
  • Kernel (e.g. uname -a): 4.4.52+
@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Aug 8, 2017
@k8s-github-robot k8s-github-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Aug 8, 2017
@thesandlord
Copy link
Contributor Author

/sig storage
/sig docs

@k8s-ci-robot k8s-ci-robot added sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/docs Categorizes an issue or PR as relevant to SIG Docs. labels Aug 8, 2017
@k8s-github-robot k8s-github-robot removed the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Aug 8, 2017
@wongma7
Copy link
Contributor

wongma7 commented Aug 9, 2017

Yes, symlinks are involved. Atomic writer relies on symlinks to update configmaps, secrets and such: https://github.com/kubernetes/kubernetes/blob/master/pkg/volume/util/atomic_writer.go. On the host, the pod volume directory looks something like this:

$ pwd
/var/lib/kubelet/pods/uuid/volumes/kubernetes.io~secret/my-secret*
$ tree -a
.
├── ..8988_09_08_14_21_15.788262705
│   └── secret.json
├── ..data -> ..8988_09_08_14_21_15.788262705
└── secret.json -> ..data/secret.json

When you subPath the secret file, that secret.json file is bind mounted into the container. But secret.json is actually a symlink to another secret.json in a timestamped folder (..8988_09_08_14_21_15.788262705). When the secret gets updated, the symlinks get changed around but the file bind mounted into the container remains the same.

Not sure what the solution is. Hope this helps somebody else think of one though :)

e: Disregarding the symlinking complexity of the atomic writer algorithm for the moment...the tool we have to atomically update the file is a rename, in that case is a solution even possible? The bind mount file will always refer to the same inode yes?

@supereagle
Copy link
Contributor

@thesandlord Maybe your use case is Add ConfigMap data to a specific path in the Volume.

I follow the documentation, and it works as expected.
My configmap:

apiVersion: v1
data:
  config.json: |
    {
      "special.level": "good",
      "special.type": "charm"
    }
kind: ConfigMap
metadata:
  creationTimestamp: 2017-08-10T01:21:28Z
  name: my-config
  namespace: test
  resourceVersion: "2368592"
  selfLink: /api/v1/namespaces/test/configmaps/my-config
  uid: 3bde7d2d-7d6a-11e7-9d4a-fa163ed438e9

My pod.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
  namespace: test
spec:
  containers:
    - name: test-container
      image: nginx:latest
      volumeMounts:
      - name: config-volume
        mountPath: /usr/src/app/config
  volumes:
    - name: config-volume
      configMap:
        name: my-config
        items:
        - key: config.json
          path: config.json
  restartPolicy: Never

@kfox1111
Copy link

@supereagle that is not the same thing. sometimes you want to merge in a few config files into a magic config dir, like, /etc/condor/config.d, but leave the rest of the dir open for other things to drop things in. subPath is the right way to do that I think. but should be able to get updates still.

@barleyer
Copy link

barleyer commented Nov 1, 2017

@SCheng1

@bnelz
Copy link

bnelz commented Nov 13, 2017

Bump

@QiuMike
Copy link

QiuMike commented Dec 20, 2017

Any update for this issue?
When I create a volume using hostPath with a file, it also has this problem.
That is: modified the host file, Pod's doesn't changed.

apiVersion: v1
kind: ReplicationController
metadata:
   name: cloud52
   namespace: kube-system
spec:
  replicas: 1
  selector:
     name: cloud52
  template:
    metadata:
     labels:
       name: cloud52
    spec:
      volumes:
      - name: hosts-volume
        hostPath:
          path: /root/k8s/hosts
      hostname: cloud52
      subdomain: cloud52
      containers:
      - image: DockerRegistry:5000/centos
        command:
          - sleep
          - "3600"
        name: cloud52
        volumeMounts:
        - name: hosts-volume
          mountPath: /etc/hosts
---
apiVersion: v1
kind: Service
metadata:
  name: cloud52
  namespace: kube-system
spec:
  selector:
    name: cloud52
  ports:
  - name: foo # Actually, no port is needed.
    port: 23
    targetPort: 23

@liggitt liggitt added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Jan 4, 2018
@liggitt liggitt added this to the v1.10 milestone Jan 4, 2018
@liggitt liggitt removed the sig/docs Categorizes an issue or PR as relevant to SIG Docs. label Jan 4, 2018
@liggitt
Copy link
Member

liggitt commented Jan 4, 2018

cc @kubernetes/sig-storage-bugs

maeb added a commit to nlnwa/veidemann-dashboard that referenced this issue Feb 5, 2018
maeb added a commit to nlnwa/veidemann-dashboard that referenced this issue Feb 6, 2018
@jberkus
Copy link

jberkus commented Feb 21, 2018

@maeb do you see this getting done in the next 5 days for 1.10?

@jberkus
Copy link

jberkus commented Feb 23, 2018

This issue and its related PRs will be removed from 1.10 at Code Freeze on Monday, unless they are all updated with status/approved-for-milestone and with a progress update. If that's fine, do nothing; if you are still targeting 1.10, please let us know what's going on and update the labels. Thanks!

@jberkus
Copy link

jberkus commented Feb 26, 2018

As a reminder, this issue is about to be kicked out of 1.10 tracking in 6 hours, because it doesn't have the required labels. If this is actually an 1.10 issue, please update it! @maeb @thesandlord

@msau42
Copy link
Member

msau42 commented Feb 26, 2018

I think we just need to document this as a known limitation.

Because subpaths are bind mounted by docker, if it was a symlink, then it gets resolved to the actual path during the bindmount.

@msau42
Copy link
Member

msau42 commented Feb 26, 2018

/assign

amisevsk added a commit to amisevsk/devworkspace-operator that referenced this issue Mar 3, 2021
Changes to configmaps are not propagated when the configmap is mounted
via subPath. We can work around this but it would require changes to the
async storage server image.

See issue kubernetes/kubernetes#50345 for more
details.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this issue Mar 4, 2021
Changes to configmaps are not propagated when the configmap is mounted
via subPath. We can work around this but it would require changes to the
async storage server image.

See issue kubernetes/kubernetes#50345 for more
details.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this issue Mar 8, 2021
Changes to configmaps are not propagated when the configmap is mounted
via subPath. We can work around this but it would require changes to the
async storage server image.

See issue kubernetes/kubernetes#50345 for more
details.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this issue Mar 13, 2021
Changes to configmaps are not propagated when the configmap is mounted
via subPath. We can work around this but it would require changes to the
async storage server image.

See issue kubernetes/kubernetes#50345 for more
details.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this issue Mar 16, 2021
Changes to configmaps are not propagated when the configmap is mounted
via subPath. We can work around this but it would require changes to the
async storage server image.

See issue kubernetes/kubernetes#50345 for more
details.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this issue Mar 16, 2021
Changes to configmaps are not propagated when the configmap is mounted
via subPath. We can work around this but it would require changes to the
async storage server image.

See issue kubernetes/kubernetes#50345 for more
details.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this issue Mar 16, 2021
Changes to configmaps are not propagated when the configmap is mounted
via subPath. We can work around this but it would require changes to the
async storage server image.

See issue kubernetes/kubernetes#50345 for more
details.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this issue Mar 16, 2021
Changes to configmaps are not propagated when the configmap is mounted
via subPath. We can work around this but it would require changes to the
async storage server image.

See issue kubernetes/kubernetes#50345 for more
details.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to devfile/devworkspace-operator that referenced this issue Mar 19, 2021
Changes to configmaps are not propagated when the configmap is mounted
via subPath. We can work around this but it would require changes to the
async storage server image.

See issue kubernetes/kubernetes#50345 for more
details.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
vdeenadh pushed a commit to vdeenadh/ramen that referenced this issue Aug 3, 2021
- Don't use subpath field when mounting to the RamenConfig configuration
  map, which is known to not refresh within the pod.
  kubernetes/kubernetes#50345 (comment)

  Code contributed by Shyam Ranganathan

Signed-off-by: Veera Deenadhayalan <vdeenadh@redhat.com>
vdeenadh pushed a commit to vdeenadh/ramen that referenced this issue Aug 3, 2021
- Don't use subpath field when mounting to the RamenConfig configuration
  map, which is known to not refresh within the pod.
  kubernetes/kubernetes#50345 (comment)

Thanks to Shyam Ranganathan for contributing this change.

Signed-off-by: Veera Deenadhayalan <vdeenadh@redhat.com>
vdeenadh pushed a commit to vdeenadh/ramen that referenced this issue Aug 3, 2021
- Don't use subpath field when mounting to the RamenConfig configuration
  map, which is known to not refresh within the pod.
  kubernetes/kubernetes#50345 (comment)

Thanks to Shyam Ranganathan for contributing this change.

Signed-off-by: Veera Deenadhayalan <vdeenadh@redhat.com>
vdeenadh pushed a commit to vdeenadh/ramen that referenced this issue Aug 3, 2021
- Don't use subpath field when mounting to the RamenConfig configuration
  map, which is known to not refresh within the pod.
  kubernetes/kubernetes#50345 (comment)

Thanks to Shyam Ranganathan for contributing this change.

Signed-off-by: Veera Deenadhayalan <vdeenadh@redhat.com>
vdeenadh pushed a commit to vdeenadh/ramen that referenced this issue Aug 9, 2021
- Don't use subpath field when mounting to the RamenConfig configuration
  map, which is known to not refresh within the pod.
  kubernetes/kubernetes#50345 (comment)

Thanks to Shyam Ranganathan for contributing this change.

Signed-off-by: Veera Deenadhayalan <vdeenadh@redhat.com>
vdeenadh pushed a commit to vdeenadh/ramen that referenced this issue Aug 10, 2021
- Don't use subpath field when mounting to the RamenConfig configuration
  map, which is known to not refresh within the pod.
  kubernetes/kubernetes#50345 (comment)

Thanks to Shyam Ranganathan for contributing this change.

Signed-off-by: Veera Deenadhayalan <vdeenadh@redhat.com>
vdeenadh pushed a commit to vdeenadh/ramen that referenced this issue Aug 11, 2021
- Don't use subpath field when mounting to the RamenConfig configuration
  map, which is known to not refresh within the pod.
  kubernetes/kubernetes#50345 (comment)

Thanks to Shyam Ranganathan for contributing this change.

Signed-off-by: Veera Deenadhayalan <vdeenadh@redhat.com>
ShyamsundarR pushed a commit to RamenDR/ramen that referenced this issue Aug 11, 2021
- Don't use subpath field when mounting to the RamenConfig configuration
  map, which is known to not refresh within the pod.
  kubernetes/kubernetes#50345 (comment)

Thanks to Shyam Ranganathan for contributing this change.

Signed-off-by: Veera Deenadhayalan <vdeenadh@redhat.com>
ShyamsundarR pushed a commit to red-hat-storage/ramen that referenced this issue Aug 12, 2021
- Don't use subpath field when mounting to the RamenConfig configuration
  map, which is known to not refresh within the pod.
  kubernetes/kubernetes#50345 (comment)

Thanks to Shyam Ranganathan for contributing this change.

Signed-off-by: Veera Deenadhayalan <vdeenadh@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. sig/storage Categorizes an issue or PR as relevant to SIG Storage.
Projects
None yet
Development

No branches or pull requests