Fixed formatting for markdown file (#12192)
* Fixed formatting for markdown file File updated: define-environment-variable-container.md Language: zh * Fixes to markdown formattingpull/12197/head
parent
3466056184
commit
5c56b43456
|
@ -30,32 +30,44 @@ content_template: templates/task
|
|||
|
||||
1. 基于YAML文件创建一个Pod:
|
||||
|
||||
kubectl create -f https://k8s.io/docs/tasks/inject-data-application/envars.yaml
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/inject-data-application/envars.yaml
|
||||
```
|
||||
|
||||
1. 获取一下当前正在运行的Pods信息:
|
||||
|
||||
kubectl get pods -l purpose=demonstrate-envars
|
||||
```shell
|
||||
kubectl get pods -l purpose=demonstrate-envars
|
||||
```
|
||||
|
||||
查询结果应为:
|
||||
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
envar-demo 1/1 Running 0 9s
|
||||
```log
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
envar-demo 1/1 Running 0 9s
|
||||
```
|
||||
|
||||
1. 进入该Pod下的容器并打开一个命令终端:
|
||||
|
||||
kubectl exec -it envar-demo -- /bin/bash
|
||||
```shell
|
||||
kubectl exec -it envar-demo -- /bin/bash
|
||||
```
|
||||
|
||||
1. 在命令终端中通过执行`printenv`打印出环境变量。
|
||||
|
||||
root@envar-demo:/# printenv
|
||||
```shell
|
||||
root@envar-demo:/# printenv
|
||||
```
|
||||
|
||||
打印结果应为:
|
||||
|
||||
NODE_VERSION=4.4.2
|
||||
EXAMPLE_SERVICE_PORT_8080_TCP_ADDR=10.3.245.237
|
||||
HOSTNAME=envar-demo
|
||||
...
|
||||
DEMO_GREETING=Hello from the environment
|
||||
```log
|
||||
NODE_VERSION=4.4.2
|
||||
EXAMPLE_SERVICE_PORT_8080_TCP_ADDR=10.3.245.237
|
||||
HOSTNAME=envar-demo
|
||||
...
|
||||
DEMO_GREETING=Hello from the environment
|
||||
```
|
||||
|
||||
1. 通过键入`exit`退出命令终端。
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ content_template: templates/task
|
|||
`39528$vdg7Jb`。 首先使用 [Base64 编码](https://www.base64encode.org/) 将用户名和密码转化为 base-64 形式。 这里是一个 Linux 示例:
|
||||
|
||||
```shell
|
||||
echo -n 'my-app' | base64
|
||||
echo -n '39528$vdg7Jb' | base64
|
||||
echo -n 'my-app' | base64
|
||||
echo -n '39528$vdg7Jb' | base64
|
||||
```
|
||||
|
||||
结果显示 base-64 形式的用户名为 `bXktYXBw`,
|
||||
|
@ -66,17 +66,17 @@ base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`。
|
|||
输出:
|
||||
|
||||
```shell
|
||||
Name: test-secret
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: <none>
|
||||
Name: test-secret
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: <none>
|
||||
|
||||
Type: Opaque
|
||||
Type: Opaque
|
||||
|
||||
Data
|
||||
====
|
||||
password: 13 bytes
|
||||
username: 7 bytes
|
||||
Data
|
||||
====
|
||||
password: 13 bytes
|
||||
username: 7 bytes
|
||||
```
|
||||
|
||||
## 创建可以通过卷访问 secret 数据的 Pod
|
||||
|
@ -88,57 +88,57 @@ base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`。
|
|||
1. 创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f secret-pod.yaml
|
||||
kubectl create -f secret-pod.yaml
|
||||
```
|
||||
|
||||
1. 确认 Pod 正在运行:
|
||||
|
||||
```shell
|
||||
kubectl get pod secret-test-pod
|
||||
kubectl get pod secret-test-pod
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```shell
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
secret-test-pod 1/1 Running 0 42m
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
secret-test-pod 1/1 Running 0 42m
|
||||
```
|
||||
|
||||
1. 在 Pod 中运行的容器中获取一个 shell:
|
||||
|
||||
```shell
|
||||
kubectl exec -it secret-test-pod -- /bin/bash
|
||||
kubectl exec -it secret-test-pod -- /bin/bash
|
||||
```
|
||||
|
||||
1. secret 数据通过挂载在 `/etc/secret-volume` 目录下的卷暴露在容器中。
|
||||
在 shell 中,进入 secret 数据被暴露的目录:
|
||||
|
||||
```shell
|
||||
root@secret-test-pod:/# cd /etc/secret-volume
|
||||
root@secret-test-pod:/# cd /etc/secret-volume
|
||||
```
|
||||
1. 在 shell 中,列出 `/etc/secret-volume` 目录的文件:
|
||||
|
||||
```shell
|
||||
root@secret-test-pod:/etc/secret-volume# ls
|
||||
root@secret-test-pod:/etc/secret-volume# ls
|
||||
```
|
||||
|
||||
输出显示了两个文件,每个对应一条 secret 数据:
|
||||
|
||||
```shell
|
||||
password username
|
||||
password username
|
||||
```
|
||||
|
||||
1. 在 shell 中,显示 `username` 和 `password` 文件的内容:
|
||||
|
||||
```shell
|
||||
root@secret-test-pod:/etc/secret-volume# cat username; echo; cat password; echo
|
||||
root@secret-test-pod:/etc/secret-volume# cat username; echo; cat password; echo
|
||||
```
|
||||
|
||||
输出为用户名和密码:
|
||||
|
||||
```shell
|
||||
my-app
|
||||
39528$vdg7Jb
|
||||
my-app
|
||||
39528$vdg7Jb
|
||||
```
|
||||
|
||||
## 创建通过环境变量访问 secret 数据的 Pod
|
||||
|
@ -150,41 +150,41 @@ base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`。
|
|||
1. 创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/examples/pods/inject/secret-envars-pod.yaml
|
||||
kubectl create -f https://k8s.io/examples/pods/inject/secret-envars-pod.yaml
|
||||
```
|
||||
|
||||
1. 确认 Pod 正在运行:
|
||||
|
||||
```shell
|
||||
kubectl get pod secret-envars-test-pod
|
||||
kubectl get pod secret-envars-test-pod
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```shell
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
secret-envars-test-pod 1/1 Running 0 4m
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
secret-envars-test-pod 1/1 Running 0 4m
|
||||
```
|
||||
|
||||
1. 在 Pod 中运行的容器中获取一个 shell:
|
||||
|
||||
```shell
|
||||
kubectl exec -it secret-envars-test-pod -- /bin/bash
|
||||
kubectl exec -it secret-envars-test-pod -- /bin/bash
|
||||
```
|
||||
|
||||
1. 在 shell 中,显示环境变量:
|
||||
|
||||
```shell
|
||||
root@secret-envars-test-pod:/# printenv
|
||||
root@secret-envars-test-pod:/# printenv
|
||||
```
|
||||
|
||||
输出包括用户名和密码:
|
||||
|
||||
```shell
|
||||
...
|
||||
SECRET_USERNAME=my-app
|
||||
...
|
||||
SECRET_PASSWORD=39528$vdg7Jb
|
||||
...
|
||||
SECRET_USERNAME=my-app
|
||||
...
|
||||
SECRET_PASSWORD=39528$vdg7Jb
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
@ -201,5 +201,3 @@ base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`。
|
|||
* [Pod](/docs/api-reference/{{< param "version" >}}/#pod-v1-core)
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue