From e6b2c53b52bcdc3983093def9f0acd930b37eb07 Mon Sep 17 00:00:00 2001 From: Qiming Teng Date: Sat, 25 Jun 2022 20:57:50 +0800 Subject: [PATCH] [zh-cn] Resync static-pod page --- .../configure-pod-container/static-pod.md | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/content/zh-cn/docs/tasks/configure-pod-container/static-pod.md b/content/zh-cn/docs/tasks/configure-pod-container/static-pod.md index aa2b7af0a0..5117f6f87a 100644 --- a/content/zh-cn/docs/tasks/configure-pod-container/static-pod.md +++ b/content/zh-cn/docs/tasks/configure-pod-container/static-pod.md @@ -12,13 +12,13 @@ without the {{< glossary_tooltip text="API server" term_id="kube-apiserver" >}} observing them. Unlike Pods that are managed by the control plane (for example, a {{< glossary_tooltip text="Deployment" term_id="deployment" >}}); -instead, the kubelet watches each static Pod (and restarts it if it crashes). +instead, the kubelet watches each static Pod (and restarts it if it fails). --> -*静态 Pod* 在指定的节点上由 kubelet 守护进程直接管理,不需要 +**静态 Pod** 在指定的节点上由 kubelet 守护进程直接管理,不需要 {{< glossary_tooltip text="API 服务器" term_id="kube-apiserver" >}} 监管。 与由控制面管理的 Pod(例如,{{< glossary_tooltip text="Deployment" term_id="deployment" >}}) -不同;kubelet 监视每个静态 Pod(在它崩溃之后重新启动)。 +不同;kubelet 监视每个静态 Pod(在它失败之后重新启动)。 -静态 Pod 永远都会绑定到一个指定节点上的 {{< glossary_tooltip term_id="kubelet" >}}。 +静态 Pod 始终都会绑定到特定节点的 {{< glossary_tooltip term_id="kubelet" >}} 上。 -kubelet 会尝试通过 Kubernetes API 服务器为每个静态 Pod 自动创建一个 -{{< glossary_tooltip text="镜像 Pod" term_id="mirror-pod" >}}。 +kubelet 会尝试通过 Kubernetes API 服务器为每个静态 Pod +自动创建一个{{< glossary_tooltip text="镜像 Pod" term_id="mirror-pod" >}}。 这意味着节点上运行的静态 Pod 对 API 服务来说是可见的,但是不能通过 API 服务器来控制。 Pod 名称将把以连字符开头的节点主机名作为后缀。 {{< note >}} + 如果你在运行一个 Kubernetes 集群,并且在每个节点上都运行一个静态 Pod, -就可能需要考虑使用 {{< glossary_tooltip text="DaemonSet" term_id="daemonset" >}} 替代这种方式。 +就可能需要考虑使用 {{< glossary_tooltip text="DaemonSet" term_id="daemonset" >}} +替代这种方式。 {{< /note >}} + +{{< note >}} - -{{< note >}} 静态 Pod 的 `spec` 不能引用其他 API 对象 (如:{{< glossary_tooltip text="ServiceAccount" term_id="service-account" >}}、 {{< glossary_tooltip text="ConfigMap" term_id="configmap" >}}、 @@ -85,7 +85,7 @@ You can configure a static Pod with either a [file system hosted configuration f ## 创建静态 Pod {#static-pod-creation} 可以通过[文件系统上的配置文件](/zh-cn/docs/tasks/configure-pod-container/static-pod/#configuration-files) -或者 [web 网络上的配置文件](/zh-cn/docs/tasks/configure-pod-container/static-pod/#pods-created-via-http) +或者 [Web 网络上的配置文件](/zh-cn/docs/tasks/configure-pod-container/static-pod/#pods-created-via-http) 来配置静态 Pod。 - 1. 选择一个要运行静态 Pod 的节点。在这个例子中选择 `my-node1`。 ```shell @@ -140,13 +139,13 @@ For example, this is how to start a simple web server as a static Pod: protocol: TCP EOF --> -2. 选择一个目录,比如在 `/etc/kubelet.d` 目录来保存 web 服务 Pod 的定义文件, - `/etc/kubelet.d/static-web.yaml`: +2. 选择一个目录,比如在 `/etc/kubernetes/manifests` 目录来保存 Web 服务 Pod 的定义文件,例如 + `/etc/kubernetes/manifests/static-web.yaml`: ```shell # 在 kubelet 运行的节点上执行以下命令 - mkdir /etc/kubelet.d/ - cat </etc/kubelet.d/static-web.yaml + mkdir -p /etc/kubernetes/manifests/ + cat </etc/kubernetes/manifests/static-web.yaml apiVersion: v1 kind: Pod metadata: @@ -165,20 +164,19 @@ For example, this is how to start a simple web server as a static Pod: ``` 3. 配置这个节点上的 kubelet,使用这个参数执行 `--pod-manifest-path=/etc/kubelet.d/`。 -在 Fedora 上编辑 `/etc/kubernetes/kubelet` 以包含下行: + 在 Fedora 上编辑 `/etc/kubernetes/kubelet` 以包含下面这行: ``` - KUBELET_ARGS="--cluster-dns=10.254.0.10 --cluster-domain=kube.local --pod-manifest-path=/etc/kubelet.d/" + KUBELET_ARGS="--cluster-dns=10.254.0.10 --cluster-domain=kube.local --pod-manifest-path=/etc/kubernetes/manifests/" ``` + + 或者在 [Kubelet 配置文件](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/) 中添加 `staticPodPath: <目录>`字段。 @@ -190,7 +188,7 @@ For example, this is how to start a simple web server as a static Pod: systemctl restart kubelet ``` --> -4. 重启 kubelet。Fedora 上使用下面的命令: +4. 重启 kubelet。在 Fedora 上,你将使用下面的命令: ```shell # 在 kubelet 运行的节点上执行以下命令 @@ -248,6 +246,7 @@ JSON/YAML 格式的 Pod 定义文件。 ``` KUBELET_ARGS="--cluster-dns=10.254.0.10 --cluster-domain=kube.local --manifest-url=" ``` + -3. 重启 kubelet。在 Fedora 上运行如下命令: +3. 重启 kubelet。在 Fedora 上,你将运行如下命令: ```shell # 在 kubelet 运行的节点上执行以下命令 @@ -278,7 +277,7 @@ crictl ps The output might be something like: --> -## 观察静态 pod 的行为 {#behavior-of-static-pods} +## 观察静态 Pod 的行为 {#behavior-of-static-pods} 当 kubelet 启动时,会自动启动所有定义的静态 Pod。 当定义了一个静态 Pod 并重新启动 kubelet 时,新的静态 Pod 就应该已经在运行了。 @@ -300,12 +299,12 @@ CONTAINER IMAGE CREATED STATE 129fd7d382018 docker.io/library/nginx@sha256:... 11 minutes ago Running web 0 34533c6729106 ``` +{{< note >}} -{{< note >}} -`crictl` 会输出镜像 URI 和 SHA-256 校验和。 `NAME` 看起来像: +`crictl` 会输出镜像 URI 和 SHA-256 校验和。`NAME` 看起来像: `docker.io/library/nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31`。 {{< /note >}} @@ -323,13 +322,14 @@ NAME READY STATUS RESTARTS AGE static-web 1/1 Running 0 2m ``` +{{< note >}} -{{< note >}} 要确保 kubelet 在 API 服务上有创建镜像 Pod 的权限。如果没有,创建请求会被 API 服务拒绝。 -可以看 [Pod 安全性准入](/zh-cn/docs/concepts/security/pod-security-admission/)和 [Pod 安全策略](/zh-cn/docs/concepts/security/pod-security-policy/)。 +参阅 [Pod 安全性准入](/zh-cn/docs/concepts/security/pod-security-admission/)和 +[Pod 安全策略](/zh-cn/docs/concepts/security/pod-security-policy/)。 {{< /note >}} -静态 Pod 上的{{< glossary_tooltip term_id="label" text="标签" >}} 被传到镜像 Pod。 -你可以通过 {{< glossary_tooltip term_id="selector" text="选择算符" >}} 使用这些标签。 +静态 Pod 上的{{< glossary_tooltip term_id="label" text="标签" >}}被传播到镜像 Pod。 +你可以通过{{< glossary_tooltip term_id="selector" text="选择算符" >}}使用这些标签。 -如果你用 `kubectl` 从 API 服务上删除镜像 Pod,kubelet _不会_ 移除静态 Pod: +如果你用 `kubectl` 从 API 服务上删除镜像 Pod,kubelet **不会**移除静态 Pod: ```shell kubectl delete pod static-web ``` + ``` pod "static-web" deleted ``` @@ -379,7 +380,7 @@ sleep 20 crictl ps ``` --> -回到 kubelet 运行的节点上,你可以手动停止容器。 +回到 kubelet 运行所在的节点上,你可以手动停止容器。 可以看到过了一段时间后 kubelet 会发现容器停止了并且会自动重启 Pod: ```shell @@ -398,8 +399,14 @@ CONTAINER IMAGE CREATED STATE +## 动态增加和删除静态 Pod +运行中的 kubelet 会定期扫描配置的目录(比如例子中的 `/etc/kubernetes/manifests` 目录)中的变化, +并且根据文件中出现/消失的 Pod 来添加/删除 Pod。 + + -## 动态增加和删除静态 pod - -运行中的 kubelet 会定期扫描配置的目录(比如例子中的 `/etc/kubelet.d` 目录)中的变化, -并且根据文件中出现/消失的 Pod 来添加/删除 Pod。 - ```shell -# 前提是你在用主机文件系统上的静态 Pod 配置文件 +# 这里假定你在用主机文件系统上的静态 Pod 配置文件 # 在 kubelet 运行的节点上执行以下命令 mv /etc/kubelet.d/static-web.yaml /tmp sleep 20 @@ -435,5 +437,3 @@ CONTAINER IMAGE CREATED STATE f427638871c35 docker.io/library/nginx@sha256:... 19 seconds ago Running web 1 34533c6729106 ``` - -