ConfigMaps and Secrets
Settings are objects in the cluster, handed to pods
A ConfigMap and a Secret, passed in as variables or files.
An image should carry no settings, so they have to come from somewhere. In Kubernetes they are objects of their own. A config map holds ordinary settings as keys and values. A secret holds sensitive ones, such as a password. A pod can take them in two ways. As environment variables, set when the container starts. Or as files: the object is mounted as a directory, with one file for each key.
ConfigMaps and Secrets · Going deeper · 1 of 2
Lab: settings from a ConfigMap and a Secret
Create both, decode the Secret, then read the variables inside the pod.
When settings update · Going deeper · 2 of 2
Four ways in, and only one of them follows a change
Variables are fixed at start. A mounted volume is refreshed. A subPath file is not.
The pod manifest
A manifest names its settings; it does not contain them
envFrom a ConfigMap, a secretKeyRef, then requests and limits.
Here is how a pod asks for them. Read down the manifest. The image is the same one used everywhere. Env from takes every key in the config map and turns it into a variable. This variable is filled from one key of a secret. The password itself appears nowhere in the file, so the file can safely go into Git. Then the resources. Requests say what the container needs. Limits say what it must never exceed.
Secrets
A Secret is not secret by itself
base64 is not encryption. Access rules and encryption at rest are.
Look inside a secret and the value seems scrambled. It is not. It is base sixty four, a way of writing bytes as text, and one command turns it back. So anyone who is allowed to read the secret can read the password. The first real protection is deciding who that is. The second is asking the cluster to encrypt secrets where it stores them, which is not always on by default. And the third is keeping the true values in a dedicated secret manager, not in files in Git.
Secret types · Going deeper
A Secret has a type, and the type fixes the keys inside
Opaque for anything, tls for certificates, dockerconfigjson for registries.
Requests and limits
A request is a promise; a limit is a ceiling
Under the request: guaranteed. Over the limit: killed.
Two numbers govern how much a container may use. This one requests two hundred and fifty six mebibytes of memory, with a limit of five hundred and twelve. While it uses less than its request, that memory is always there for it. It may go above the request, as long as the node has room to spare. But if it passes the limit, the container is killed and restarted.
Namespace limits · Going deeper
A namespace can supply defaults and cap the total
A LimitRange fills in each container. A ResourceQuota caps the sum.
Quality of service
When a node runs out, the pods that promised least go first
BestEffort goes first, Burstable next, Guaranteed last.
Requests matter for one more reason. When a node runs short of memory, Kubernetes has to remove pods, and it chooses by class. A pod that set no requests at all is called best effort. It goes first. A pod that requests less than its limit is burstable, and goes next. A pod whose requests equal its limits is guaranteed. It is the last to be touched.
Lesson complete
You finished “Configuration and secrets”
Nicely done.