What happened?
The docs say this about immutable Secrets
https://kubernetes.io/docs/concepts/configuration/secret/#secret-immutable-create
Note:
Once a Secret or ConfigMap is marked as immutable, it is not possible to revert this change nor to mutate the contents of the data field. You can only delete and recreate the Secret. Existing Pods maintain a mount point to the deleted Secret - it is recommended to recreate these pods.
However, we're seeing different behavior. After the "delete and recreate" we see a mix of behavior. First off, if we recreate the Secret with new keys. New pods cannot mount these keys, but they can mount previously existing keys. If we add a new key in the newly created Secret (with the same name), we'll get an error like this:
Error: couldn't find key FOO in Secret test/mysecret
But if we view the Secret with kubectl the new key exists. There is also a more difficult to reproduce problem where some pods get old values in the existing keys, and some pods get new values. I think all the symptoms stem from the same issue, which is that the kubelet caches the immutable secret forever. The documentation indicates that on Pod create, this would be refreshed, but that does not seem to happen.
Is the documentation incorrect in that the kubelet persists the data forever and may never update it?
As a pretty harsh workaround, I recreated nodes in the cluster and these fresh Nodes pulled the updated Secret and values.
What did you expect to happen?
After recreating the immutable secret, new pods would be able to access the updated values.
How can we reproduce it (as minimally and precisely as possible)?
- Create an immutable Secret
- Start and mount the Secret to a Pod
- Delete the immutable Secret
- Recreate the immutable Secret with new values
- Start and mount the Secret to a new Pod that is scheduled on the same node as the previous Pod
Anything else we need to know?
Likely related issue: #124701
Kubernetes version
Details
$ kubectl version
Client Version: v1.31.0
Kustomize Version: v5.4.2
Server Version: v1.30.10-gke.1070000
Cloud provider
Details
GKE
OS version
Details
Install tools
Details
Container runtime (CRI) and version (if applicable)
Details
Related plugins (CNI, CSI, ...) and versions (if applicable)
Details
What happened?
The docs say this about immutable Secrets
https://kubernetes.io/docs/concepts/configuration/secret/#secret-immutable-create
However, we're seeing different behavior. After the "delete and recreate" we see a mix of behavior. First off, if we recreate the Secret with new keys. New pods cannot mount these keys, but they can mount previously existing keys. If we add a new key in the newly created Secret (with the same name), we'll get an error like this:
But if we view the Secret with
kubectlthe new key exists. There is also a more difficult to reproduce problem where some pods get old values in the existing keys, and some pods get new values. I think all the symptoms stem from the same issue, which is that thekubeletcaches the immutable secret forever. The documentation indicates that on Pod create, this would be refreshed, but that does not seem to happen.Is the documentation incorrect in that the
kubeletpersists the data forever and may never update it?As a pretty harsh workaround, I recreated nodes in the cluster and these fresh Nodes pulled the updated Secret and values.
What did you expect to happen?
After recreating the immutable secret, new pods would be able to access the updated values.
How can we reproduce it (as minimally and precisely as possible)?
Anything else we need to know?
Likely related issue: #124701
Kubernetes version
Details
Cloud provider
Details
GKEOS version
Details
Google COSInstall tools
Details
Container runtime (CRI) and version (if applicable)
Details
Related plugins (CNI, CSI, ...) and versions (if applicable)
Details