跳到主要内容

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

让 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

指定 CLB 属性

默认创建的 CLB 是公网类型,如果要内网类型,需传入子网 ID:

apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
annotations:
# 指定子网 ID
service.kubernetes.io/qcloud-loadbalancer-internal-subnetid: subnet-********
spec:
type: LoadBalancer
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx