In some applications, the application configurations are set by default in the codebase (hard-coded). If you want to override them, you can provide your override values through environment variables. Sometimes and for some configurations, it doesn’t matter if the override values exist. However, you want to make sure the application runs without any issues. If ConfigMaps/Secrets are available, use them and override default values, and if there are no ConfigMaps/Secrets for the application, run the application with its default configuration. In such a case, Kubernetes provides us optional field for using ConfigMaps/Secrets as environment variables in Pods.

Follow our social media:

If you run the pod with a regular manifest and the ConfigMap/Secret does not exist, it will face the following CreateContainerConfigError error.

apiVersion: v1
kind: Pod
  name: optional-configmap-secret
    - name: registry
      image: registry:latest
        - configMapRef:
            name: registry-config
        - secretRef:
            name: registry-secret

Now we can use the optional field to run the pod even if ConfigMap/Secret is not available to be used by the pod container without that error.

If you like this series of articles, please share them and write your thoughts as comments here. Your feedback encourages me to complete this massively planned program.

Follow my LinkedIn

Follow Kubedemy LinkedIn

Follow Kubedemy Telegram

Leave a Reply

Your email address will not be published. Required fields are marked *