/data/visits.txtCONFIGMAPGREETING=HelloCLAIM 1Gi RWOSECRETczNjcjN0PODweb-1VOLUME1Gi1import os, time2greeting = os.environ["GREETING"]3password = open("/etc/db/password").read()4with open("/data/visits.txt", "a") as f:5 f.write(greeting + "\n")6while True: time.sleep(3600)LINE 1LINE 2LINE 3
Blocks: the Pod, a ConfigMap, a Secret, a claim and a volumeFront: the Python app, and the lines of the file on the volumeTokens: the setting, the password, the claim and a written lineA Pod running one unchanged image reads a setting from a ConfigMap as an environment variable, a password from a Secret as a file, and writes to a PersistentVolume it reaches through a claim. When the Pod is replaced the file on the volume survives; when the ConfigMap changes, the new value arrives only after a restart. Pods made by a Deployment get generated names such as web-7c9d8f6b5-x2x7q. The figure calls them web-1, web-2 and web-3 to keep them readable. Strictly, the Deployment manages a ReplicaSet, and it is the ReplicaSet that starts a replacement Pod.

The idea

  1. Build one container image and run it everywhere. What differs between test and production, the settings, the passwords and the saved data, lives outside the image, in Kubernetes objects that the Pod plugs into.

Settings: ConfigMap

Passwords: Secret

Data that lasts

Changing a setting

What happens

;; step 1/10 · outside
one image, everywhere

settings        → ConfigMap
passwords, keys → Secret
data that lasts → PersistentVolume
                  (through a claim)

Secrets are only safer than ConfigMaps if you set them up that way: turn on encryption at rest for etcd and limit with RBAC who can read Secrets. Anyone who can create a Pod in a namespace can read the Secrets in it. Pods made by a Deployment get generated names such as web-7c9d8f6b5-x2x7q. The figure calls them web-1, web-2 and web-3 to keep them readable. Strictly, the Deployment manages a ReplicaSet, and it is the ReplicaSet that starts a replacement Pod.