Secrets allows creating data objects that can be consumed by Pods at runtime.
The data in Secrets is stored as key-value entries:
-
Key: is a string value formed by alphanumeric, dot (.), dash (-), and underscore (_) characters.
-
Value: is a base64-encoded string value.
To encode a text into a base64 string:
The -n flag ensures that the generated output doesn't have an extra newline character at the end of the text.
This is to avoid that the extra newline character gets encoded along with the text.
To decode a base64 data:
The key and the value, in the Secrets, are separated with a colon (
key:value).
The name of the Secrets must be a valid DNS subdomain name.
The data stored in a Secrets can be consumed in a container in one the following ways:
-
Environment variables.
-
Command-line arguments of the container command.
-
Files in volumes.
-
Custom code (read the Secrets directly from the Kubernetes API).
Note:
If you update a Secrets that was already posted to the Kubernetes API server,
then containers that were already created will be able to leverage the new data only if it was injected as files in a volume.
Secrets data injected as environment variables won't be updated in a running container.