Inferensys

Glossary

Secret

A Kubernetes Secret is an API object used to store and manage sensitive information—such as passwords, OAuth tokens, and SSH keys—separately from application code and container images.
Data engineer managing feature store on laptop, feature definitions visible, casual data engineering session.
AGENT DEPLOYMENT OBSERVABILITY

What is a Kubernetes Secret?

A Kubernetes Secret is a core API object designed to securely store and manage sensitive information, such as passwords, API tokens, and SSH keys, within a cluster.

A Kubernetes Secret is an API object that stores sensitive data like passwords, OAuth tokens, or SSH keys. Unlike a ConfigMap for plain configuration, a Secret's data is stored as base64-encoded key-value pairs, though this is not encryption. Secrets are mounted into pods as files or environment variables, allowing applications to access credentials without hardcoding them. Within Agent Deployment Observability, Secrets are critical for securely providing API keys to agents and external tools, enabling their monitored execution in production.

For observability and security, Secrets should be managed via a SealedSecret or external secret store (e.g., HashiCorp Vault) for encryption at rest. In an agentic system, the Tool Call Instrumentation pipeline must securely log that a tool was called using a credential, without exposing the secret value itself. Proper Secret management, combined with Resource Quotas and Pod Disruption Budgets, forms a foundational security and stability layer for deploying autonomous agents.

SECURITY & CONFIGURATION

Key Characteristics of Kubernetes Secrets

A Kubernetes Secret is an API object designed to store and manage sensitive information, such as passwords, API keys, and TLS certificates. Unlike ConfigMaps, Secrets are intended for confidential data and offer specific security and management features.

01

Base64 Encoding (Not Encryption)

A core characteristic is that data within a Secret is stored as base64-encoded strings. This is a fundamental point of confusion: base64 is an encoding scheme, not an encryption method. It prevents accidental exposure of binary data in YAML/JSON manifests but provides no cryptographic security.

  • Purpose: Allows storage of both plain text and binary data (like TLS certificates) in a text-based format.
  • Security Implication: The data is easily reversible. Anyone with kubectl get secret -o yaml permissions can decode the contents. Real security relies on other mechanisms like Role-Based Access Control (RBAC) and encryption at rest.
02

Mounting as Files or Environment Variables

Secrets are primarily consumed by pods in two ways, providing flexible integration with application code.

  • As Files: The most common and secure method. The Secret's key-value pairs are mounted into the container's filesystem as individual files. This allows applications to read secrets via standard file I/O operations. Updates to the Secret can be propagated to already-running pods.
  • As Environment Variables: Secret values can be injected directly into a container's environment. This is less secure as environment variables may be exposed in logs or via debugging tools, and updates are not reflected in running pods.

Example: A pod spec mounting a database password Secret as a file at /etc/db/password.

03

Types of Built-in Secrets

Kubernetes defines several Secret type fields, which define the intended use and structure of the secret data. The type is a hint to controllers and tooling.

Key built-in types include:

  • Opaque: The default type for arbitrary user-defined data (key-value pairs).
  • kubernetes.io/tls: For storing a TLS certificate and its private key. Keys must be named tls.crt and tls.key.
  • kubernetes.io/dockerconfigjson: For storing credentials to pull images from a private Docker registry.
  • kubernetes.io/service-account-token: Used by the ServiceAccount controller to store a token for API access.

Using the correct type enables integration with system components (e.g., the Ingress controller automatically uses tls type secrets).

04

Security Posture & Best Practices

Managing Secrets securely requires a defense-in-depth approach beyond the basic object.

  • Encryption at Rest: Enable and configure EncryptionConfiguration for the Kubernetes API server. This ensures Secret data is encrypted with a user-provided key before being written to etcd.
  • Least-Privilege RBAC: Restrict get, list, and watch permissions on Secrets using RBAC roles. Use namespaces to isolate secrets.
  • Avoid Environment Variables: Prefer file mounts for sensitive data to reduce exposure risk.
  • External Secret Managers: For high-security environments, integrate with external systems like HashiCorp Vault, AWS Secrets Manager, or Azure Key Vault using providers like the External Secrets Operator (ESO). These systems offer robust rotation, auditing, and fine-grained access policies.
05

Lifecycle & Immutability

Secrets have a defined lifecycle and can be made immutable for enhanced security.

  • Creation & Updates: Secrets are created via kubectl or API calls. They can be updated, and depending on how they are consumed, changes may propagate to pods.
  • Immutable Secrets: A Secret can be marked as immutable: true. This prevents any changes to its data, offering benefits:
    • Security: Accidental or malicious updates are blocked.
    • Performance: Reduces load on the kubectl-apiserver and etcd by disabling watches for that Secret.
  • Deletion: When a Secret is deleted, pods using it will continue to run but cannot restart if they depend on a mounted Secret that no longer exists.
06

Relation to ServiceAccounts

Kubernetes automatically creates and manages a special class of Secrets linked to ServiceAccounts.

  • Automated Creation: When a ServiceAccount is created, a controller automatically generates a Secret of type kubernetes.io/service-account-token. This Secret contains:
    • A namespace-scoped API token.
    • The cluster's CA certificate.
    • The namespace.
  • Pod Mounting: This Secret is automatically mounted at /var/run/secrets/kubernetes.io/serviceaccount in every pod, unless the pod spec explicitly disables it (automountServiceAccountToken: false).
  • Purpose: Provides the pod with a cryptographic identity to authenticate to the Kubernetes API server, enabling in-cluster communication and automation.
AGENT DEPLOYMENT OBSERVABILITY

How Kubernetes Secrets Work

A Kubernetes Secret is an API object for storing and managing sensitive data like passwords, tokens, or SSH keys, separate from application code or pod definitions.

A Kubernetes Secret is a built-in API object designed to hold confidential information such as passwords, OAuth tokens, or SSH keys. The data within a Secret is stored as base64-encoded key-value pairs and can be mounted into pods as data volumes or exposed as environment variables. This mechanism decouples sensitive configuration from container images and pod specifications, enhancing security and portability across different deployment environments like development, staging, and production.

From an agent deployment observability perspective, Secrets are critical for secure bootstrapping. An autonomous agent pod requires credentials to access external APIs, databases, or vector stores to perform its functions. By using Secrets, these credentials are injected at runtime, not baked into the image. This allows for centralized management, auditing, and rotation without requiring a redeployment of the agent, which is essential for maintaining deterministic execution and security posture during canary deployments or rolling updates in a production environment.

COMPARISON

Types of Kubernetes Secrets

A comparison of the primary built-in Secret types in Kubernetes, detailing their intended use cases, data format, and common management methods.

Secret TypePrimary Use CaseData Format & KeysCommon Creation Method

Opaque

Generic user-defined data (default type)

arbitrary key-value pairs

kubectl create secret generic

kubernetes.io/service-account-token

Service account authentication

Predefined keys: ca.crt, namespace, token

Automatically created by ServiceAccount controller

kubernetes.io/dockerconfigjson

Private container registry authentication

Single .dockerconfigjson key with JSON data

kubectl create secret docker-registry

kubernetes.io/tls

TLS certificates for Ingress or pods

Predefined keys: tls.crt, tls.key

kubectl create secret tls

kubernetes.io/basic-auth

Basic HTTP authentication credentials

Predefined keys: username, password

kubectl create secret generic (with specific keys)

kubernetes.io/ssh-auth

SSH private key authentication

Predefined key: ssh-privatekey

kubectl create secret generic (with specific key)

bootstrap.kubernetes.io/token

Node bootstrap token for joining a cluster

Predefined keys per token specification

kubeadm or manual creation

AGENT DEPLOYMENT OBSERVABILITY

Security Best Practices for Secrets

A Kubernetes Secret is a core object for storing sensitive data like passwords and API keys. Its security posture is critical for protecting agent deployments and the systems they interact with.

01

Encryption at Rest

By default, Kubernetes stores Secret data as base64-encoded plaintext in etcd. For production security, you must enable Encryption at Rest. This encrypts the Secret data with a configurable key (e.g., from a Key Management Service like AWS KMS, GCP Cloud KMS, or Azure Key Vault) before it is written to etcd. This protects against attackers who gain access to the underlying storage.

02

Principle of Least Privilege (RBAC)

Access to Secrets must be strictly controlled using Kubernetes Role-Based Access Control (RBAC). Best practices include:

  • Create fine-grained Roles and RoleBindings (namespace-scoped) or ClusterRoles and ClusterRoleBindings (cluster-scoped).
  • Grant get and list permissions on Secrets only to service accounts used by pods that legitimately need them.
  • Avoid granting create, update, or delete permissions broadly. Use dedicated service accounts for CI/CD systems that manage Secrets.
  • Regularly audit RBAC bindings to detect over-permissioned accounts.
03

Avoiding Environment Variable Injection

While convenient, mounting Secrets as environment variables poses risks:

  • Environment variables are visible to all processes in the container and may be logged inadvertently.
  • Child processes inherit environment variables.
  • Updates to the Secret are not reflected in already-running pods.

Preferred Method: Mount Secrets as volumes. This creates a file for each key, allowing the application to read the current value. Kubernetes automatically updates the mounted files when the Secret is updated, and the pod can detect the change (e.g., via inotify).

05

Regular Rotation and Short Lifespans

Secrets should have short lifespans and be rotated regularly to limit the blast radius of a compromise.

  • Implement automated rotation using your external secret manager or CI/CD pipelines.
  • Use init containers or sidecars to fetch fresh secrets at pod startup rather than relying on long-lived credentials baked into images.
  • For service accounts, use TokenRequest API to project short-lived, audience-bound tokens instead of relying on the default, long-lived service account token mounted in pods.
  • Monitor Secret age and alert on secrets older than a defined threshold (e.g., 90 days).
06

Static Analysis and Git Hygiene

Prevent secrets from being accidentally committed to version control, a common source of breaches.

  • Use .gitignore rigorously for files containing credentials.
  • Employ pre-commit hooks and secret scanning tools like GitGuardian, TruffleHog, or Gitleaks to detect and block commits containing high-entropy strings or patterns matching API keys, passwords, and tokens.
  • In CI/CD pipelines, scan build logs and artifacts for secret leakage.
  • Never use real secrets in development or test environments; instead, use dummy values or local secret management solutions.
KUBERNETES SECRETS

Frequently Asked Questions

A Kubernetes Secret is an object that stores sensitive data, such as passwords, API keys, and TLS certificates, in a base64-encoded format. It is a core component for managing confidential information in containerized applications and is essential for secure agent deployment observability.

A Kubernetes Secret is an API object used to store and manage sensitive information, such as passwords, OAuth tokens, SSH keys, and TLS certificates. It works by storing this data as base64-encoded key-value pairs within the cluster's etcd database. Pods can consume Secrets as environment variables, command-line arguments, or files mounted into the pod's filesystem via volumes. The primary mechanism is the kubectl create secret command or a declarative YAML manifest. For example, creating a generic secret from a file: kubectl create secret generic my-secret --from-file=./api-key.txt. This abstraction decouples sensitive configuration from application code and pod definitions, centralizing security management.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.