Kubernetes Secret rotation: verify the consumer
Determine which consumer boundary is stale and retire an old credential only after the replacement is used.
Quick answer
Kubernetes Secret rotation needs separate checks for issuer acceptance, mounted content and application adoption. Ordinary volume projection does not make a process reopen credentials, and subPath mounts do not receive automatic updates. Verify a newly authenticated client and all intended consumers before retiring the old credential.
On this page
Kubernetes Secret rotation is complete only when the application uses the replacement credential successfully. A changed Secret object proves that Kubernetes accepted new data. It does not prove that a mounted file changed, that the process reopened it, or that an existing connection pool stopped authenticating with the old credential. Diagnose those boundaries separately before retiring the old value. [1][2][4]
Scenario: an invoice API reads database credentials from a mounted directory. Its operator rotates the database account, updates a Kubernetes Secret and watches healthy Pods continue serving. Later, opening a new database connection fails. The old connections had hidden the fact that the application never adopted the replacement. This is a fictional investigation, not a customer incident or a claim about a particular database driver.
Check which credential the next fresh database authentication actually uses. Answering it needs evidence from the credential issuer, the container filesystem and the application. A green Deployment supplies only part of that evidence. The runbook below separates those observations and gives the operator a concrete decision about when to reload, replace Pods or stop the rotation.
Which boundary still holds the old credential?#
Start with the consumer path rather than another Secret update. Read the workload definition and determine whether the application receives an environment variable, a directory mount, a single-file subPath mount or a CSI volume. Also identify whether it reads the value at startup, reopens a file for each connection, or builds a long-lived client object. Those are different update contracts. [1][2][4]
Use a narrow manifest inspection that does not print credential data. Substitute the namespace and workload names appropriate to your environment. The example commands inspect only workload references and Secret metadata; they do not demonstrate that the application accepted a credential.
kubectl -n billing get deployment invoice-api -o yaml
kubectl -n billing get secret invoice-db \
-o jsonpath='{.metadata.uid}{" "}{.metadata.resourceVersion}{"\n"}'Treat the resource version as an observation about an API object, not as the credential's business version. It can change for reasons beyond the secret value, and an external secret manager can have a different generation identifier. Our proposed rotation record stores both identifiers, the intended consumer path and the workload revision so that an operator can reconcile them without logging the password.
Scenario: the issuer calls the replacement generation green; the application reports blue as its active generation. These are harmless labels chosen for this exercise. They should identify a credential version without revealing its contents. A digest of a low-entropy password is not an equivalent safe label, because it can become material for guessing. Prefer an issuer version ID or an independently assigned generation tag.
Use this record to locate the stale boundary before choosing a replacement action:
| Boundary | Useful observation | What it leaves unproved |
|---|---|---|
| Issuer | Replacement generation is accepted in a controlled authentication check | Pods received it |
| Kubernetes or CSI projection | Expected generation is available at the intended path | The process reopened that path |
| Application | A newly created client reports the expected generation | Every replica adopted it |
| Service | Fresh authenticated requests succeed across the intended replicas | Old credentials can already be revoked everywhere |
This is our acceptance record, not a Kubernetes API specification. Its purpose is to prevent a filesystem check from becoming an application success claim. A process might read the correct file and still reuse a client that was initialized earlier. Conversely, a healthy old connection can continue serving while every attempt to open a replacement connection is already broken.
What changes when a Secret uses subPath?#
A Secret mounted through subPath does not receive automatic Secret updates. Kubernetes documents that exception, and the Secrets Store CSI Driver describes the same limitation for rotated content. Waiting longer for ordinary projection will not repair that mount contract. [1][2]
Compare these fragments from the fictional API. The directory mount allows the application to open the named file through the mounted directory. The single-file form chooses subPath; replacing the Secret content does not make that existing file mount follow the new projection. These are illustrative fragments, not complete Deployment manifests.
# Directory consumer: application opens /run/invoice-db/password
volumeMounts:
- name: invoice-db
mountPath: /run/invoice-db
readOnly: true
volumes:
- name: invoice-db
secret:
secretName: invoice-db# Different contract: this existing subPath mount will not rotate in place
volumeMounts:
- name: invoice-db
mountPath: /app/config/password
subPath: password
readOnly: trueFor an ordinary Secret volume, projection is eventually consistent. Kubernetes describes propagation through the kubelet's change-detection mechanism and synchronization cycle. Do not turn that description into a universal delay guarantee: first establish that the Secret reference and mount type are correct, then investigate the cluster's actual projection behavior. [1]
The CSI case adds another boundary: the external provider and the driver's configured rotation behavior. Check the installed driver, provider support and rotation configuration. A value changing in an external vault does not establish that the Kubernetes Secret or mounted CSI content already changed. The driver's current auto-rotation documentation distinguishes those paths and the application's responsibility to react to mounted changes. [4]
Removing subPath can be the right repair when the application can read a dedicated directory. Check what else lives at the destination first. Our recommendation is to give credentials their own mounted path, with the application explicitly configured to read it. That makes the ownership of the path apparent and avoids relying on a file placed among unrelated image configuration.
There is also a valid replacement strategy: keep the startup-only file contract and replace Pods deliberately after rotation. Choose it consciously. It trades hot-reload code for rollout work and requires the old credential to remain usable long enough for the intended replacement and verification process.
How should the invoice API adopt a rotation?#
Create and test a candidate database client before directing new requests to it. For our fictional API, that means opening the current credential path, constructing a candidate database client, testing the candidate under the application's required permissions, and only then directing new work to it. Existing requests need a defined drain policy. This is a proposed application design, not a feature supplied by a Secret volume.
An implementation needs more than a file-change callback. Decide what happens if reading fails, the replacement is malformed, the issuer has not enabled it yet, or authentication works but required queries are denied. In the example design, the current valid client remains active on a rejected candidate, the failure is observable, and the rotation remains incomplete. Automatically discarding the current client before testing the new one would turn a recoverable rollout mistake into an outage.
The application also needs to reopen the path that identifies the current projection. Keeping an old file handle or retaining a client created from old bytes can defeat the intention of an otherwise correct directory mount. The CSI limitation explanation describes the symlink-based projection mechanism; the operational requirement is to test the application's actual loading behavior instead of assuming that every filesystem notification means adoption. [2][4]
Scenario: the candidate client authenticates with generation green, but an older worker still reports blue. Do not revoke blue because the first successful request looked convincing. Enumerate the intended consumers: API replicas, job runners, scheduled tasks and administrative tools. The rotation record should say which of these are in scope and which owner supplies evidence for each.
Our proposed telemetry consists of a non-secret active-generation label, reload outcome and last successful fresh authentication. Keep the labels low-cardinality and avoid including tokens, usernames that are sensitive in your environment, or connection strings. An operator should be able to answer whether an old generation remains in use without retrieving its value from a log.
The acceptance check must force the behavior that matters. An existing connection answering a lightweight query is insufficient when the problem is new connection authentication. Exercise a newly created client in a bounded test appropriate to the service. Then confirm that normal application work uses the accepted client, rather than only a separate diagnostic client that never receives production requests.
When is a rolling replacement the better choice?#
Use replacement when the application reads credentials only at startup, exposes them through environment variables, or lacks a reload path you can verify. The CSI documentation explicitly says environment-variable consumers need Pod restart. The ConfigMap documentation describes the analogous environment-variable behavior; a reference in a workload definition is not a live environment update channel. [4][5]
Changing a Secret alone is not a Deployment Pod-template change. A Deployment rollout follows a change to that template, and scaling alone does not trigger one. Plan an explicit replacement action rather than expecting the controller to infer your credential-rotation intent. The replacement policy can be driven by your existing release process or a reviewed controller, but its triggers and access need to be understood. [3]
Before replacing anything, inspect readiness behavior, replacement capacity and the issuer's overlap policy. If the issuer supports overlapping credentials, retain the old generation until the replacement consumers are confirmed. If it permits only an immediate single-value change, acknowledge that constraint in the plan: you may need a coordinated maintenance interval or a different credential mechanism rather than a promise of uninterrupted service.
Returning to an earlier workload revision also needs care. If it references a mutable Secret name whose data already changed, replacing Pods from that earlier template does not necessarily restore the previous credential. Our ConfigMap rollback guide develops that release-identity problem. The credential issuer's revocation policy decides whether any old generation remains usable.
What evidence permits retiring the old credential?#
Retire it after the intended consumers demonstrate replacement adoption and the issuer's rollback and overlap conditions are satisfied. In our example, the operator records fresh authentication from the API and workers, checks that old-generation use has stopped within the defined scope, and confirms a recovery path if a missed consumer appears. The decision is tied to this evidence, not simply to elapsed waiting time.
Write the abort conditions before the change. A stale mount, rejected candidate, unexplained old-generation request or unknown consumer keeps the rotation open. The repair then follows the failed boundary: correct projection, repair loading, replace the affected workload or reconcile the consumer inventory. Repeating the issuer rotation obscures which generation each observation refers to.
Finally, separate readiness from credential acceptance. A readiness endpoint that returns success without using the database may be behaving exactly as designed. It simply cannot prove this rotation. Tie the acceptance check to the service's actual dependency behavior, and use the rollout revision guide when concurrent releases make the workload under observation ambiguous.
This runbook was checked against the cited documentation. The YAML fragments and acceptance model are illustrative; no live cluster, secret provider or database driver was exercised for this article. Before adopting the design, rehearse it with your installed versions and include a failed candidate, a missed consumer and the retirement of the old credential in that rehearsal.
What else should you check?#
- Does updating a Secret restart a Deployment?
- A Secret update does not itself change a Deployment's Pod template. Decide explicitly how startup-only consumers will be replaced, then observe the intended rollout and fresh authentication. Scaling replicas is not a substitute for defining a rotation trigger. [3][4]
- Will waiting longer update a subPath Secret mount?
- Kubernetes documents that a Secret consumed through subPath does not receive automatic Secret updates. Replace the affected Pods or choose a directory-mount design with an application reload contract. Waiting for the ordinary projection cycle does not change that exception. [1][2]
- Is checking the mounted file enough?
- A correct mounted value proves a filesystem observation, not client adoption. The application may retain an old client or connection. Our acceptance method checks a newly authenticated client and then confirms that intended requests and consumers actually use the accepted generation.
- Can an old credential be revoked after one successful request?
- One request proves only its own path. Reconcile API replicas, workers, jobs and other intended consumers, then apply the issuer's overlap and recovery policy. The rotation record should identify remaining old-generation use before the operator approves revocation.