我们的 kubernetes 集群的流量刚刚增加,我注意到在我们的 6 个应用程序 pod 中,其中 2 个似乎没有被经常使用。kubectl top pods
返回以下内容
您可以看到 6 个 pod 中,其中 4 个使用了超过 50% 的 CPU(2 个 vCPU 节点),但其中两个实际上根本没有做太多事情。
我们的集群使用 ALB 入口控制器在 AWS 上设置。负载均衡器配置为使用Least outstanding requests
而不是Round robin
试图进一步平衡,但我们仍然看到这种不平衡。
有什么方法可以确定为什么会发生这种情况,或者这确实是一个问题吗?我希望这是正常行为而不是问题,但我宁愿调查它。
应用程序部署配置
这是主要应用程序 Pod 的配置。真的没什么特别的
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "app.fullname" . }}
labels:
{{- include "app.labels" . | nindent 4 }}
app.kubernetes.io/component: web
spec:
replicas: {{ .Values.app.replicaCount }}
selector:
matchLabels:
app: {{ include "app.fullname" . }}-web
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/config_maps/app-env-vars.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 10 }}
{{- end }}
labels:
{{- include "app.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: web
app: {{ include "app.fullname" . }}-web
spec:
serviceAccountName: {{ .Values.serviceAccount.web }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- {{ include "app.fullname" . }}-web
topologyKey: failure-domain.beta.kubernetes.io/zone
containers:
- name: {{ .Values.image.name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- bundle
args: ["exec", "puma", "-p", "{{ .Values.app.containerPort }}"]
ports:
- name: http
containerPort: {{ .Values.app.containerPort }}
protocol: TCP
readinessProbe:
httpGet:
path: /healthcheck
port: {{ .Values.app.containerPort }}
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 5
resources:
{{- toYaml .Values.resources | nindent 12 }}
envFrom:
- configMapRef:
name: {{ include "app.fullname" . }}-cm-env-vars
- secretRef:
name: {{ include "app.fullname" . }}-secret-rails-master-key
- secretRef:
name: {{ include "app.fullname" . }}-secret-db-credentials
- secretRef:
name: {{ include "app.fullname" . }}-secret-db-url-app
- secretRef:
name: {{ include "app.fullname" . }}-secret-redis-credentials
这是 Kubernetes 的一个已知问题。
简而言之,Kubernetes 不会对长期 TCP 连接进行负载平衡。
This 优秀的文章 https://learnk8s.io/kubernetes-long-lived-connections详细介绍了它。
您所显示的负载分布与实际情况完全相符。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)