diff --git a/content/zh-cn/docs/concepts/scheduling-eviction/_index.md b/content/zh-cn/docs/concepts/scheduling-eviction/_index.md index f90a06410f870..10eb08aadb8b0 100644 --- a/content/zh-cn/docs/concepts/scheduling-eviction/_index.md +++ b/content/zh-cn/docs/concepts/scheduling-eviction/_index.md @@ -48,6 +48,8 @@ of terminating one or more Pods on Nodes. * [Scheduling Framework](/docs/concepts/scheduling-eviction/scheduling-framework) * [Scheduler Performance Tuning](/docs/concepts/scheduling-eviction/scheduler-perf-tuning/) * [Resource Bin Packing for Extended Resources](/docs/concepts/scheduling-eviction/resource-bin-packing/) +* [Pod Scheduling Readiness](/docs/concepts/scheduling-eviction/pod-scheduling-readiness/) +* [Pod 调度就绪状态](/zh-cn/docs/concepts/scheduling-eviction/pod-scheduling-readiness/) --> ## 调度 diff --git a/content/zh-cn/docs/concepts/scheduling-eviction/pod-scheduling-readiness.md b/content/zh-cn/docs/concepts/scheduling-eviction/pod-scheduling-readiness.md new file mode 100644 index 0000000000000..a593744660612 --- /dev/null +++ b/content/zh-cn/docs/concepts/scheduling-eviction/pod-scheduling-readiness.md @@ -0,0 +1,178 @@ +--- +title: Pod 调度就绪状态 +content_type: concept +weight: 40 +--- + + + + + +{{< feature-state for_k8s_version="v1.26" state="alpha" >}} + + +之前,Pod 一旦创建就被认为可以进行调度。Kubernetes调度器会尽职尽责地寻找节点来放置所有待定的Pod。 +然而,在现实场景中,一些 Pod 可能会长期处于“缺失必要资源”状态。 +这些 Pod 实际上在以不必要的方式搅动调度器(和下游集成商,如Cluster AutoScaler)。 + + +通过指定/删除一个 Pod 的 `.spec.schedulingGates` ,你可以控制一个 Pod 何时准备被进行调度。 + + + + +## 配置 Pod 的调度门控 + + + +`schedulingGates` 字段包含一个字符串列表,每个字符串都为 Pod 在可调度之前应该满足的准则。 +这个字段只能在 Pod 被创建时(由客户端创建,或在准入过程中突变)初始化。 +在创建之后,每个调度门控可以按任意顺序被删除,但不允许增加新的调度门控。 + +{{}} +stateDiagram-v2 +s1: pod 创建 +s2: pod 调度受阻 +s3: pod 调度就绪 +s4: pod 运行 +if: 空的调度门控? +state if <> +[*] --> s1 +s1 --> if +s2 --> if: 调度门控被移除 +if --> s2: 否 +if --> s3: 是 +s3 --> s4 +s4 --> [*] +{{< /mermaid >}} + + +## 使用示例 + + +要标记一个 Pod 未调度就绪,你可以像这样创建它,其中包含一个或多个调度门控: + +{{< codenew file="pods/pod-with-scheduling-gates.yaml" >}} + +创建 Pod 之后,你可以使用以下命令检查其状态: + +```bash +kubectl get pod test-pod +``` + + +输出显示它处于 `SchedulingGated` 状态: + +```none +NAME READY STATUS RESTARTS AGE +test-pod 0/1 SchedulingGated 0 7s +``` + + +你也可以通过运行以下命令检查其 `schedulingGates` 字段: + +```bash +kubectl get pod test-pod -o jsonpath='{.spec.schedulingGates}' +``` + + +输出: + +```none +[{"name":"foo"},{"name":"bar"}] +``` + + +要通知调度器这个 Pod 已经准备好进行调度,你可以通过重新应用修改过的清单来完全删除其 `schedulingGates` : + +{{< codenew file="pods/pod-without-scheduling-gates.yaml" >}} + +你可以通过运行以下命令检查 `schedulingGates` 是否已被清除: + +```bash +kubectl get pod test-pod -o jsonpath='{.spec.schedulingGates}' +``` + + +输出应该为空。你可以通过运行以下命令检查其最新状态: + +```bash +kubectl get pod test-pod -o wide +``` + + +考虑到 test-pod 没有请求任何 CPU/内存资源,预期这个 Pod 的状态从之前的 `SchedulingGated` 转换为 `Running` : + +```none +NAME READY STATUS RESTARTS AGE IP NODE +test-pod 1/1 Running 0 15s 10.0.0.4 node-2 +``` + + +## 可观测性 (Observability) + + +指标 `scheduler_pending_pods` 带有一个新的标签 `"gated"` , +用于区分 Pod 是否已经尝试调度但被声明为不可调度,或者是否被显式标记为未准备好调度。 +你可以使用 `scheduler_pending_pods{queue="gated"}` 来检查指标结果。 + +## {{% heading "whatsnext" %}} + + +* 阅读 [Pod 调度就绪状态 KEP](https://github.com/kubernetes/enhancements/blob/master/keps/sig-scheduling/3521-pod-scheduling-readiness) 以了解更多细节 \ No newline at end of file diff --git a/content/zh-cn/docs/reference/command-line-tools-reference/feature-gates.md b/content/zh-cn/docs/reference/command-line-tools-reference/feature-gates.md index 0476ef1efed2a..32b92de6685a3 100644 --- a/content/zh-cn/docs/reference/command-line-tools-reference/feature-gates.md +++ b/content/zh-cn/docs/reference/command-line-tools-reference/feature-gates.md @@ -211,6 +211,7 @@ For a reference to old feature gates that are removed, please refer to | `PodDeletionCost` | `true` | Beta | 1.22 | | | `PodDisruptionConditions` | `false` | Alpha | 1.25 | - | | `PodHasNetworkCondition` | `false` | Alpha | 1.25 | | +| `PodSchedulingReadiness` | `false` | Alpha | 1.26 | | | `ProbeTerminationGracePeriod` | `false` | Alpha | 1.21 | 1.21 | | `ProbeTerminationGracePeriod` | `false` | Beta | 1.22 | 1.24 | | `ProbeTerminationGracePeriod` | `true` | Beta | 1.25 | | diff --git a/content/zh-cn/examples/pods/pod-with-scheduling-gates.yaml b/content/zh-cn/examples/pods/pod-with-scheduling-gates.yaml new file mode 100644 index 0000000000000..0e4a642d6ba61 --- /dev/null +++ b/content/zh-cn/examples/pods/pod-with-scheduling-gates.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-pod +spec: + schedulingGates: + - name: foo + - name: bar + containers: + - name: pause + image: registry.k8s.io/pause:3.6 diff --git a/content/zh-cn/examples/pods/pod-without-scheduling-gates.yaml b/content/zh-cn/examples/pods/pod-without-scheduling-gates.yaml new file mode 100644 index 0000000000000..a6ef5ee6b055e --- /dev/null +++ b/content/zh-cn/examples/pods/pod-without-scheduling-gates.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-pod +spec: + containers: + - name: pause + image: registry.k8s.io/pause:3.6