Search code examples
kuberneteskubernetes-secrets

Referencing secrets in Kubernetes


What is the difference between env and envFrom fields in kubernetes when referencing secrets? Thank you!


Solution

  • Below is the "env:" sample which will load variables into container environment as environment variables which can referenced using "$DEMO_GREETING" then you will get "Hello from the environment"

        env:
        - name: DEMO_GREETING
          value: "Hello from the environment"
        - name: DEMO_FAREWELL
          value: "Such a sweet sorrow"
    

    Similarly you can load secret as environment variable as below

      envFrom:
      - secretRef:
          name: mysecret
    

    Here the secret will be loaded as environment variable and this can be referenced as $mysecret inside the container.