Files
website/docs/tasks/inject-data-application/define-environment-variable-container.md
T
Andrew Chen 2e257d9707 Changes for move to Netlify (#4464)
* disable jekyll-redirect-from gem

* add _redirects file

* disable 404 redirect script

* add 301 redirect to test

* retain _redirects file

* Convert redirect_from's to _redirect file. (#4409)

* Remove redirect_from's. (#4424)

* Add 301's to _redirects. (#4427)

* add whitespace before 301

* move redirects in /js/redirects/js to _redirects

* add disabled option for cn redirect

* convert include to array in _config.yml

* enable redirects.js script for legacy support
2017-07-28 08:23:11 -07:00

2.1 KiB

title
title
Define Environment Variables for a Container

{% capture overview %}

This page shows how to define environment variables when you run a container in a Kubernetes Pod.

{% endcapture %}

{% capture prerequisites %}

{% include task-tutorial-prereqs.md %}

{% endcapture %}

{% capture steps %}

Define an environment variable for a container

When you create a Pod, you can set environment variables for the containers that run in the Pod. To set environment variables, include the env or envFrom field in the configuration file.

In this exercise, you create a Pod that runs one container. The configuration file for the Pod defines an environment variable with name DEMO_GREETING and value "Hello from the environment". Here is the configuration file for the Pod:

{% include code.html language="yaml" file="envars.yaml" ghlink="/docs/tasks/inject-data-application/envars.yaml" %}

  1. Create a Pod based on the YAML configuration file:

     kubectl create -f https://k8s.io/docs/tasks/inject-data-application/envars.yaml
    
  2. List the running Pods:

     kubectl get pods -l purpose=demonstrate-envars
    

    The output is similar to this:

     NAME            READY     STATUS    RESTARTS   AGE
     envar-demo      1/1       Running   0          9s
    
  3. Get a shell to the container running in your Pod:

     kubectl exec -it envar-demo -- /bin/bash
    
  4. In your shell, run the printenv command to list the environment variables.

     root@envar-demo:/# printenv
    

    The output is similar to this:

     NODE_VERSION=4.4.2
     EXAMPLE_SERVICE_PORT_8080_TCP_ADDR=10.3.245.237
     HOSTNAME=envar-demo
     ...
     DEMO_GREETING=Hello from the environment
    
  5. To exit the shell, enter exit.

{% endcapture %}

{% capture whatsnext %}

{% endcapture %}

{% include templates/task.md %}