gpt4 book ai didi

kubernetes - Kubernetes HPA禁用缩小

转载 作者:行者123 更新时间:2023-12-02 11:51:50 27 4
gpt4 key购买 nike

根据我们产品的设计,我们想禁用HPA的按比例缩小功能,是否可以将其禁用?

最佳答案

不,这是不可能的。

1)您可以删除HPA并使用所需数量的Pod创建简单的部署

2)您可以使用用户'frankh'在HorizontalPodAutoscaler: Possible to limit scale down?#65097问题上提供的解决方法:

I've made a very hacky workaround, I have a cronjob that runs every 3 minutes, and sets the minimum replicas on an HPA to $currentReplicas - $downscaleLimit. If anyone feels like using it it's here: https://gist.github.com/frankh/050943c72273cf639886b43e98bc3caa


apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hpa-downscale-limiter
namespace: kube-system
spec:
schedule: "*/3 * * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
serviceAccountName: hpa-downscale-limiter
containers:
- name: kubectl
image: frankh/k8s-kubectl:1.10.3
command: ["/bin/bash", "-c"]
args:
- |
set -xeuo pipefail
namespaces=$(kubectl get hpa --no-headers --all-namespaces | cut -d' ' -f1 | uniq)
for namespace in $namespaces; do
hpas=$(kubectl get hpa --namespace=$namespace --no-headers | cut -d' ' -f1)
for hpa in $hpas; do
echo "$(kubectl get hpa --namespace=$namespace $hpa -o jsonpath="{.spec.minReplicas} {.status.desiredReplicas} {.metadata.annotations.originalMinimum} {.metadata.annotations.downscaleLimit}")" > tmpfile
read -r minReplicas desiredReplicas originalMinimum downscaleLimit < tmpfile

if [ -z "$originalMinimum" ]; then
kubectl annotate hpa --namespace=$namespace $hpa originalMinimum="$minReplicas"
originalMinimum=$minReplicas
fi

if [ -z "$downscaleLimit" ]; then
downscaleLimit=1
fi
target=$(( $desiredReplicas - $downscaleLimit ))
target=$(( $target > $originalMinimum ? $target : $originalMinimum ))

if [ "$minReplicas" -ne "$target" ]; then
kubectl patch hpa --namespace=$namespace $hpa --patch="{\"spec\": {\"minReplicas\": "$target"}}"
fi
done
done
restartPolicy: OnFailure
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: hpa-downscale-limiter
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: hpa-downscale-limiter-admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- name: hpa-downscale-limiter
kind: ServiceAccount
namespace: kube-system

关于kubernetes - Kubernetes HPA禁用缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60212727/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com