Secrets in Kubernetes: Keeping Passwords, Keys and Tokens Safe
A beginner-friendly, ground-up guide to what Kubernetes Secrets are, how they travel through a cluster, where they can leak, and how real teams protect them in production.
Imagine you run a busy restaurant. The recipes are written on cards pinned to the kitchen wall, and every cook can read them. But the key to the cash register, the code for the safe and the password to the bank account are not pinned to the wall. They live in a locked drawer, and only the people who truly need them get access, and only for as long as they need them. Kubernetes Secrets are the locked drawer of your software kitchen.
Every real application needs private information to do its job: a database password, a key to talk to a payment service, a certificate that proves its identity. If that information is written carelessly into the application itself, anyone who sees the code sees the keys. This guide walks you, step by step, through how Kubernetes handles this problem, what it does well, where it is weaker than most beginners assume, and how professional teams build a safe setup around it.
1What Is a Secret, Really?
Before Kubernetes enters the picture, we need to agree on what “secret” means in software.
The plain-English definition
A secret is any small piece of data that gives power to whoever holds it. A password lets you log in. An API key lets you spend someone’s money or read someone’s data. A private certificate key lets you pretend to be a trusted website. If a stranger gets one of these, they can act as if they were you, which is why we protect them more carefully than ordinary settings.
Ordinary settings, such as the colour of a button or the name of a country, are not secret. If they leak, nothing bad happens. The whole idea of a Secret in Kubernetes is to give sensitive values a separate home, with separate rules, away from the ordinary settings.
Think of your house. The address on the front door is public information, like an ordinary setting. The spare key hidden for the babysitter is a secret. You would never paint the key’s location on the front door for the whole street to read, and you would tell only the babysitter where it is.
Why not just put secrets in the code?
Beginners often ask why they cannot simply type the password into the program. The trouble is that code travels. It gets copied to laptops, uploaded to shared repositories, packed into images, and read by many colleagues. A password written into code follows it everywhere, and you can never fully take it back once it has been copied.
Changing a password also becomes painful. If the password is baked into the program, you must rebuild and redeploy the whole application just to change one word. Keeping secrets outside the program means you can change them without touching the program at all.
Many people believe that a private code repository is a safe place for secrets. It is not. Private repositories get shared, cloned, backed up and sometimes made public by mistake. Treat any secret that has ever appeared in code as already leaked.
2Kubernetes in Five Minutes
A quick tour of the building blocks you need before Secrets make sense.
Kubernetes is a system that runs and manages applications packed into small, portable boxes called containers. Instead of you starting programs by hand on individual computers, you tell Kubernetes what you want, and it keeps making that true. If a program crashes, Kubernetes restarts it. If traffic grows, Kubernetes can start more copies.
Cluster
The whole group of computers that Kubernetes manages together, acting like one big machine.
Node
A single computer inside the cluster, physical or virtual, that actually runs your containers.
Pod
The smallest unit Kubernetes runs. A pod wraps one or more containers that live and work together.
Namespace
A named section of the cluster used to separate teams, projects or environments from each other.
API Server
The front desk of the cluster. Every request to read or change anything goes through it.
etcd
The cluster’s memory. A database that stores the entire state of the cluster, including Secrets.
Picture a large shopping mall. The mall is the cluster, each shop is a node, and each counter inside a shop is a pod. Namespaces are the separate floors. The management office is the API server, and the office filing cabinet holding every record is etcd.
Keep the last two blocks in mind. Nearly every security question about Secrets comes back to who can talk to the API server and who can peek inside etcd.
3What Is a Kubernetes Secret?
A Secret is a Kubernetes object designed to hold a small amount of sensitive data.
The core idea
A Kubernetes Secret is a named object stored in the cluster that holds one or more key and value pairs. The keys might be “username” and “password”, and the values are the actual sensitive data. Applications running in pods can be given access to these values without the values ever being written into the application’s image or its deployment description.
Kubernetes was built with a clear division of labour. The person who knows the password creates the Secret. The person who writes the application simply says “this pod needs that Secret”. The real value never has to be copied around by hand between them.
Why Secrets exist as a separate object
Kubernetes already has another object for ordinary settings, called a ConfigMap. Secrets are a sibling of ConfigMaps, but they are treated with extra care. Secrets can be given tighter access rules, are kept away from casual logs and printouts, and are handled more carefully on the nodes that use them.
A ConfigMap is the notice board in the staff room, where everyone can read the shift timings. A Secret is the small safe under the manager’s desk. Both hold information for the team, but only one is built to keep prying eyes away.
What a Secret looks like inside
A Secret has a name, lives in a namespace, has a type that describes its purpose, and carries a bundle of data entries. The data values are stored in an encoded form called base64. Beginners nearly always misunderstand this last point, so it deserves its own chapter later. For now, remember only this: base64 is a way of writing data, not a way of hiding it.
4Types of Secrets
Kubernetes labels each Secret with a type so that tools know what to expect inside it.
The type tells Kubernetes and other tools what shape of data the Secret should contain. Some types are checked by Kubernetes itself, for example by insisting that certain keys are present. Others are simply labels to help humans and tools.
Opaque
The general-purpose default. Holds any keys and values you like, such as database passwords or third-party API keys.
Docker Config
Stores login details for a private container image registry so the cluster can download your private images.
TLS
Holds a certificate and its matching private key, used to secure web traffic with HTTPS.
Basic Authentication
Stores a username and password pair meant for simple login checks.
SSH Authentication
Keeps a private SSH key that a pod can use to connect securely to other systems.
Service Account Token
An identity token that lets a pod prove who it is when talking to the Kubernetes API server.
Bootstrap Token
A short-lived token used when new nodes are joining a cluster for the first time.
If you are not sure which type to use, Opaque is the right answer for most application secrets. Pick the specialised types only when a tool, such as an ingress controller or an image puller, expects that exact shape.
A closer look at the TLS type
The TLS type is one of the most common in daily life. Whenever you visit a website with a padlock in the browser, a certificate and a private key are working behind the scenes. In Kubernetes, the certificate and key are kept in a TLS Secret, and the component that handles incoming web traffic reads them from there. Because the private key lets anyone impersonate your website, this Secret is among the most valuable in the cluster.
A closer look at the registry type
Companies rarely publish every container image to the public internet. Private images sit in private registries that demand a login. The Docker Config type stores that login, and Kubernetes uses it when a node needs to pull an image. Without it, the pod would be stuck waiting, unable to fetch its own software.
5How Pods Use Secrets
Creating a Secret is only half of the story. The other half is getting it safely to the application that needs it.
There are three main ways a pod can receive the contents of a Secret. Each has strengths and weaknesses, and choosing well is one of the first real security decisions you will make.
Way 1: Environment Variables
The value of the Secret is placed into the application’s environment when the container starts. The application reads it like any other setting. This is simple and works with almost any software, but environment variables are easy to leak by accident, for example when a program prints its settings during a crash report.
Way 2: Mounted Files
Each entry in the Secret appears as a small file inside a folder in the container. The application opens the file and reads the value. This method is generally preferred, because files can be given tight permissions, and updated values can appear in the folder without restarting the pod.
Way 3: Image Pull Credentials
The Secret is not seen by the application at all. Instead, the node uses it to log in to a private registry and download the container image. This is how private software gets started in the first place.
flowchart LR
S["Secret object in the cluster"] --> E["Environment variable"]
S --> F["Mounted file"]
S --> R["Registry login for image pull"]
E --> A["Application in the pod"]
F --> A
R --> N["Node downloads private image"]
N --> A
The diagram shows that one Secret can feed an application in different ways. The registry route is a little different because the node, not the application, is the one using the Secret, but the end result is the same: the application is able to start and do its work.
Environment variables are like shouting a password across a room: quick, but anyone nearby may hear it. A mounted file is like handing a sealed envelope to one person. The registry login is like showing your membership card at the gate so that the delivery truck can bring in the goods.
A value delivered as an environment variable is fixed at the moment the container starts. If you later change the Secret, the running container will not notice. You must restart the pod to see the new value.
6Internal Working: What Happens Behind the Curtain
Let us follow a Secret from the moment it is created to the moment an application reads it.
Step one: the Secret is stored
When someone creates a Secret, the request goes to the API server. The API server checks who is asking, checks whether that person is allowed to create Secrets, and then writes the Secret into etcd, the cluster’s database. From this moment, the Secret exists as a permanent record.
Step two: the Secret is scheduled to a node
When a pod that needs the Secret is placed on a node, the kubelet, which is the small manager program running on every node, notices. The kubelet asks the API server for the Secret. The API server again checks permissions, and this time the answer is limited: a node may only receive the Secrets needed by pods actually running on it.
Step three: the Secret is delivered to the pod
The kubelet places the Secret’s data into the pod. For mounted files, the kubelet stores the data in memory-backed storage on the node rather than on the hard disk. This design means that the secret values do not get written into permanent disk storage, and they vanish when the pod is removed.
sequenceDiagram
participant Admin as Administrator
participant API as API Server
participant DB as etcd
participant Kubelet as Kubelet on Node
participant Pod as Application Pod
Admin->>API: Create Secret
API->>API: Check identity and permissions
API->>DB: Store Secret
Kubelet->>API: Request Secret for a scheduled pod
API->>Kubelet: Send Secret if node is authorised
Kubelet->>Pod: Provide as file in memory or as variable
Pod->>Pod: Application reads the value
Because mounted Secrets live in memory on the node, someone who steals a hard drive from a decommissioned machine will not find old passwords on it. This is a small but clever protection built into the design.
Automatic updates for mounted files
When a Secret is changed, the kubelet periodically checks for updates and refreshes the mounted files. There is a short delay, often up to a minute or so, before the new value appears. Applications that reread their files can pick up the change without a restart, which makes password rotation far smoother.
7The Life of a Secret
Every secret goes through stages, from birth to retirement. Good teams plan for all of them.
Creation
Someone generates a strong password, key or token, ideally with a tool rather than by inventing it by hand, and places it in a trusted store.
Storage
The value is saved as a Secret in the cluster, or fetched into the cluster from an external vault that acts as the true home of the secret.
Distribution
The kubelet delivers the Secret to only those pods that have asked for it, on only those nodes where they run.
Use
The application reads the value and uses it to log in, sign requests or encrypt traffic.
Rotation
On a regular schedule, or immediately after any suspicion of leakage, the old value is replaced with a new one.
Revocation and Deletion
When the secret is no longer needed, it is switched off at the source, for example by disabling the account, and then removed from the cluster.
Most beginners think only about the first four steps. Experienced engineers spend just as much time on the last two, because a secret that can never be replaced or retired is a risk that grows every year.
A hotel room key card works the same way. It is created at check-in, used during the stay, and switched off at check-out. If a guest loses the card, the hotel immediately issues a new one and cancels the old. A secret needs the same discipline.
8Encoding Is Not Encryption
The single most important lesson for anyone new to Kubernetes Secrets.
When you look at a Secret’s stored data, the values look like a jumble of letters and numbers. It is natural to think they have been scrambled for safety. They have not. The jumble is base64, a method of writing any data using only ordinary letters, digits and a few symbols, so that it can travel safely inside text files.
Anyone can turn base64 back into the original text in a second, with no password and no special tool. It is like writing a message in a different alphabet that everybody in the world happens to know.
Imagine putting your house key inside a see-through plastic bag. The bag keeps the key tidy and stops it from getting lost, but it does nothing to hide the key from someone who looks. Base64 is the plastic bag.
So why does Kubernetes use it?
Secret values can be binary data, such as certificates and keys, which do not fit neatly into text files. Base64 lets Kubernetes carry any kind of data inside its text-based descriptions. It is a convenience for transport, not a protection.
By default, the Secrets stored in etcd are not encrypted either. Anyone who obtains a copy of etcd’s data, or a backup of it, can read every secret in the cluster. Real protection requires deliberate steps, which we cover in the next chapter.
9Security: Building Real Protection
Since Secrets are not safe by default, security is built in layers around them.
Layer 1: Control who can read Secrets
Kubernetes uses a system called role-based access control, usually shortened to RBAC. It decides who may do what to which objects. The golden rule is least privilege: give each person and each program only the exact access they need, and nothing more.
Be especially careful with permissions to list or watch Secrets. Someone who is allowed to list all Secrets in a namespace can read every value, even if they were never told the names. Also remember that anyone allowed to create a pod in a namespace can point that pod at any Secret in the same namespace and read it. Pod creation rights are therefore a hidden form of Secret access.
Layer 2: Encrypt Secrets at rest
Kubernetes can be configured so that the API server encrypts Secret data before writing it into etcd. With this turned on, a stolen copy of etcd is unreadable without the encryption key. The strongest form uses an external key management service, so the key that unlocks the Secrets is never stored next to the Secrets themselves.
Layer 3: Protect traffic
Secrets travel across the network between the API server, etcd and the nodes. Every one of these paths should use encrypted connections. Kubernetes components normally do this by default, but it is worth verifying in any environment you build yourself.
Layer 4: Separate with namespaces and nodes
Namespaces divide Secrets into groups, and RBAC can be applied to each group separately. For highly sensitive workloads, teams also pin them to dedicated nodes, so that a compromise of a lower-value application cannot reach the memory of the machine holding critical secrets.
Layer 5: Watch everything
Audit logs record who read which Secret and when. Reviewing them, and raising alarms on unusual reads, turns silent theft into visible events. We look at this in more detail in a later chapter.
flowchart TD
A["Secret data"] --> B["Layer 1: RBAC limits who can read"]
B --> C["Layer 2: Encryption at rest in etcd"]
C --> D["Layer 3: Encrypted network traffic"]
D --> E["Layer 4: Namespace and node separation"]
E --> F["Layer 5: Audit logs and alerts"]
A bank does not rely on a single lock. It has a guarded gate, a locked door, a vault, cameras and a logbook. If one layer fails, the others still stand. Secret protection in Kubernetes follows the same thinking.
10Beyond Built-in Secrets: External Secret Managers
Many companies decide that the cluster should not be the true home of their most valuable secrets.
An external secret manager is a dedicated service built only for storing, protecting, rotating and auditing secrets. Examples include HashiCorp Vault, and the managed offerings of the major cloud providers. These services offer stronger features than a plain Kubernetes Secret: automatic rotation, detailed history, short-lived credentials and fine control of access.
The challenge is bringing those secrets to the applications inside the cluster. Several popular approaches exist.
External Secrets Operator
A helper running in the cluster that copies values from an external manager into ordinary Kubernetes Secrets and keeps them fresh.
Secrets Store CSI Driver
Mounts secrets from an external manager directly into the pod as files, and can avoid creating a Kubernetes Secret at all.
Vault Agent Injector
Adds a small sidecar container to your pod that logs in to Vault and writes the secrets into a shared folder for the application.
Sealed Secrets
Lets you encrypt a Secret so the encrypted form can be safely stored in a shared repository. Only the cluster can decrypt it.
| Approach | Where the true secret lives | Main benefit | Main trade-off |
|---|---|---|---|
| Plain Kubernetes Secret | Inside the cluster | Simple, built in, no extra tools | Weak by default, manual rotation |
| External Secrets Operator | External manager | Central control, automatic sync | Still creates a copy inside the cluster |
| Secrets Store CSI Driver | External manager | Can skip the in-cluster copy | More moving parts to run |
| Vault Agent Injector | Vault | Short-lived credentials, rich policies | Extra sidecar in every pod |
| Sealed Secrets | Encrypted file in a repository | Safe for version-controlled workflows | Tied to one cluster’s key |
Small teams and learning projects are perfectly fine starting with built-in Secrets, as long as encryption at rest and tight RBAC are switched on. As the number of applications and the sensitivity of the data grow, moving to an external manager is the natural next step.
Keeping secrets only in Kubernetes is like keeping valuables in a safe inside your own shop. An external manager is like using a professional bank vault: you take out only what you need for the day, the bank keeps a record, and it changes the locks for you regularly.
11Rotation and Immutability
Changing secrets safely is just as important as storing them safely.
Why rotate at all?
Every day a secret exists, the chance that it has leaked grows a little. People leave companies, laptops get lost, and logs sometimes capture things they should not. Rotation limits the damage by making sure that a stolen secret expires and becomes useless.
Rotation should be routine, not a panic reaction. A team that rotates its secrets every few weeks will handle a real emergency calmly, because the process is already tested and familiar.
How rotation reaches the application
How smoothly a rotation goes depends on how the Secret is delivered. Mounted files can refresh on their own, and an application that rereads its files will pick up the new value. Environment variables are locked in at startup, so those pods must be restarted. Good applications are designed to reload their credentials, or to fail gracefully and retry, when a password changes.
Immutable Secrets
Kubernetes allows a Secret to be marked immutable, meaning its contents can never be edited once created. This sounds restrictive, but it brings real benefits. It prevents accidental changes that could break every pod at once, and it reduces the load on the API server because the kubelet no longer needs to keep checking for updates. To change an immutable Secret, you create a new one with a new name and switch your pods over to it, which also gives you a clean, reversible rollout.
Advantages of Immutable Secrets
- Protection against accidental edits that break many pods
- Lower load on the API server in large clusters
- Clear, versioned changes that are easy to roll back
- Simpler reasoning about which value a pod is using
Trade-offs
- Every change means creating a new Secret and updating pods
- Old Secrets pile up if nobody cleans them
- Not suited to values that must change frequently in place
12Monitoring, Logging and Auditing
You cannot protect what you cannot see.
Even with strong locks, a careful team assumes that something may eventually go wrong and prepares to notice it quickly. For Secrets, this means keeping a record of every access and watching that record for strange behaviour.
Audit logs
The API server can record every request it receives: who asked, what they asked for, and whether it was allowed. For Secrets, the important recording level captures the fact that a read happened without writing the secret value itself into the log. A poorly configured audit log that copies the secret data would simply create a second, less protected copy of the secret.
What to watch for
Bulk Reads
A single identity listing or reading many Secrets in a short time is a classic sign of someone searching for treasure.
Unusual Hours or Places
Secret reads from unexpected times, networks or accounts deserve a closer look.
Denied Requests
A burst of refused attempts to read Secrets often means someone is probing for weak spots.
New Pods Mounting Old Secrets
A freshly created pod that suddenly references a sensitive Secret it never used before can indicate misuse.
Keeping secrets out of ordinary logs
Applications sometimes print their whole configuration when they start, or dump everything during an error. If a secret is in that output, it now sits in the logging system, where many more people can read it. Teams should review what their applications print, and log collection tools can be set to mask values that look like passwords or keys.
Debug tools and cluster dashboards may display Secret values on screen. Limit who can use them, and never share screenshots that include Secret data in chat tools or tickets.
13Design Patterns and Anti-Patterns
Patterns are proven habits that work. Anti-patterns are popular mistakes that keep hurting teams.
Patterns worth adopting
One Secret per Purpose per Application
Give each application its own Secret with its own credentials. If one is compromised, the damage stays within a single application instead of spreading across many.
Short-Lived Credentials
Where possible, use secrets that expire in minutes or hours rather than months. A stolen credential that dies quickly is a small problem instead of a disaster.
Workload Identity
Instead of storing a cloud access key in a Secret, let the pod prove its identity to the cloud provider directly. No long-lived key is stored, so there is nothing to steal.
Secrets Delivered by Automation
Let tools, not humans, move secrets into the cluster. Fewer people handling secrets means fewer chances for mistakes and leaks.
Anti-patterns to avoid
Problem
The team stores Secret descriptions, complete with base64 values, in a shared code repository so that deployments are easy.
Why It’s Harmful
Base64 is trivially reversed, so anyone with repository access can read every secret. The history of the repository also keeps old values forever, even after they are deleted from the latest version.
Correct Approach
Keep only encrypted forms in the repository, using a sealing tool, or keep the secrets in an external manager and store only references to them.
Problem
Everyone in the company receives broad cluster-admin rights, because it is quicker than setting up proper roles.
Why It’s Harmful
Every person and every automated tool can now read every Secret in every namespace. One stolen laptop or one careless script exposes everything.
Correct Approach
Design narrow roles per team and per namespace, review them regularly, and grant broader rights only for limited periods.
Problem
One shared Secret holding the master database password is used by every application in the company.
Why It’s Harmful
Rotating the password becomes a risky company-wide event, and there is no way to tell which application misused it. A leak from any one application exposes the whole database.
Correct Approach
Create separate database accounts for each application, each with only the permissions it needs, and store each in its own Secret.
Problem
Secrets are baked into container images so that the application simply starts with everything it needs.
Why It’s Harmful
Images are copied, cached and shared widely. Anyone who can download the image can unpack it and read the secret, and changing the secret means rebuilding the image.
Correct Approach
Keep images free of secrets and supply them at run time through Secrets or an external manager.
14Advantages, Disadvantages and Trade-offs
An honest look at what built-in Kubernetes Secrets give you, and what they do not.
Advantages
- Built into Kubernetes, so there is nothing extra to install
- Separates sensitive values from application code and images
- Works with the same access rules as other cluster objects
- Mounted Secrets are kept in memory on nodes, not on disk
- Nodes receive only the Secrets needed by their own pods
- Easy for developers to understand and adopt quickly
Disadvantages / Trade-offs
- Values are only base64 encoded, not encrypted, by default
- Not encrypted in etcd unless you turn that on deliberately
- No built-in rotation, expiry or detailed version history
- Anyone who can create pods in a namespace can reach its Secrets
- Environment variables can leak through logs and crash reports
- Limited size of about one mebibyte per Secret
The takeaway is not that Kubernetes Secrets are bad. They are a useful foundation. But they are a foundation, not a finished building. The security of your secrets depends on what you build around them.
15Best Practices and Common Mistakes
A checklist of habits that separate careful teams from careless ones.
Best practices
- Turn on encryption at rest — ideally with a key held in an external key management service, so the lock and the key are never stored together.
- Apply least privilege everywhere — narrow RBAC roles, per-namespace permissions and no casual cluster-admin access.
- Prefer mounted files over environment variables — files are easier to protect and can refresh without a restart.
- Keep secrets out of code, images and repositories — use sealing tools or external managers for anything that must be version controlled.
- Rotate on a schedule — practise rotation regularly so it is never a stressful, untested event.
- Use separate credentials per application — so a single leak cannot open every door.
- Audit and alert — record reads of Secrets, and raise alarms on unusual patterns.
- Prefer short-lived and identity-based access — the best secret is the one that does not need to be stored.
Common mistakes
Many teams relax because the values look scrambled. Remember that anyone with read access sees the real value in one step.
Cluster backups contain Secrets too. A backup stored in an open storage location undoes all the careful protection inside the cluster. Encrypt and restrict backups just like the cluster itself.
Old Secrets from retired applications linger for years, and each one is a door that nobody remembers. Delete what you no longer use, after disabling it at the source.
Pasting a password into a team chat or a ticket creates a permanent, searchable copy. Use the approved secret store for every hand-over.
16Real-World Examples
How the ideas in this guide show up in everyday engineering.
An Online Shop and Its Payment Provider
An online shop needs an API key to talk to a payment provider. The key lives in a Secret in the shop’s own namespace, is mounted as a file into only the checkout pods, and is rotated every month. The catalogue and search pods, which do not handle payments, cannot read it at all.
A Bank and Its Database Credentials
A bank keeps database logins in an external vault. Each application receives a temporary username and password that expires within hours. Even if an attacker steals one, it stops working before they can do much with it, and the vault’s log shows exactly which application asked for it.
A Media Company and Its Website Certificates
A media company serves thousands of sites over HTTPS. Certificates and private keys are held as TLS Secrets, and an automation tool renews them before they expire. Nobody copies keys by hand, which removes a whole class of human error.
A Start-up Using Sealed Secrets
A small start-up wants all of its cluster description kept in version control, including secrets. They use a sealing tool so that only encrypted forms are stored in the repository. Only the cluster can decrypt them, so a leaked repository does not leak the passwords.
A Software Vendor and Private Images
A software vendor keeps its container images in a private registry. A registry login Secret in each namespace lets the cluster download those images, while the same login is limited to read-only access so it cannot be abused to overwrite the images.
17Frequently Asked Questions
Only to the extent that you protect it. By default the values are merely base64 encoded and are stored unencrypted in etcd. With encryption at rest, tight access rules and auditing, a Secret becomes properly protected.
Both hold configuration for applications. A ConfigMap is meant for ordinary, non-sensitive settings. A Secret is meant for sensitive values and receives extra handling, such as memory-backed storage on nodes and separate access rules.
Mounted files are usually the safer choice. They are less likely to appear in logs and crash reports, they can carry strict permissions, and they can refresh without restarting the pod. Environment variables are simpler but leak more easily.
A pod can only use Secrets from its own namespace. However, someone with broad permissions across namespaces can still read Secrets in all of them, which is why access rules matter so much.
Not always. For small or low-risk setups, well-configured built-in Secrets can be enough. As the number of applications, the sensitivity of the data or regulatory demands grow, an external manager brings rotation, short-lived credentials and better audit trails.
The Secret object stays in the cluster. Only the copy delivered to that pod, including the memory-backed files on the node, is removed along with the pod.
There is no single answer, but a common approach is every few weeks to a few months for long-lived secrets, and immediately after any suspected leak or staff departure. Short-lived credentials that expire on their own reduce the need for manual rotation.
Only if the backups themselves are encrypted and restricted. A backup of etcd contains all the Secrets, so it must be guarded with the same care as the live cluster.
Secrets are stored in etcd and sent through the API server. Very large objects would slow down the whole cluster, so each Secret is limited to about one mebibyte. Secrets are meant for small values like keys and passwords, not for large files.
Start by tightening who can read Secrets and turning on encryption at rest. These two steps close the most common gaps with modest effort.
18Summary and Key Takeaways
Kubernetes Secrets give applications a dedicated, separate place to receive passwords, keys and tokens, so that these values need not live in code or images. They travel from the API server and etcd, through the kubelet, into pods as files or environment variables, and they are treated with more care than ordinary settings. But out of the box, they are only encoded, not encrypted, and real safety comes from the layers you add: strict access rules, encryption at rest, careful delivery, rotation, monitoring and, for the most sensitive cases, an external secret manager.
Treat secrets the way a good restaurant treats its safe: known location, few keys, regular code changes and a record of every opening. Do that, and Kubernetes becomes a trustworthy home for the private parts of your software.
Key Takeaways
- A Secret is a separate home for sensitive data — it keeps passwords, keys and tokens out of code, images and ordinary settings.
- Base64 is not encryption — anyone who can read a Secret can decode it instantly, and etcd stores it unencrypted unless you enable encryption at rest.
- Access control is the first defence — apply least privilege with RBAC, and remember that the right to create pods is also a way to reach Secrets.
- Prefer mounted files to environment variables — files leak less, carry permissions and can refresh without restarting pods.
- Plan the whole life of a secret — creation, distribution, rotation and revocation all matter, and rotation should be routine.
- Consider external managers as you grow — vaults and cloud services add rotation, short-lived credentials and stronger audit trails.
- Watch and record access — audit logs and alerts turn silent theft into events you can see and react to.