Service
测试 Service
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
type: ClusterIP
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
CLB 直连 Pod
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
annotations:
# 显式声明使用直连
service.cloud.tencent.com/direct-access: "true"
spec:
type: LoadBalancer
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
使用已有 CLB
- 使用已有 CLB
- 多个 Service 复用同一个 CLB
让 Service 使用指定已经创建好的 CLB:
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
annotations:
# 指定要已有的 CLB ID
service.kubernetes.io/tke-existed-lbid: "lb-********"
spec:
type: LoadBalancer
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
多个 Service 可以使用同一个 CLB (前提是端口不冲突):
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
annotations:
# 指 定要已有的 CLB ID
service.kubernetes.io/tke-existed-lbid: "lb-********"
spec:
type: LoadBalancer
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
apiVersion: v1
kind: Service
metadata:
name: nginx2
labels:
app: nginx2
annotations:
# 指定要已有的 CLB ID
service.kubernetes.io/tke-existed-lbid: "lb-********"
spec:
type: LoadBalancer
ports:
- port: 8080
protocol: TCP
targetPort: 80
selector:
app: nginx2