gpt4 book ai didi

Kubernetes 水平 pod 自动扩缩器未根据副本计数创建副本

转载 作者:行者123 更新时间:2023-12-02 11:48:57 25 4
gpt4 key购买 nike

在这里,我试图通过 helm 图表在 kubernetes 自定义集群(通过 kubeadm 创建)中部署一个 dockerized Web 服务。因此,当它自动缩放时,它不会根据副本数创建副本。

这是我的部署文件。

apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: {{ template "demochart.fullname" . }}
labels:
app: {{ template "demochart.name" . }}
chart: {{ template "demochart.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "demochart.name" . }}
release: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ template "demochart.name" . }}
release: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
volumeMounts:
- name: cred-storage
mountPath: /root/
resources:
{{ toYaml .Values.resources | indent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
volumes:
- name: cred-storage
hostPath:
path: /home/aodev/
type:

这是 values.yaml
replicaCount: 3

image:
repository: REPO_NAME
tag: latest
pullPolicy: IfNotPresent

service:
type: NodePort
port: 8007

ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
path: /
hosts:
- chart-example.local
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
limits:
cpu: 1000m
memory: 2000Mi
requests:
cpu: 1000m
memory: 2000Mi

nodeSelector: {}

tolerations: []

affinity: {}

这是我正在运行的 pod,其中包括 heapster 和指标服务器以及我的 web 服务。

kubectl get pods before autoscaling

下面是hpa文件
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
annotations:
name: entitydetection
namespace: kube-system
spec:
maxReplicas: 20
minReplicas: 5
scaleTargetRef:
apiVersion: apps/v1beta2
kind: Deployment
name: entitydetection
targetCPUUtilizationPercentage: 50

所以我在部署中将副本数设为 3,将 minReplicas 设为 5,将 maxReplicas 设为 20,targetCPUUtilization 设为 hpa 中的 50%。因此,当 cpu 利用率超过 50% 时,它是随机创建副本而不是根据副本计数。

因此,当 CPU 超过 50% 时创建了 36 岁以下的 2 个副本。理想情况下应该创建 3 个副本。有什么问题?

kubectl get pods after autoscaling

最佳答案

这是来自 HPA 设计的引述 documentation :

The autoscaler is implemented as a control loop. It periodically queries pods described by Status.PodSelector of Scale subresource, and collects their CPU utilization.

Then, it compares the arithmetic mean of the pods' CPU utilization with the target defined in Spec.CPUUtilization, and adjusts the replicas of the Scale if needed to match the target (preserving condition: MinReplicas <= Replicas <= MaxReplicas).

CPU utilization is the recent CPU usage of a pod (average across the last 1 minute) divided by the CPU requested by the pod.

The target number of pods is calculated from the following formula:

TargetNumOfPods = ceil(sum(CurrentPodsCPUUtilization) / Target)    

Starting and stopping pods may introduce noise to the metric (for instance, starting may temporarily increase CPU). So, after each action, the autoscaler should wait some time for reliable data. Scale-up can only happen if there was no rescaling within the last 3 minutes. Scale-down will wait for 5 minutes from the last rescaling.


因此,HPA 生成的 pod 数量最少,可以解决当前负载。

关于Kubernetes 水平 pod 自动扩缩器未根据副本计数创建副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49941425/

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