Kubernetes 请求不平衡

Kubernetes requests not balanced

我们的 kubernetes 集群的流量刚刚增加,我注意到在我们的 6 个应用程序 pods 中,其中 2 个似乎使用得不多。 kubectl top pods returns 以下

您可以看到 6 个 pods,其中 4 个使用了超过 50% 的 CPU(2 vCPU 节点),但其中两个不是'根本没有做太多事情。

我们的集群是在 AWS 上设置的,使用 ALB 入口控制器。负载平衡器配置为使用 Least outstanding requests 而不是 Round robin 以尝试平衡更多东西,但我们仍然看到这种不平衡。

有什么方法可以确定为什么会发生这种情况,或者这是否确实是一个问题?我希望这是正常行为而不是问题,但我宁愿调查它。

应用部署配置

这是主应用程序的配置pods。没什么特别的

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 连接进行负载平衡。
excellent article 对此进行了详细介绍。

您所服务的负载分布与案例完全一致。