在Serverless集群中使用Service
更新时间:2023-03-24
本文介绍如何在serverless集群中使用Service。根据在创建集群的时候选择的不同Cluster Service模式--kube-proxy或BLB,有下面两种方式:
BLB
采用该模式的Service都绑定一个BLB,Service的ClusterIP是BLB的VPC IP。在该模式下,用户需要为BLB付费,适合少量Service,大量后端Pod的集群。
限制
该模式下由于BLB本身的限制,导致Service也有以下限制:
- 同一个Service不能同时监听TCP和UDP的同一个端口,如果业务方有暴露TCP、UDP同一个端口的需求,建议拆分成两个Service来规避。
- 对于监听UDP端口的Service需要配置UDP的健康检查字符串,通过在Service的Annotations中进行配置,Annotation Key:
service.kubernetes.io/cce-appblb-udp-health-check-string
,健康检查字串可参考:BLB UDP 配置 - BLB有配额的限制,参考:BLB 配额说明
- Service的ClusterIP不能在创建时指定。
kube-proxy
访问此模式的Service时,客户端Pod需要包含一个运行kube-proxy的container。在该模式下,用户需要为Pod中的kube-proxy容器所占用的资源付费,适合Service数量较大,客户端Pod数量相对较少的集群。
该模式下,客户端Pod如果需要开启kube-proxy,需要通过Pod template中的Annotation进行指定,Annotation Key:bci.virtual-kubelet.io/kube-proxy-enabled
配置示例
Plain Text
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: busybox
5spec:
6 selector:
7 matchLabels:
8 app: busybox
9 replicas: 1
10 template:
11 metadata:
12 labels:
13 app: busybox
14 annotations:
15 bci.virtual-kubelet.io/kube-proxy-enabled: "true"
16 spec:
17 containers:
18 - name: busybox
19 image: busybox
20 command: [ "/bin/sh", "-c", "sleep 3600" ]