kubernetes 负载均衡器 IP

问题描述 投票:0回答:1

我在树莓派上有一个复制了 5 次 kubernetes 集群的 pod:

$ sudo kubectl get pods -o wide
NAME                         READY   STATUS    RESTARTS   AGE   IP            NODE          NOMINATED NODE   READINESS GATES
dhscanner-7f57688986-4rgq2   1/1     Running   0          62m   10.42.3.25    oren6         <none>           <none>
dhscanner-7f57688986-2d7q8   1/1     Running   0          62m   10.42.3.24    oren6         <none>           <none>
dhscanner-7f57688986-9sb7j   1/1     Running   0          62m   10.42.2.30    oren2         <none>           <none>
dhscanner-7f57688986-ps9l6   1/1     Running   0          62m   10.42.5.21    oren7         <none>           <none>
dhscanner-7f57688986-w9tkl   1/1     Running   0          62m   10.42.0.132   raspberrypi   <none>           <none>

我的所有日志都很好:

$ sudo kubectl logs -l app=dhscanner
10.42.3.0 - - [09/Oct/2024:13:08:46 +0000] "POST /from/php/to/dhscanner/ast HTTP/1.1" 200 174 "" "Python/3.12 aiohttp/3.10.9"
10.42.3.0 - - [09/Oct/2024:13:08:46 +0000] "POST /from/js/to/dhscanner/ast HTTP/1.1" 200 172 "" "Python/3.12 aiohttp/3.10.9"
10.42.3.0 - - [09/Oct/2024:13:08:52 +0000] "POST /from/php/to/dhscanner/ast HTTP/1.1" 200 173 "" "Python/3.12 aiohttp/3.10.9"
10.42.3.1 - - [09/Oct/2024:13:08:32 +0000] "POST /from/php/to/dhscanner/ast HTTP/1.1" 200 177 "" "Python/3.12 aiohttp/3.10.9"
10.42.3.1 - - [09/Oct/2024:13:08:32 +0000] "POST /from/php/to/dhscanner/ast HTTP/1.1" 200 180 "" "Python/3.12 aiohttp/3.10.9"

当我查看集群和节点端口时,我看到不同 IP:

$ sudo kubectl get services
NAME               TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes         ClusterIP   10.43.0.1      <none>        443/TCP          301d
parsers-nodeport   NodePort    10.43.84.166   <none>        3000:31111/TCP   2d6h

那么

10.42.3.0
10.42.3.1
是从哪里来的?!


我认为确切的 kubernetes 脚本无关紧要, 但为了完整起见,这是我的部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: dhscanner
spec:
  replicas: 5
  selector:
    matchLabels:
      app: dhscanner
  template:
    metadata:
      labels:
        app: dhscanner
    spec:
      containers:
      - name: parsers
        image: orenishdocker/dhscanner-parsers:aarch64
        ports:
        - containerPort: 3000

和我的节点端口服务脚本:

apiVersion: v1
kind: Service
metadata:
  name: parsers-nodeport
spec:
  type: NodePort
  selector:
    app: dhscanner
  ports:
    - protocol: TCP
      port: 3000
      nodePort: 31111
kubernetes load-balancing ip-address
1个回答
0
投票

10.42.3.x 是 pod ip,10.43.0.x 是服务 ip。 Kubernetes 根据定义的 CIDR 分配 podip/serviceip

用于获取服务IP范围

kubectl cluster-info dump | grep -m 1 service-cluster-ip-range

用于获取 pod ip 范围

kubectl cluster-info dump | grep -m 1 pod
© www.soinside.com 2019 - 2024. All rights reserved.