You deployed your application successfully. Your Pods are running. Your CI/CD pipeline is green.
But there's one problem.
Your database password is sitting inside a GitHub repository.
Your Kubernetes Secret is stored in plain YAML.
And your application credentials might be accessible to people who should never see them.
💀 Welcome to one of the most overlooked areas of Kubernetes: Secrets management.
Many developers believe that creating a Kubernetes Secret automatically makes sensitive information secure.
Unfortunately, that's not how it works.
Let's understand how Kubernetes Secrets work, explore common security mistakes, and learn how to protect sensitive information in a real cluster.
🧠 1. What Exactly Is a Kubernetes Secret?
A Kubernetes Secret is an object designed to store sensitive information such as:
- Database passwords
- API tokens
- TLS certificates
- Authentication credentials
- Private registry credentials
For example, imagine your application needs database credentials.
You could create a Secret:
apiVersion: v1 kind: Secret metadata: name: database-secret type: Opaque data: username: YWRtaW4= password: cGFzc3dvcmQxMjM= Apply it:
kubectl apply -f secret.yaml Check it:
kubectl get secrets Example output:
NAME TYPE DATA AGE database-secret Opaque 2 10s Looks secure, right?
Not necessarily.
Here's why.
💀 2. Mistake #1: Thinking Base64 Is Encryption
This is probably the biggest Kubernetes Secret misconception.
Look at this value:
cGFzc3dvcmQxMjM= It looks complicated.
But it's just Base64 encoding.
Decode it:
echo "cGFzc3dvcmQxMjM=" | base64 --decode Output:
password123 That's it.
Anyone who can read the encoded value can decode it.
Base64 is encoding, not encryption.
Never assume that placing a password inside a Kubernetes Secret automatically protects it.
For stronger protection, consider encryption at rest and an appropriate external secrets-management solution.
🔥 3. Mistake #2: Committing Secrets to GitHub
Imagine this workflow:
Developer | v Creates secret.yaml | v Pushes to GitHub | v Repository Becomes Public | v Credentials Exposed Even if you delete the file later, sensitive information may remain in Git history, forks, logs, or cached copies.
For example, avoid committing this:
apiVersion: v1 kind: Secret metadata: name: app-secret type: Opaque stringData: DATABASE_PASSWORD: my-super-secret-password Instead, use a secure process to inject credentials during deployment.
Some tools worth exploring:
- External Secrets Operator
- HashiCorp Vault
- AWS Secrets Manager
- Sealed Secrets
If a credential is accidentally exposed, rotate or revoke it immediately. Removing the file is not enough.
🔐 4. Mistake #3: Giving Everyone Access to Secrets
Imagine your Kubernetes cluster has ten developers.
Should every developer be able to read every Secret?
Absolutely not.
Kubernetes provides Role-Based Access Control (RBAC).
You can restrict permissions using Roles and RoleBindings.
Example Role:
apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: pod-reader rules: - apiGroups: [""] resources: ["pods"] verbs: ["get", "list", "watch"] This Role grants permission to read Pods in the default namespace.
It does not grant permission to read Secrets.
Create it:
kubectl apply -f role.yaml Check permissions:
kubectl auth can-i get secrets \ --as=system:serviceaccount:default:default Kubernetes RBAC follows the principle of least privilege.
Give users and service accounts only the permissions they actually need.
🚨 5. Mistake #4: Ignoring Encryption at Rest
By default, Kubernetes Secret data is not necessarily encrypted in the cluster's backing storage.
In many standard configurations, Secret data is stored in etcd without encryption at rest unless encryption is configured.
This creates a serious risk if someone gains unauthorized access to the underlying datastore or its backups.
Kubernetes supports encryption at rest using an EncryptionConfiguration.
A simplified example:
apiVersion: apiserver.config.k8s.io/v1 kind: EncryptionConfiguration resources: - resources: - secrets providers: - aescbc: keys: - name: key1 secret: BASE64_ENCODED_ENCRYPTION_KEY - identity: {} This is an illustrative configuration, not a ready-to-deploy production file.
A production setup needs a securely generated encryption key, appropriate API server configuration, key management, backup planning, and migration of existing Secret data.
You can also integrate an external Key Management Service (KMS).
The important lesson:
Protecting access to a Secret and encrypting its stored data are two different security controls.
🐳 6. Mistake #5: Passing Passwords Through Environment Variables Without Understanding the Risks
Kubernetes allows Secrets to be exposed to containers as environment variables.
Example:
apiVersion: v1 kind: Pod metadata: name: database-app spec: containers: - name: app image: nginx:1.27 env: - name: DB_PASSWORD valueFrom: secretKeyRef: name: database-secret key: password This is convenient.
However, environment variables can potentially be exposed through:
- Application debugging output
- Process inspection
- Crash reports
- Logs
- Diagnostic tooling
Another option is mounting Secrets as files.
apiVersion: v1 kind: Pod metadata: name: database-app spec: containers: - name: app image: nginx:1.27 volumeMounts: - name: secret-volume mountPath: /etc/secrets readOnly: true volumes: - name: secret-volume secret: secretName: database-secret The application can read the Secret from the mounted directory.
Neither approach automatically makes the application secure. You still need appropriate permissions, careful logging practices, and application-level protection.
⚠️ 7. Mistake #6: Forgetting That Secrets Are Namespace-Scoped
Here's a common mistake.
You create a Secret in the default namespace:
kubectl create secret generic db-secret \ --from-literal=password=example-password \ -n default Then you deploy an application in another namespace:
kubectl create namespace production You try to reference the Secret from a Pod in production.
It doesn't work.
Why?
Because Kubernetes Secrets are namespace-scoped.
A Pod can reference a Secret in its own namespace, not directly from another namespace.
Check your Secrets:
kubectl get secrets -A Create the Secret in the correct namespace using a secure process.
Don't solve this by giving every application access to a shared namespace containing all your credentials.
🛡️ 8. Mistake #7: Forgetting Secret Rotation
Imagine your application has used the same database password for two years.
What happens if that password is accidentally exposed?
If you never rotate credentials, an attacker may retain access for a long time.
A better approach includes:
- Establishing a credential rotation policy.
- Using short-lived credentials where possible.
- Updating application credentials safely.
- Testing that applications can reconnect.
- Revoking old credentials.
- Auditing access to sensitive information.
For larger environments, external secrets-management platforms can help automate this process.
Examples:
- HashiCorp Vault
- AWS Secrets Manager
- External Secrets Operator
Official resources:
https://developer.hashicorp.com/vault
https://docs.aws.amazon.com/secretsmanager/
🏗️ 9. Build a More Secure Kubernetes Secrets Architecture
Let's bring these concepts together.
Imagine a production application running on Kubernetes.
Instead of manually storing passwords in Git, use an external secrets-management system.
Architecture:
DEVELOPER | v GITHUB Application Code | v CI/CD | v KUBERNETES | v EXTERNAL SECRETS OPERATOR | v SECRET MANAGEMENT SYSTEM | v KUBERNETES SECRET | v APPLICATION POD For example, an External Secrets Operator can synchronize secrets from an external provider into Kubernetes Secrets.
This architecture can help centralize credential management.
However, the security of the complete setup still depends on:
- Identity and access management.
- Provider permissions.
- RBAC.
- Encryption at rest.
- Network security.
- Secret rotation.
- Audit logging.
No single tool automatically solves every security problem.
🧪 10. Your Kubernetes Security Challenge
Now let's test your understanding.
Create a Kubernetes namespace:
kubectl create namespace security-lab Create a test Secret:
kubectl create secret generic app-secret \ --from-literal=username=admin \ --from-literal=password=test-password \ -n security-lab Inspect it:
kubectl get secret app-secret -n security-lab Decode one value:
kubectl get secret app-secret \ -n security-lab \ -o jsonpath='{.data.password}' | base64 --decode Now answer these questions:
- Why is Base64 not sufficient protection?
- Can a Pod in another namespace directly reference this Secret?
- How can RBAC restrict access to Secrets?
- Why should you avoid committing Secret manifests containing real credentials?
- What is encryption at rest?
- How would you rotate an exposed database password?
Try answering without looking at documentation.
This is a useful way to test whether you understand Kubernetes security rather than just remembering YAML syntax.
🎯 Final Thoughts
Kubernetes makes deploying applications easier.
But deploying applications securely requires a different mindset.
A green deployment does not mean your application is secure.
A running Pod does not mean your credentials are protected.
And a Kubernetes Secret does not automatically mean your sensitive data is encrypted.
As a DevOps engineer, you should understand:
- Base64 encoding versus encryption.
- Kubernetes RBAC.
- Encryption at rest.
- Secret mounting and environment variables.
- Namespace isolation.
- Credential rotation.
- External secrets-management systems.
Security isn't something you add after deploying your application. It should be part of your deployment architecture from day one.
👇 Let's discuss!
Which Kubernetes security mistake do you think developers make most often?
- Committing Secrets to GitHub.
- Ignoring encryption at rest.
- Giving excessive RBAC permissions.
- Never rotating credentials.
- Assuming Base64 means encrypted.
Share your thoughts in the comments!
☸️ Preparing for the Certified Kubernetes Administrator (CKA) Exam?
Want to strengthen your Kubernetes fundamentals and prepare for your certification journey?
Check out my:
📘 CKA Complete Study Guide — Certified Kubernetes Administrator
A structured learning resource to help you build your Kubernetes knowledge and improve your exam preparation.
Understand Kubernetes. Practice consistently. Build real-world confidence.
