gpt4 book ai didi

kubernetes - ClusterIP 服务是否在副本 Pod 之间分发请求?

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

你们知道吗ClusterIP服务在目标部署副本之间分配工作负载?

我有一个后端的 5 个副本,一个 ClusterIP 服务选择了它们。我还有另外 5 个 nginx pod 副本指向这个后端部署。但是当我运行一个繁重的请求时,后端停止响应其他请求,直到它完成繁重的请求。

更新

这是我的配置:

Note: I've replaced some info that are related to the company.



内容提供者部署:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: frontend
spec:
replicas: 3
template:
metadata:
labels:
app: webapp
tier: frontend
spec:
containers:
- name: python-gunicorn
image: <my-user>/webapp:1.1.2
command: ["/env/bin/gunicorn", "--bind", "0.0.0.0:8000", "main:app", "--chdir", "/deploy/app", "--error-logfile", "/var/log/gunicorn/error.log", "--timeout", "7200"]
resources:
requests:
# memory: "64Mi"
cpu: "0.25"
limits:
# memory: "128Mi"
cpu: "0.4"
ports:
- containerPort: 8000
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /login
port: 8000
initialDelaySeconds: 30
timeoutSeconds: 1200
imagePullSecrets:
# NOTE: the secret has to be created at the same namespace level on which this deployment was created
- name: dockerhub

内容提供者服务:
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
app: webapp
tier: frontend
spec:
# type: LoadBalancer
ports:
- port: 8000
targetPort: 8000
selector:
app: webapp
tier: frontend

Nginx 部署:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 5
template:
metadata:
labels:
app: nginx
spec:
volumes:
- name: secret-volume
secret:
secretName: nginxsecret
- name: configmap-volume
configMap:
name: nginxconfigmap
containers:
- name: nginxhttps
image: ymqytw/nginxhttps:1.5
command: ["/home/auto-reload-nginx.sh"]
ports:
- containerPort: 443
- containerPort: 80
livenessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 30
timeoutSeconds: 1200
resources:
requests:
# memory: "64Mi"
cpu: "0.1"
limits:
# memory: "128Mi"
cpu: "0.25"
volumeMounts:
- mountPath: /etc/nginx/ssl
name: secret-volume
- mountPath: /etc/nginx/conf.d
name: configmap-volume

Nginx 服务:
apiVersion: v1
kind: Service
metadata:
name: nginxsvc
labels:
app: nginxsvc
spec:
type: LoadBalancer
ports:
- port: 80
protocol: TCP
name: http
- port: 443
protocol: TCP
name: https
selector:
app: nginx

Nginx 配置文件:
server {
server_name local.mydomain.com;
rewrite ^(.*) https://local.mydomain.com$1 permanent;
}

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

listen 443 ssl;

root /usr/share/nginx/html;
index index.html;

keepalive_timeout 70;
server_name www.local.mydomain.com local.mydomain.com;
ssl_certificate /etc/nginx/ssl/tls.crt;
ssl_certificate_key /etc/nginx/ssl/tls.key;

location / {
proxy_pass http://localhost:8000;
proxy_connect_timeout 7200;
proxy_send_timeout 7200;
proxy_read_timeout 7200;
send_timeout 7200;
}
}

最佳答案

是的,服务类型 ClusterIP用途 kube-proxyiptables将请求大致均匀地分布在 round robin 中的规则方式。

documentation说:

By default, the choice of backend is round robin.



虽然, round robin请求的分发可能会受到以下因素的影响:
  • 繁忙的后端
  • 粘性 session
  • 基于连接(如果后端 pod 已与用户多次点击 ClusterIP 建立 TCP session 或安全隧道)
  • 自定义主机级/节点级 iptables kubernetes 之外的规则
  • 关于kubernetes - ClusterIP 服务是否在副本 Pod 之间分发请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48789227/

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