如何配置 pod 中断预算以耗尽 kubernetes 节点?

How to configure pod disruption budget to drain kubernetes node?

我想在 AKS 上配置集群自动缩放器。缩小时由于 PDB 而失败:

I1207 14:24:09.523313       1 cluster.go:95] Fast evaluation: node aks-nodepool1-32797235-0 cannot be removed: no enough pod disruption budget to move kube-system/metrics-server-5cbc77f79f-44f9w
I1207 14:24:09.523413       1 cluster.go:95] Fast evaluation: node aks-nodepool1-32797235-3 cannot be removed: non-daemonset, non-mirrored, non-pdb-assignedkube-system pod present: cluster-autoscaler-84984799fd-22j42
I1207 14:24:09.523438       1 scale_down.go:490] 2 nodes found to be unremovable in simulation, will re-check them at 2018-12-07 14:29:09.231201368 +0000 UTC m=+8976.856144807

所有系统 pods 都手动分配了 minAvailable: 1 PDB。我可以想象这不适用于 PODs 只有一个副本,如 metrics-server:

❯ k get nodes -o wide
NAME                       STATUS   ROLES   AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
aks-nodepool1-32797235-0   Ready    agent   4h    v1.11.4   10.240.0.4    <none>        Ubuntu 16.04.5 LTS   4.15.0-1030-azure   docker://3.0.1
aks-nodepool1-32797235-3   Ready    agent   4h    v1.11.4   10.240.0.6    <none>        Ubuntu 16.04.5 LTS   4.15.0-1030-azure   docker://3.0.1

❯ ks get pods -o wide
NAME                                    READY   STATUS    RESTARTS   AGE   IP            NODE                       NOMINATED NODE
cluster-autoscaler-84984799fd-22j42     1/1     Running   0          2h    10.244.1.5    aks-nodepool1-32797235-3   <none>
heapster-5d6f9b846c-g7qb8               2/2     Running   0          1h    10.244.0.16   aks-nodepool1-32797235-0   <none>
kube-dns-v20-598f8b78ff-8pshc           4/4     Running   0          3h    10.244.1.4    aks-nodepool1-32797235-3   <none>
kube-dns-v20-598f8b78ff-plfv8           4/4     Running   0          1h    10.244.0.15   aks-nodepool1-32797235-0   <none>
kube-proxy-fjvjv                        1/1     Running   0          1h    10.240.0.6    aks-nodepool1-32797235-3   <none>
kube-proxy-szr8z                        1/1     Running   0          1h    10.240.0.4    aks-nodepool1-32797235-0   <none>
kube-svc-redirect-2rhvg                 2/2     Running   0          4h    10.240.0.4    aks-nodepool1-32797235-0   <none>
kube-svc-redirect-r2m4r                 2/2     Running   0          4h    10.240.0.6    aks-nodepool1-32797235-3   <none>
kubernetes-dashboard-68f468887f-c8p78   1/1     Running   0          4h    10.244.0.7    aks-nodepool1-32797235-0   <none>
metrics-server-5cbc77f79f-44f9w         1/1     Running   0          4h    10.244.0.3    aks-nodepool1-32797235-0   <none>
tiller-deploy-57f988f854-z9qln          1/1     Running   0          4h    10.244.0.8    aks-nodepool1-32797235-0   <none>
tunnelfront-7cf9d447f9-56g7k            1/1     Running   0          4h    10.244.0.2    aks-nodepool1-32797235-0   <none>

需要更改哪些内容(副本数?PDB 配置?)才能使缩减工作正常进行?

基本上,这是一个管理问题,当耗尽由 PDB (Pod Disruption Budget) 配置的节点时

这是因为强制驱逐必须遵守您指定的 PDB

你有两个选择:

要么逼手:

kubectl drain foo --force --grace-period=0

您可以从文档中查看其他选项 -> https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#drain

或者使用驱逐api:

{
  "apiVersion": "policy/v1beta1",
  "kind": "Eviction",
  "metadata": {
    "name": "quux",
    "namespace": "default"
  }
}

无论如何,耗尽或驱逐 api 尝试在 pod 上删除,以便在完全耗尽节点之前将它们安排在其他地方

如文档中所述:

API 可以通过以下三种方式之一进行响应:

  1. 如果驱逐被批准,那么 pod 将被删除,就像您向 pod 的 URL 发送了 DELETE 请求一样,您会返回 200 OK。
  2. 如果当前情况不允许按照预算中规定的规则进行驱逐,您将收到 429 太多请求。这通常用于任何请求的通用速率限制
  3. 如果存在某种配置错误,例如多个预算指向同一个 pod,您将收到 500 Internal Server Error。

对于给定的驱逐请求,有两种情况:

  1. 没有符合此广告连播的预算。在这种情况下,服务器总是 returns 200 OK.

  2. 至少有一项预算。在这种情况下,上述三个响应中的任何一个都可能适用。

如果卡住了,您可能需要手动操作

你可以读我here or here