k8s中使用service做四层负载均衡
我们通过service访问k8s内部应用的时候数据包走向是从 客户端请求
–>node节点的IP:端口
–>service的ip:端口
-->pod的ip:端口
demo
创建一个k8s pod,通过service代理
cat pod_test.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
run: nginx
replicas: 2
template:
metadata:
labels:
run: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
创建一个service
cat service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
run: nginx
spec:
ports:
- port: 80
protocol: TCP
selector:
run: nginx