部署nodePort+StatefulSet
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- port: 80
selector:
app: nginx
type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nginx
spec:
podManagementPolicy: Parallel
serviceName: nginx
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.9.1
启用iptables trace调试
iptables -t raw -A PREROUTING -p tcp -s 192.168.0.105 -d 192.168.0.104 --dport 31531 -j TRACE
iptables -t raw -A OUTPUT -p tcp -s 192.168.0.105 -d 192.168.0.104 --dport 31531 -j TRACE
Nov 11 11:57:16 slave kernel: TRACE: raw:PREROUTING:policy:2 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307)
Nov 11 11:57:16 slave kernel: TRACE: mangle:PREROUTING:policy:1 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307)
Nov 11 11:57:16 slave kernel: TRACE: nat:PREROUTING:rule:1 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307)
Nov 11 11:57:16 slave kernel: TRACE: nat:KUBE-SERVICES:rule:2 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307)
Nov 11 11:57:16 slave kernel: TRACE: nat:KUBE-NODE-PORT:rule:1 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307)
Nov 11 11:57:16 slave kernel: TRACE: nat:KUBE-MARK-MASQ:rule:1 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307)
Nov 11 11:57:16 slave kernel: TRACE: nat:KUBE-MARK-MASQ:return:2 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: nat:KUBE-NODE-PORT:return:2 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: nat:KUBE-SERVICES:return:4 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: nat:PREROUTING:rule:2 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: nat:DOCKER:return:2 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: nat:PREROUTING:policy:3 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: mangle:INPUT:policy:1 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:INPUT:rule:1 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:KUBE-SERVICES:return:1 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:INPUT:rule:2 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:KUBE-EXTERNAL-SERVICES:return:1 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:INPUT:rule:3 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:KUBE-FIREWALL:return:3 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:INPUT:policy:8 IN=ens33 OUT= MAC=00:0c:29:d0:ff:9b:00:0c:29:9e:20:65:08:00 SRC=192.168.0.105 DST=192.168.0.104 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=31531 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: raw:OUTPUT:policy:2 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: mangle:OUTPUT:policy:1 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:OUTPUT:rule:1 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:KUBE-SERVICES:return:1 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:OUTPUT:rule:2 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:KUBE-FIREWALL:return:3 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: filter:OUTPUT:policy:4 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: mangle:POSTROUTING:policy:2 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: nat:POSTROUTING:rule:1 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: nat:KUBE-POSTROUTING:rule:3 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307) MARK=0x4000
Nov 11 11:57:16 slave kernel: TRACE: nat:KUBE-POSTROUTING:rule:4 IN= OUT=cni0 SRC=192.168.0.105 DST=10.16.1.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=56832 DF PROTO=TCP SPT=51422 DPT=80 SEQ=3403463061 ACK=0 WINDOW=29200 RES=0x00 SYN URGP=0 OPT (020405B40402080A000F67950000000001030307)
转发路径分析
prerouting链
nat表KUBE-NODE-PORT-TCP链ipset有NodePort 31531
ipvs工作在input链,目的IP+目的端口匹配后经过ipvs完成负载均衡转发。
标签:11,00,service,0x00,29,192.168,0c,ipvs,nodePort From: https://www.cnblogs.com/WJQ2017/p/17825814.html