kubernetes - Service
一:介绍
是kubernetes系统中提供的只能负载均衡器
1.服务发现
通过Label标签获取Pod
2.负载均衡
使用
kind: Deployment
apiVersion: apps/v1
metadata:
name: test-service
spec:
selector:
matchLabels:
app: test-svc
template:
metadata:
labels:
app: test-svc
spec:
containers:
- name: nginx
image: nginx:1.19.2
---
kind: Service
apiVersion: v1
metadata:
name: nginx-svc
spec:
ClusterIP: None
selector:
app: test-svc
ports:
- port: 80
targetPort: 80
name: http
- port: 443
targetPort: 443
name: https
查看
kubectl describe service nginx-svc
二:Service类型
1. ClusterIP
kind: Service
apiVersion: v1
metadata:
name: svc
spec:
ports:
- name: http
port: 80
targetPort: 80
nodePort: 30001
selector:
app: test-svc
type: NodePort
2. NodePort
3.HeadLess
kind: Service
apiVersion: v1
metadata:
name: test-svc
spec:
ClusterIP: None
selector:
app: test-svc
ports:
- post: 80
targetPort: 80
- post: 443
targetPort: 443
4.LoadBalancer
关联云服务商的弹性IP
kind: Service
apiVersion: v1
metadata:
name: loadbalancer
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
name: http
selector:
app: test
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: loadbalancer
spec:
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
name: nginx-http