ZH-trans: Update content/en/docs/tasks/inject-data-application/... (#11860)

* ZH-trans: Update content/en/docs/tasks/inject-data-application/...

ZH-trans: Update content/en/docs/tasks/inject-data-application/...

* Update define-command-argument-container.md

* Update distribute-credentials-secure.md
This commit is contained in:
lIuDuI 2018-12-24 21:11:47 +08:00 committed by Kubernetes Prow Robot
parent a33ae0f00c
commit 2448c0152c
3 changed files with 95 additions and 31 deletions

View File

@ -34,34 +34,48 @@ content_template: templates/task
{{< code file="commands.yaml" >}}
1. 基于YAML文件创建一个Pod
```shell
kubectl create -f https://k8s.io/docs/tasks/inject-data-application/commands.yaml
```
<!--
2. List the running Pods:
-->
kubectl create -f https://k8s.io/docs/tasks/inject-data-application/commands.yaml
1. 获取一下当前正在运行的Pods信息
kubectl get pods
获取正在运行的 pod
```shell
kubectl get pods
```
查询结果显示在command-demo这个Pod下运行的容器已经启动完成
1. 如果要获取容器启动时执行命令的输出结果可以通过Pod的日志进行查看
3. 如果要获取容器启动时执行命令的输出结果可以通过Pod的日志进行查看
kubectl logs command-demo
```shell
kubectl logs command-demo
```
日志中显示了HOSTNAME 与KUBERNETES_PORT 这两个环境变量的值:
command-demo
tcp://10.3.240.1:443
```shell
command-demo
tcp://10.3.240.1:443
```
## 使用环境变量来设置入参
在上面的示例中,我们直接将一串字符作为命令的入参。除此之外,我们还可以
将环境变量作为命令的入参。
```shell
env:
- name: MESSAGE
value: "hello world"
command: ["/bin/echo"]
args: ["$(MESSAGE)"]
```
这样一来,我们就可以将那些用来设置环境变量的方法应用于设置命令的入参,其
中包括了[ConfigMaps](/docs/tasks/configure-pod-container/configure-pod-configmap/)
@ -78,8 +92,10 @@ content_template: templates/task
有时候需要通过shell来执行命令。 例如,命令可能由多个命令组合而成,抑或包含
在一个shell脚本中。这时就可以通过如下方式在shell中执行命令
```shell
command: ["/bin/sh"]
args: ["-c", "while true; do echo hello; sleep 10;done"]
```
## 注意

View File

@ -20,8 +20,10 @@ content_template: templates/task
假设用户想要有两条 secret 数据:用户名 `my-app` 和密码
`39528$vdg7Jb`。 首先使用 [Base64 编码](https://www.base64encode.org/) 将用户名和密码转化为 base-64 形式。 这里是一个 Linux 示例:
echo -n 'my-app' | base64
echo -n '39528$vdg7Jb' | base64
```shell
echo -n 'my-app' | base64
echo -n '39528$vdg7Jb' | base64
```
结果显示 base-64 形式的用户名为 `bXktYXBw`
base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`
@ -32,31 +34,41 @@ base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`。
{{< code file="secret.yaml" >}}
<!--
kubectl create -f https://k8s.io/docs/tasks/inject-data-application/secret.yaml
-->
1. 创建 Secret
kubectl create -f secret.yaml
```shell
kubectl create -f https://k8s.io/docs/tasks/inject-data-application/secret.yaml
```
{{< note >}}
**注意:** 如果想要跳过 Base64 编码的步骤,可以使用 `kubectl create secret` 命令来创建 Secret
{{< /note >}}
```shell
kubectl create secret generic test-secret --from-literal=username='my-app' --from-literal=password='39528$vdg7Jb'
```
1. 查看 Secret 相关信息:
kubectl get secret test-secret
输出:
```shell
NAME TYPE DATA AGE
test-secret Opaque 2 1m
```
1. 查看 Secret 相关的更多详细信息:
3. 查看 Secret 相关的更多详细信息:
kubectl describe secret test-secret
输出:
```shell
Name: test-secret
Namespace: default
Labels: <none>
@ -67,7 +79,8 @@ base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`。
Data
====
password: 13 bytes
username: 7 bytes
username: 7 bytes
```
## 创建可以通过卷访问 secret 数据的 Pod
@ -77,43 +90,59 @@ base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`。
1. 创建 Pod
```shell
kubectl create -f secret-pod.yaml
```
1. 确认 Pod 正在运行:
```shell
kubectl get pod secret-test-pod
```
输出:
```shell
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
```
1. secret 数据通过挂载在 `/etc/secret-volume` 目录下的卷暴露在容器中。
在 shell 中,进入 secret 数据被暴露的目录:
```shell
root@secret-test-pod:/# cd /etc/secret-volume
```
1. 在 shell 中,列出 `/etc/secret-volume` 目录的文件:
```shell
root@secret-test-pod:/etc/secret-volume# ls
```
输出显示了两个文件,每个对应一条 secret 数据:
```shell
password username
```
1. 在 shell 中,显示 `username``password` 文件的内容:
```shell
root@secret-test-pod:/etc/secret-volume# cat username; echo; cat password; echo
```
输出为用户名和密码:
```shell
my-app
39528$vdg7Jb
```
## 创建通过环境变量访问 secret 数据的 Pod
@ -121,33 +150,49 @@ base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`。
{{< code file="secret-envars-pod.yaml" >}}
<!--
kubectl create -f https://k8s.io/docs/tasks/inject-data-application/secret-pod.yaml
-->
1. 创建 Pod
kubectl create -f secret-envars-pod.yaml
```shell
kubectl create -f https://k8s.io/docs/tasks/inject-data-application/secret-pod.yaml
```
1. 确认 Pod 正在运行:
```shell
kubectl get pod secret-envars-test-pod
```
输出:
```shell
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
```
1. 在 shell 中,显示环境变量:
```shell
root@secret-envars-test-pod:/# printenv
```
输出包括用户名和密码:
```shell
...
SECRET_USERNAME=my-app
...
SECRET_PASSWORD=39528$vdg7Jb
```
{{% /capture %}}

View File

@ -43,7 +43,7 @@ content_template: templates/task
**注意:** 本示例中的字段是Pod字段不是Pod中容器的字段。
{{< /note >}}
创建Pod
创建 Pod
```shell
kubectl create -f https://k8s.io/cn/docs/tasks/inject-data-application/dapi-volume.yaml
@ -61,7 +61,10 @@ kubectl get pods
kubectl logs kubernetes-downwardapi-volume-example
```
输出显示`labels`和`annotations`文件的内容:
<!--
The output shows the contents of the labels file and the annotations file:
-->
输出显示 `labels``annotations` 文件的内容:
```shell
cluster="test-cluster1"