Luk*_*kas 12 kubernetes google-kubernetes-engine
我最近注意到状态为“关闭”的 Pod 大量堆积。自 2020 年 10 月以来,我们一直在使用 Kubernetes。
生产和登台运行在相同的节点上,只是登台使用可抢占节点来降低成本。容器在暂存过程中也很稳定。(故障很少发生,因为它们是在之前的测试中发现的)。
服务提供商 Google Cloud Kubernetes。
我熟悉了这些文档并尝试搜索,但我都不认识谷歌对这种特殊状态的帮助。日志中没有错误。
我没有遇到 pod 被停止的问题。理想情况下,我希望 K8s 自动删除这些关闭 Pod。如果我跑kubectl delete po redis-7b86cdccf9-zl6k9,它就会眨眼间消失。
kubectl get pods | grep Shutdown | awk '{print $1}' | xargs kubectl delete pod是手动临时解决方法。
附言。k是我的环境中的别名kubectl。
我偶然发现了一些解释状态的相关问题 https://github.com/kubernetes/website/pull/28235 https://github.com/kubernetes/kubernetes/issues/102820
“当 Pod 在节点正常关闭期间被逐出时,它们会被标记为失败。运行时kubectl get pods会将被逐出的 Pod 的状态显示为Shutdown。”
被驱逐的 Pod 并不是故意删除的,正如 k8s 团队在此处所说的那样1,被驱逐的 Pod 也不是为了在驱逐后进行检查而被删除。
我相信最好的方法是创建一个 cronjob 2,正如已经提到的那样。
apiVersion: batch/v1
kind: CronJob
metadata:
name: del-shutdown-pods
spec:
schedule: "* 12 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- kubectl get pods | grep Shutdown | awk '{print $1}' | xargs kubectl delete pod
restartPolicy: OnFailure
Run Code Online (Sandbox Code Playgroud)
小智 8
您不需要任何grep - 只需使用 kubectl 提供的选择器。而且,顺便说一句,您无法从 busybox 映像调用 kubectl,因为它根本没有kubectl 。我还创建了一个具有 pod 删除权限的服务帐户。
apiVersion: batch/v1
kind: CronJob
metadata:
name: del-shutdown-pods
spec:
schedule: "0 */2 * * *"
concurrencyPolicy: Replace
jobTemplate:
metadata:
name: shutdown-deleter
spec:
template:
spec:
serviceAccountName: deleter
containers:
- name: shutdown-deleter
image: bitnami/kubectl
imagePullPolicy: IfNotPresent
command:
- "/bin/sh"
args:
- "-c"
- "kubectl delete pods --field-selector status.phase=Failed -A --ignore-not-found=true"
restartPolicy: Never
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9066 次 |
| 最近记录: |