【发布时间】:2021-08-14 18:36:57
【问题描述】:
我正在 Kubernetes (GKE) 中运行 WebService 后端应用程序。它仅由我们的前端 Web 应用程序使用。通常有来自同一用户 (ClientIP) 的数十个请求序列。 我的应用设置为至少运行 2 个实例(“minReplicas: 2”)。
问题:
从日志中,我可以看到一个 pod 过载(接收许多请求)而另一个 pod 空闲的情况。两个 pod 都处于 Ready 状态。
我尝试修复它: 我尝试添加一个自定义的 Readiness 健康检查,当打开的连接太多时返回“不健康”状态。 但即使在健康检查返回“不健康”之后,负载均衡器也会在第二个(健康的)pod 空闲时向同一个 pod 发送更多请求。
以下是 service.yaml 的摘录:
kind: Service
metadata:
annotations:
networking.gke.io/load-balancer-type: "Internal"
spec:
type: LoadBalancer
ports:
- protocol: TCP
port: 80
targetPort: 8080
sessionAffinity 未指定,所以我希望它是“无”
我的问题: 我究竟做错了什么? Readiness 运行状况检查对负载均衡器有什么影响吗? 如何控制请求分发?
其他信息:
集群创建:
gcloud container --project %PROJECT% clusters create %CLUSTER%
--zone "us-east1-b" --release-channel "stable" --machine-type "n1-standard-2"
--disk-type "pd-ssd" --disk-size "20" --metadata disable-legacy-endpoints=true
--scopes "storage-rw" --num-nodes "1" --enable-stackdriver-kubernetes
--enable-ip-alias --network "xxx" --subnetwork "xxx"
--cluster-secondary-range-name "xxx" --services-secondary-range-name "xxx"
--no-enable-master-authorized-networks
节点池:
gcloud container node-pools create XXX --project %PROJECT% --zone="us-east1-b"
--cluster=%CLUSTER% --machine-type=c2-standard-4 --max-pods-per-node=16
--num-nodes=1 --disk-type="pd-ssd" --disk-size="10" --scopes="storage-full"
--enable-autoscaling --min-nodes=1 --max-nodes=30
服务:
apiVersion: v1
kind: Service
metadata:
name: XXX
annotations:
networking.gke.io/load-balancer-type: "Internal"
labels:
app: XXX
version: v0.1
spec:
selector:
app: XXX
version: v0.1
type: LoadBalancer
ports:
- protocol: TCP
port: 80
targetPort: 8080
HPA:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: XXX
spec:
scaleTargetRef:
apiVersion: "apps/v1"
kind: Deployment
name: XXX
minReplicas: 2
maxReplicas: 30
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 40
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 70
部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: XXX
labels:
app: XXX
version: v0.1
spec:
replicas: 1
selector:
matchLabels:
app: XXX
version: v0.1
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: XXX
version: v0.1
spec:
containers:
- image: XXX
name: XXX
imagePullPolicy: Always
resources:
requests:
memory: "10Gi"
cpu: "3200m"
limits:
memory: "10Gi"
cpu: "3600m"
readinessProbe:
httpGet:
path: /health/ready
port: 8080
initialDelaySeconds: 3
periodSeconds: 8
failureThreshold: 3
livenessProbe:
httpGet:
path: /health/live
port: 8080
initialDelaySeconds: 120
periodSeconds: 30
nodeSelector:
cloud.google.com/gke-nodepool: XXX
【问题讨论】:
-
您好,请使用以下信息更新您的问题。您能否详细介绍一下您的设置以及您的应用程序是如何工作的?您的所有应用程序
Pods是否也处于Ready状态?他们出现在$ kubectl get endpoints中吗?当您声明您只运行 2 个副本时,自动缩放如何在您的设置中发挥作用? -
大卫,我已经改写了我的问题。通常,两个 pod 都处于
Ready状态并出现在kubectl get endpoints中。我认为问题不在于自动缩放。我提到它只是为了说至少有 2 个 pod 一直在运行。问题在于请求分布不均。谢谢 -
为了进一步解决此问题并找出根本原因,请您提供minimal, reproducible example。集群信息、映像(如果可行)、部署清单和您已采取的步骤。
-
大卫,我添加了一些额外的信息。 HTH。我无法分享图片,我认为没有必要。
-
我已经复制了您的设置,但无法复制您遇到的问题。请求被平均分配。至于我使用普通
nginx的图像,所有测试都显示使用/平衡约为50%(来自容器的日志,它们的cpu使用情况)。您能否检查一下您的设置中的nginx图像是否发生同样的情况?
标签: google-cloud-platform google-kubernetes-engine load-balancing kubernetes-health-check