From 9ea3da3bc5aae898f5e42095e02e7cfe312abe3b Mon Sep 17 00:00:00 2001 From: AdamDang Date: Wed, 26 Dec 2018 21:09:59 +0800 Subject: [PATCH] zh-trans: add /docs/tasks/configure-pod-container/configure-pod-initialization.md (#11886) zh-trans: add /docs/tasks/configure-pod-container/configure-pod-initialization.md --- .../configure-pod-initialization.md | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 content/zh/docs/tasks/configure-pod-container/configure-pod-initialization.md diff --git a/content/zh/docs/tasks/configure-pod-container/configure-pod-initialization.md b/content/zh/docs/tasks/configure-pod-container/configure-pod-initialization.md new file mode 100644 index 0000000000..c9c875c476 --- /dev/null +++ b/content/zh/docs/tasks/configure-pod-container/configure-pod-initialization.md @@ -0,0 +1,151 @@ +--- +title: 配置 Pod 初始化 +content_template: templates/task +weight: 130 +--- + + + +{{% capture overview %}} + +本文介绍在应用容器运行前,怎样利用 Init 容器初始化 Pod。 +{{% /capture %}} + +{{% capture prerequisites %}} + +{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}} + +{{% /capture %}} + +{{% capture steps %}} + + + +## 创建一个包含 Init 容器的 Pod + +本例中您将创建一个包含一个应用容器和一个 Init 容器的 Pod。Init 容器在应用容器启动前运行完成。 + +下面是 Pod 的配置文件: + +{{< codenew file="pods/init-containers.yaml" >}} + + + +配置文件中,您可以看到应用容器和 Init 容器共享了一个卷。 + +Init 容器将共享卷挂载到了 `/work-dir` 目录,应用容器将共享卷挂载到了 `/usr/share/nginx/html` 目录。 +Init 容器执行完下面的命令就终止: + + wget -O /work-dir/index.html http://kubernetes.io + + + +请注意 Init 容器在 nginx 服务器的根目录写入 `index.html`。 + +创建 Pod: + + kubectl create -f https://k8s.io/examples/pods/init-containers.yaml + + + +检查 nginx 容器运行正常: + + kubectl get pod init-demo + + + +结果表明 nginx 容器运行正常: + + NAME READY STATUS RESTARTS AGE + init-demo 1/1 Running 0 1m + + + +通过 shell 进入 init-demo Pod 中的 nginx 容器: + + kubectl exec -it init-demo -- /bin/bash + + + +在 shell 中,发送个 GET 请求到 nginx 服务器: + + root@nginx:~# apt-get update + root@nginx:~# apt-get install curl + root@nginx:~# curl localhost + + + +结果表明 nginx 正在为 Init 容器编写的 web 页面服务: + + + + + + ... + "url": "http://kubernetes.io/"} + + + ... +

Kubernetes is open source giving you the freedom to take advantage ...

+ ... + +{{% /capture %}} + +{{% capture whatsnext %}} + + + +* 进一步了解 [相同 Pod 中的容器间的通信](/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/)。 +* 进一步了解 [Init 容器](/docs/concepts/workloads/pods/init-containers/)。 +* 进一步了解 [卷](/docs/concepts/storage/volumes/)。 +* 进一步了解 [Init 容器排错](/docs/tasks/debug-application-cluster/debug-init-containers/)。 + +{{% /capture %}} + +