TkeServiceConfig is a Custom Resource Definition (CRD) provided by TKE. TkeServiceConfig can help you configure LoadBalancer-type Services more flexibly and manage various CLB configurations in them.
CLB parameters and features that cannot be defined by Service YAML semantics can be configured through TkeServiceConfig.
TkeServiceConfig can help you quickly perform CLB configuration. Through the Service annotation service.cloud.tencent.com/tke-service-config:<config-name>, you can specify the target configuration to be applied in the Service.
Note:
TkeServiceConfig resources and the Service need to be in the same namespace.
TkeServiceConfig does not help you directly configure or modify protocols and ports. You need to describe protocols and ports in the configuration in order to specify the listener for forwarding the configuration. You can declare multiple sets of listener configurations in a single TkeServiceConfig. Currently, configurations are mainly provided CLB health check and backend access.
When the protocol and port are specified, the configuration will be accurately forwarded to the corresponding listener:
spec.loadBalancer.l4Listeners.protocol
: Layer-4 protocolspec.loadBalancer.l4Listeners.port
: listening portapiVersion: cloud.tencent.com/v1alpha1
kind: TkeServiceConfig
metadata:
name: sample # configuration name
namespace: default # configuration namespace
spec:
loadBalancer:
l4Listeners: # Layer-4 rule configuration, applicable to Service listener configuration
- protocol: TCP # Layer-4 rule for protocol ports anchoring the Service. Required. Enumerated value: TCP|UDP.
port: 80 # Required. Value range: 1-65535.
session: # Configuration related to session persistence. Optional.
enable: true # Indicates whether to enable session persistence. Required. Boolean.
sessionExpireTime: 100 # Session persistence duration. Optional. Default value: 30. Value range: 30-3600. Unit: second.
healthCheck: # Configuration related to health check. Optional.
enable: true # Indicates whether to enable session persistence. Required. Boolean.
intervalTime: 10 # Health check probe interval. Optional. Default value: 5. Value range: 5-300. Unit: second.
healthNum: 2 # Healthy threshold, indicating the number of consecutive healthy health check results that it takes to indicate normal forwarding. Optional. Default value: 3. Value range: 2-10. Unit: times.
unHealthNum: 3 # Unhealthy threshold, indicating the number of consecutive unhealthy health check results that it takes to indicate a forwarding exception. Optional. Default value: 3. Value range: 2-10. Unit: times.
timeout: 10 # Health check response timeout threshold. This should be less than the health check interval. Optional. Default value: 2. Value range: 2-60. Unit: second.
scheduler: WRR # Request forwarding method. WRR, LEAST_CONN, and IP_HASH indicate polling by weight, least connections, and hashing by IP address, respectively. Optional. Enumerated value: WRR | LEAST_CONN.
internetMaxBandwidthOut: 100 # Max egress bandwidth, valid only for public network LBs. Optional. Value range: 0-2048. Unit: Mbps.
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: jetty
name: jetty-deployment
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 3
revisionHistoryLimit: 10
selector:
matchLabels:
app: jetty
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: jetty
spec:
containers:
- image: jetty:9.4.27-jre11
imagePullPolicy: IfNotPresent
name: jetty
ports:
- containerPort: 80
protocol: TCP
- containerPort: 443
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
apiVersion: v1
kind: Service
metadata:
annotations:
service.cloud.tencent.com/tke-service-config: jetty-service-config
# Specify existing tke-service-config
# service.cloud.tencent.com/tke-service-config-auto: true
# Automatically create tke-service-config
name: jetty-service
namespace: default
spec:
ports:
- name: tcp-80-80
port: 80
protocol: TCP
targetPort: 80
- name: tcp-443-443
port: 443
protocol: TCP
targetPort: 443
selector:
app: jetty
type: LoadBalancer
This sample includes the following configurations:
jetty-service-config
CLB configuration is used.apiVersion: cloud.tencent.com/v1alpha1
kind: TkeServiceConfig
metadata:
name: jetty-service-config
namespace: default
spec:
loadBalancer:
l4Listeners:
- protocol: TCP
port: 80
healthCheck:
enable: false
- protocol: TCP
port: 443
session:
enable: true
sessionExpireTime: 3600
healthCheck:
enable: true
intervalTime: 10
healthNum: 2
unHealthNum: 2
timeout: 5
scheduler: LEAST_CONN
This sample includes the following configurations:
The name is jetty-service-config
, and in the Layer-4 listener configuration, two configuration segments are declared:
➜ kubectl apply -f jetty-deployment.yaml
➜ kubectl apply -f jetty-service.yaml
➜ kubectl apply -f jetty-service-config.yaml
➜ kubectl get pods
NAME READY STATUS RESTARTS AGE
jetty-deployment-8694c44b4c-cxscn 1/1 Running 0 8m8s
jetty-deployment-8694c44b4c-mk285 1/1 Running 0 8m8s
jetty-deployment-8694c44b4c-rjrtm 1/1 Running 0 8m8s
➜ kubectl get service jetty
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
jetty LoadBalancer 10.127.255.209 150.158.220.237 80:31338/TCP,443:32373/TCP 2m47s
# Obtain the TkeServiceConfig Configuration List
➜ kubectl get tkeserviceconfigs.cloud.tencent.com
NAME AGE
jetty-service-config 52s
# Update and Modify the TkeServiceConfig Configuration
➜ kubectl edit tkeserviceconfigs.cloud.tencent.com jetty-service-config
TkeServiceConfig.cloud.tencent.com/jetty-service-config edited
Was this page helpful?