- Key-value pair format — directly in the Pod spec
- ConfigMap — stored as a Kubernetes API object
- Secrets — for confidential data, base64-encoded
Key-Value Pair Format
pod.yaml
ConfigMap
ConfigMap stores configuration data as a Kubernetes API object, similar in concept to key-value pairs but more reusable across pods.Creating a ConfigMap
- Imperative
- Declarative
<name>=<value>:.env
Using ConfigMap in a Pod
- Entire ConfigMap
- Single Value
- As Volume
Inject all ConfigMap values as environment variables. The
configMapRef.name must match the ConfigMap’s metadata.name.api-party.yaml
Secrets
Secrets store confidential information like passwords, keys, or tokens. How Kubernetes manages secrets:- A secret is only sent to a node if a pod requires it.
- The kubelet stores a copy of the secret in
tmpfs(RAM disk) — not written to disk storage. - The kubelet deletes its local copy when the pod that depends on the secret is deleted.
Built-in Secret Types
| Type | Usage |
|---|---|
Opaque | Arbitrary user-defined data |
kubernetes.io/service-account-token | ServiceAccount token |
kubernetes.io/dockerconfigjson | Serialized ~/.docker/config.json file |
kubernetes.io/basic-auth | Credentials for basic authentication |
kubernetes.io/ssh-auth | Credentials for SSH authentication |
kubernetes.io/tls | Data for a TLS client or server |
bootstrap.kubernetes.io/token | Bootstrap token data |
Creating Secrets
- Imperative
- Declarative (Opaque)
- TLS
- Basic Auth
- SSH Auth
When using imperative commands, you don’t need to encode your data — the command handles it.
Using Secrets in a Pod
- Entire Secret
- Single Value
- As Volume
api-party.yaml