October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Decode and Mount a Kubernetes Secret as a Read-Only Volume

Decode a Kubernetes Secret value with kubectl or mount its keys as read-only files. Learn how to limit projected keys, set file modes, and account for rotation and access risks.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Decode an individual Secret value with kubectl when you need to inspect it; mount the Secret as a volume when an application needs to read its values as files. Secret data is base64-encoded, not encrypted by that encoding, and Secret volumes are read-only. These steps limit how an application receives a value, but they do not replace access controls or encryption at rest.

Decode one Secret value with kubectl

Secret values in the API’s data field are base64-encoded. To print one value, substitute the Secret name and key in this command:

As an Amazon Associate I earn from qualifying purchases.

kubectl get secret my-secret -o jsonpath='{.data.password}' | base64 --decode

The decoded value is written to standard output. Base64 is a reversible encoding, not encryption; Kubernetes cautions against treating it as confidentiality. Avoid displaying the output where unauthorized people can see it, and do not put secret values in shell history or command logs. See Kubernetes’ Secrets documentation and kubectl Secret guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Mount a Secret as read-only files

A Secret volume exposes each Secret key as a file, with the value decoded for the application to read. The Secret and Pod must be in the same namespace. Add a volume to the Pod and mount it only in the container that needs the data:

#1 Best Overall
apiVersion: v1
kind: Pod
metadata:
  name: app
spec:
  containers:
    - name: app
      image: example/app:stable
      volumeMounts:
        - name: app-secret
          mountPath: /etc/app-secret
          readOnly: true
  volumes:
    - name: app-secret
      secret:
        secretName: my-secret

With the default key mapping, a Secret key named password is available to the container at /etc/app-secret/password. Secret volumes are inherently read-only; specifying readOnly: true makes the intended mount mode explicit. The example shows manifest structure and is not a tested deployment. Refer to Kubernetes’ Volumes documentation and Secrets documentation.

Expose only selected keys or change their file paths

By default, all keys are projected using their key names as filenames. Use items as an allowlist when the application needs only some keys, or when a key should appear at a different relative path:

volumes:
  - name: app-secret
    secret:
      secretName: my-secret
      items:
        - key: password
          path: credentials/password

Mounted at /etc/app-secret, this mapping makes the value available at /etc/app-secret/credentials/password. If items is specified, only the listed keys are projected, and every listed key must exist for the volume to be created. Restricting the projection to the keys the application needs reduces its exposure. Details are in Distribute Credentials Securely Using Secrets.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set file permissions where needed

Secret volume files default to mode 0644. Set defaultMode on the Secret volume for a volume-wide mode, or specify mode for an individual key to override it. For example, YAML accepts octal 0400. JSON does not support octal numeric literals, so use the decimal equivalent there. Choose a mode compatible with the container’s user and application; restrictive file permissions do not control who can otherwise access the Secret.

Plan for updates and rotation

When a Secret changes, Kubernetes propagates the new data to a mounted Secret volume eventually, rather than guaranteeing an immediate update. A Secret mounted using subPath does not receive automated updates. If an application relies on rotation, account for propagation delay and ensure it can reload or reopen the relevant files. See the Kubernetes Secrets and Volumes documentation.

Choose a direct Secret volume or a projected volume

For files from one Secret, a direct Secret volume is the simpler fit. A projected volume can combine multiple sources, including Secrets, ConfigMaps, and downward API data, into one directory. Its Secret source can map selected keys to paths. Choose based on how many sources the application needs and the directory layout it expects; see Projected Volumes.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What read-only mounting protects—and what it does not

Read-only means the container cannot write through that mount. It does not hide the mounted value from the process or from users able to read the file, and it does not prevent an authorized user from reading the Secret API object. Kubernetes documents that Secret objects are stored unencrypted in etcd by default; base64 encoding does not change that. Its security guidance recommends encryption at rest, least-privilege RBAC, and limiting Secret mounts or environment-variable references to the containers that need them. Treat Pod-creation privileges carefully: someone allowed to create Pods in a namespace may be able to arrange access to Secrets in that namespace. Applications must also protect values after reading them, including avoiding cleartext logs and untrusted transmission. See Kubernetes’ Secret security guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.