Kubernetes ConfigMap and Secrets

Sanket NankarSanket Nankar
3 min read

ConfigMaps

URL: https://kubernetes.io/docs/concepts/configuration/configmap/

  • A ConfigMap is an API object used to store non-confidential data in key-value pairs.

  • Pods can consume ConfigMaps as environment variables, command-line arguments or as configuration files in a volume.

  • A ConfigMap allows you to decouple environment-specific configuration from your container images, so that your applications are easily portable.

  • Caution:

    • ConfigMap does not provide secrecy or encryption.

    • If the data you want to store are confidential, use a Secret rather than a ConfigMap or use additional (third party) tools to keep your data private.

Here is a comprehensive list of commonly used Kubernetes commands related to ConfigMaps using kubectl:

โœ… Create ConfigMap

kubectl create configmap <configmap-name> --from-literal=key1=value1
kubectl create configmap <configmap-name> --from-file=path/to/config.file
kubectl create configmap <configmap-name> --from-env-file=env.file

๐Ÿ“– View ConfigMap

kubectl get configmap
kubectl get configmap <configmap-name> -o yaml

โœ๏ธ Edit ConfigMap

kubectl edit configmap <configmap-name>

๐Ÿ” Describe ConfigMap

kubectl describe configmap <configmap-name>

โŒ Delete ConfigMap

kubectl delete configmap <configmap-name>

Secrets

URL: https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#define-container-environment-variables-using-secret-data

Uses for Secrets

You can use Secrets for purposes such as the following:

โœ… Create Secret

From literal key-value pair:

kubectl create secret generic <secret-name> --from-literal=username=admin --from-literal=password=secret

From file:

kubectl create secret generic <secret-name> --from-file=path/to/secret.file

From env file:

kubectl create secret generic <secret-name> --from-env-file=secret.env

๐Ÿ“– View Secret (encoded)

kubectl get secret
kubectl get secret <secret-name> -o yaml

๐Ÿ”“ To decode a secret value:

echo <base64-encoded-string> | base64 --decode

โœ๏ธ Edit Secret

kubectl edit secret <secret-name>

๐Ÿ” Describe Secret

kubectl describe secret <secret-name>

โŒ Delete Secret

kubectl delete secret <secret-name>
0
Subscribe to my newsletter

Read articles from Sanket Nankar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sanket Nankar
Sanket Nankar