Kubernetes Secrets separate sensitive application settings from a container image. They can hold values such as a database password, token or certificate. That separation is useful, but the word “Secret” does not mean the value is automatically encrypted everywhere or hidden from every cluster user.
Secret values in the data field are base64-encoded. Base64 is an encoding, not encryption. Upstream Kubernetes stores Secrets unencrypted in etcd by default unless encryption at rest has been configured. Managed platforms can apply different defaults, so verify the settings for your own cluster.
Access control is equally important. Someone with permission to read a Secret can retrieve its contents. A person who can create workloads in a namespace may also be able to arrange for a workload to read a Secret there. Namespace access needs to reflect that relationship.
For a learning environment, place a disposable test value in a local file called password.txt. Keep it outside source control and restrict access to the file. The following example assumes that a namespace named demo already exists:
kubectl -n demo create secret generic app-credentials \
--from-file=password=./password.txt
The file is still sensitive. Using a file avoids putting its value directly into this command, but does not make local storage, backups or access to the workstation safe automatically. Production credential handling should follow your organisation’s approved process.
A workload can reference a Secret through an environment variable or a mounted file. Choose the method the application supports. Avoid exposing the same credential through both methods unless there is a reason.
Here is a fragment to place inside a container definition in a Pod or Deployment specification:
env:
- name: APP_PASSWORD
valueFrom:
secretKeyRef:
name: app-credentials
key: password
The Secret and the workload must be in the same namespace. This fragment does not create a complete Deployment or initialise a database; it only shows how an application environment variable can reference a Secret key.
Updating a Secret does not automatically change an environment variable inside an already-running process. Plan a controlled rollout when the application reads credentials at startup. Mounted Secret files have different update behaviour, and the application still needs a way to reload the changed value; mounts using subPath have additional limitations.
Test the full sequence: introduce the new credential, update the application, confirm connectivity, and retire the previous credential when it is safe to do so. Changing a Kubernetes object is only one part of rotation.
The Nandan Sinha newsletter
Get new articles on technology, practical guides, wellbeing and spirituality, delivered to your inbox.
Subscribe by email. Confirm your address to join. Unsubscribe anytime. Privacy policy.
We use essential cookies to run this website and optional cookies for analytics and advertising. Choose Accept All, Reject, or Preferences to manage optional cookies. You can change your choice at any time.
Manage your cookie preferences below:
Essential cookies enable basic functions and are necessary for the proper function of the website.
These cookies are needed for adding comments on this website.
Google's current Sign in with Google client library. It renders the Google sign-in button, or the One Tap prompt, so visitors can log in to your site with their Google account. It replaces the older Google Sign-In platform library.
Service URL: policies.google.com (opens in a new window)
Google Tag Manager simplifies the management of marketing tags on your website without code changes.
Statistics cookies collect information anonymously. This information helps us understand how visitors use our website.
Google Analytics is a powerful tool that tracks and analyzes website traffic for informed marketing decisions.
Service URL: policies.google.com (opens in a new window)
Marketing cookies are used to follow visitors to websites. The intention is to show ads that are relevant and engaging to the individual user.
AddToAny provides share and follow buttons that let visitors post your pages to social networks, messaging apps, and bookmarking services.
Service URL: www.addtoany.com (opens in a new window)
You can find more information in our Privacy Policy and Privacy Policy.

Leave a Reply