Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0bc2efe

Browse files
Merge pull request kubernetes#2204 from steveperry-53/env-yaml
Fix link.
2 parents e8a49bb + b6465d0 commit 0bc2efe

1 file changed

Lines changed: 94 additions & 90 deletions

File tree

  • docs/user-guide/environment-guide

docs/user-guide/environment-guide/index.md

Lines changed: 94 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,97 @@ assignees:
44
title: Using Environment Variables
55
---
66

7-
This example demonstrates running pods, replication controllers, and
8-
services. It shows two types of pods: frontend and backend, with
9-
services on top of both. Accessing the frontend pod will return
10-
environment information about itself, and a backend pod that it has
11-
accessed through the service. The goal is to illuminate the
12-
environment metadata available to running containers inside the
13-
Kubernetes cluster. The documentation for the Kubernetes environment
14-
is [here](/docs/user-guide/container-environment).
15-
16-
![Diagram](/images/docs/diagram.png)
17-
18-
## Prerequisites
19-
20-
This example assumes that you have a Kubernetes cluster installed and
21-
running, and that you have installed the `kubectl` command line tool
22-
somewhere in your path. Please see the [getting
23-
started](/docs/getting-started-guides/) for installation instructions
24-
for your platform.
25-
26-
## Optional: Build your own containers
27-
28-
The code for the containers is under
29-
[containers/](/docs/user-guide/containers/)
30-
31-
## Get everything running
32-
33-
```shell
34-
kubectl create -f ./backend-rc.yaml
35-
kubectl create -f ./backend-srv.yaml
36-
kubectl create -f ./show-rc.yaml
37-
kubectl create -f ./show-srv.yaml
38-
```
39-
40-
## Query the service
41-
42-
Use `kubectl describe service show-srv` to determine the public IP of
43-
your service.
44-
45-
> Note: If your platform does not support external load balancers,
46-
you'll need to open the proper port and direct traffic to the
47-
internal IP shown for the frontend service with the above command
48-
49-
Run `curl <public ip>:80` to query the service. You should get
50-
something like this back:
51-
52-
```shell
53-
Pod Name: show-rc-xxu6i
54-
Pod Namespace: default
55-
USER_VAR: important information
56-
57-
Kubernetes environment variables
58-
BACKEND_SRV_SERVICE_HOST = 10.147.252.185
59-
BACKEND_SRV_SERVICE_PORT = 5000
60-
KUBERNETES_RO_SERVICE_HOST = 10.147.240.1
61-
KUBERNETES_RO_SERVICE_PORT = 80
62-
KUBERNETES_SERVICE_HOST = 10.147.240.2
63-
KUBERNETES_SERVICE_PORT = 443
64-
KUBE_DNS_SERVICE_HOST = 10.147.240.10
65-
KUBE_DNS_SERVICE_PORT = 53
66-
67-
Found backend ip: 10.147.252.185 port: 5000
68-
Response from backend
69-
Backend Container
70-
Backend Pod Name: backend-rc-6qiya
71-
Backend Namespace: default
72-
```
73-
74-
First the frontend pod's information is printed. The pod name and
75-
[namespace](https://github.com/kubernetes/kubernetes/blob/{{page.githubbranch}}/docs/design/namespaces.md) are retrieved from the
76-
[Downward API](/docs/user-guide/downward-api). Next, `USER_VAR` is the name of
77-
an environment variable set in the [pod
78-
definition](/docs/user-guide/environment-guide/show-rc.yaml). Then, the dynamic Kubernetes environment
79-
variables are scanned and printed. These are used to find the backend
80-
service, named `backend-srv`. Finally, the frontend pod queries the
81-
backend service and prints the information returned. Again the backend
82-
pod returns its own pod name and namespace.
83-
84-
Try running the `curl` command a few times, and notice what
85-
changes. Ex: `watch -n 1 curl -s <ip>` Firstly, the frontend service
86-
is directing your request to different frontend pods each time. The
87-
frontend pods are always contacting the backend through the backend
88-
service. This results in a different backend pod servicing each
89-
request as well.
90-
91-
## Cleanup
92-
93-
```shell
94-
kubectl delete rc,service -l type=show-type
95-
kubectl delete rc,service -l type=backend-type
96-
```
7+
This example demonstrates running pods, replication controllers, and
8+
services. It shows two types of pods: frontend and backend, with
9+
services on top of both. Accessing the frontend pod will return
10+
environment information about itself, and a backend pod that it has
11+
accessed through the service. The goal is to illuminate the
12+
environment metadata available to running containers inside the
13+
Kubernetes cluster. The documentation for the Kubernetes environment
14+
is [here](/docs/user-guide/container-environment).
15+
16+
![Diagram](/images/docs/diagram.png)
17+
18+
## Prerequisites
19+
20+
This example assumes that you have a Kubernetes cluster installed and
21+
running, and that you have installed the `kubectl` command line tool
22+
somewhere in your path. Please see the [getting
23+
started](/docs/getting-started-guides/) for installation instructions
24+
for your platform.
25+
26+
## Optional: Build your own containers
27+
28+
These are the configuration files for the containers:
29+
30+
* [backend-rc.yaml](https://raw.githubusercontent.com/kubernetes/kubernetes.github.io/master/docs/user-guide/environment-guide/backend-rc.yaml)
31+
* [backend-srv.yaml](https://raw.githubusercontent.com/kubernetes/kubernetes.github.io/master/docs/user-guide/environment-guide/backend-srv.yaml)
32+
* [show-rc.yaml](https://raw.githubusercontent.com/kubernetes/kubernetes.github.io/master/docs/user-guide/environment-guide/show-rc.yaml)
33+
* [show-srv.yaml](https://raw.githubusercontent.com/kubernetes/kubernetes.github.io/master/docs/user-guide/environment-guide/show-srv.yaml)
34+
35+
## Get everything running
36+
37+
```shell
38+
kubectl create -f ./backend-rc.yaml
39+
kubectl create -f ./backend-srv.yaml
40+
kubectl create -f ./show-rc.yaml
41+
kubectl create -f ./show-srv.yaml
42+
```
43+
44+
## Query the service
45+
46+
Use `kubectl describe service show-srv` to determine the public IP of
47+
your service.
48+
49+
> Note: If your platform does not support external load balancers,
50+
you'll need to open the proper port and direct traffic to the
51+
internal IP shown for the frontend service with the above command
52+
53+
Run `curl <public ip>:80` to query the service. You should get
54+
something like this back:
55+
56+
```shell
57+
Pod Name: show-rc-xxu6i
58+
Pod Namespace: default
59+
USER_VAR: important information
60+
61+
Kubernetes environment variables
62+
BACKEND_SRV_SERVICE_HOST = 10.147.252.185
63+
BACKEND_SRV_SERVICE_PORT = 5000
64+
KUBERNETES_RO_SERVICE_HOST = 10.147.240.1
65+
KUBERNETES_RO_SERVICE_PORT = 80
66+
KUBERNETES_SERVICE_HOST = 10.147.240.2
67+
KUBERNETES_SERVICE_PORT = 443
68+
KUBE_DNS_SERVICE_HOST = 10.147.240.10
69+
KUBE_DNS_SERVICE_PORT = 53
70+
71+
Found backend ip: 10.147.252.185 port: 5000
72+
Response from backend
73+
Backend Container
74+
Backend Pod Name: backend-rc-6qiya
75+
Backend Namespace: default
76+
```
77+
78+
First the frontend pod's information is printed. The pod name and
79+
[namespace](https://github.com/kubernetes/kubernetes/blob/{{page.githubbranch}}/docs/design/namespaces.md) are retrieved from the
80+
[Downward API](/docs/user-guide/downward-api). Next, `USER_VAR` is the name of
81+
an environment variable set in the [pod
82+
definition](/docs/user-guide/environment-guide/show-rc.yaml). Then, the dynamic Kubernetes environment
83+
variables are scanned and printed. These are used to find the backend
84+
service, named `backend-srv`. Finally, the frontend pod queries the
85+
backend service and prints the information returned. Again the backend
86+
pod returns its own pod name and namespace.
87+
88+
Try running the `curl` command a few times, and notice what
89+
changes. Ex: `watch -n 1 curl -s <ip>` Firstly, the frontend service
90+
is directing your request to different frontend pods each time. The
91+
frontend pods are always contacting the backend through the backend
92+
service. This results in a different backend pod servicing each
93+
request as well.
94+
95+
## Cleanup
96+
97+
```shell
98+
kubectl delete rc,service -l type=show-type
99+
kubectl delete rc,service -l type=backend-type
100+
```

0 commit comments

Comments
 (0)