我在 GKE 中創建了帶有負載均衡器服務的 Nginx pod。當它收到來自外部用戶的請求時,在 Nginx 日志中它顯示請求是從內部 IP 接收的(這是隨機發生的)。
樣品請求
"@timestamp": "03/Sep/2022:16:25:38 0530", "@fields": { "remote_addr": "10.160.0.30", "remote_user": "-", "body_bytes_sent": "3767", "gzip_ratio": "3.52","request_time": "0.113", "connection_requests": "7","status": "200", "request": "GET /admin HTTP/2.0", "request_method": "GET"
YAML 檔案
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: image_name
ports:
- containerPort: 80
- containerPort: 443
resources:
requests:
cpu: 2000m
memory: 2Gi
limits:
cpu: 2000m
memory: 2Gi
==========
apiVersion: v1
kind: Service
metadata:
name: dev-nginx-lb-service
spec:
loadBalancerIP: IP_address
type: LoadBalancer
selector:
app: nginx
ports:
- name: https
protocol: TCP
port: 443
targetPort: 443
- name: http
protocol: TCP
port: 80
targetPort: 80
uj5u.com熱心網友回復:
不知道為什么會是隨機的。默認情況下,GKE 節點對通過負載均衡接收的資料包執行 SNAT。如果您想將客戶端地址直接傳遞給后端 pod,您可以externalTrafficPolicy: Local在您的服務規范中設定:
apiVersion: v1
kind: Service
metadata:
name: dev-nginx-lb-service
spec:
loadBalancerIP: IP_address
type: LoadBalancer
externalTrafficPolicy: Local
selector:
app: nginx
ports:
- name: https
protocol: TCP
port: 443
targetPort: 443
- name: http
protocol: TCP
port: 80
targetPort: 80
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/503818.html
標籤:Google Cloud Collective nginx Kubernetes 谷歌 Kubernetes 引擎
