本文通过下面的例子,分析访问service ip的流程及iptables规则如何生效。
创建service
通过此yaml文件创建三个pod,一个client,两个nginx(监听在80端口),和一个service(将9999映射到nginx的80端口),实现到nginx后端的负载均衡。
[master-1 ~]# cat pod.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx1
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
kubernetes.io/hostname: pccc-203-10-worker-1
containers:
- name: hello
image: nginx
ports:
- name: http
containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx2
spec:
selector:
matchLabels:
app: nginx
replicas: 1
templ