How to Use ELB in a Cluster
This section describes how to use the Elastic Load Balance (ELB) service in a cluster created by CCE.
Procedure
Before enabling sticky session, ensure that the following conditions are met:
- The workload protocol is TCP.
- Anti-affinity has been configured between pods of the workload. That is, all pods of the workload are deployed on different nodes. For details, see Workload-Node Anti-Affinity.
apiVersion: v1
kind: Service
metadata:
annotations:
kubernetes.io/elb.class: union
kubernetes.io/session-affinity-mode: SOURCE_IP
kubernetes.io/elb.subnet-id: 5083f225-9bf8-48fa-9c8b-67bd9693c4c0
kubernetes.io/elb.autocreate: "{\"type\":\"public\",\"bandwidth_name\":\"cce-bandwidth-1551163379627\",\"bandwidth_chargemode\":\"bandwidth\",\"bandwidth_size\":5,\"bandwidth_sharetype\":\"PER\",\"eip_type\":\"5_bgp\",\"name\":\"james\"}"
labels:
app: nginx
name: nginx
spec:
externalTrafficPolicy: Local
ports:
- name: service0
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancer apiVersion: v1
kind: Service
metadata:
annotations:
kubernetes.io/elb.class: union
kubernetes.io/session-affinity-mode: SOURCE_IP
kubernetes.io/elb.id: 3c7caa5a-a641-4bff-801a-feace27424b6
kubernetes.io/elb.subnet-id: 5083f225-9bf8-48fa-9c8b-67bd9693c4c0
labels:
app: nginx
name: nginx
spec:
loadBalancerIP: 10.78.42.242
externalTrafficPolicy: Local
ports:
- name: service0
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancer | Parameter | Type | Description |
|---|---|---|
| kubernetes.io/elb.class | String | Mandatory and must be set to union if a shared load balancer is in use. |
| kubernetes.io/session-affinity-mode | String | Optional. If sticky session is enabled, add this parameter. The value SOURCE_IP indicates that listeners ensure sticky session based on source IP addresses. |
| kubernetes.io/elb.id | String | Optional. This parameter is mandatory if an existing ELB is used. ID of a shared load balancer. |
| kubernetes.io/elb.subnet-id | String | Optional. This parameter is mandatory only if a load balancer will be automatically created. For clusters of v1.11.7-r0 or later, this parameter can be left unspecified. |
| kubernetes.io/elb.autocreate | elb.autocreate object | Optional. This parameter is mandatory if a public network load balancer will be automatically created. The system will create an ELB and an EIP. This parameter is also mandatory if a private network load balancer will be automatically created. The system will create an ELB. Example:
|
| loadBalancerIP | String | Private IP address of a private network load balancer or public IP address of a public network load balancer. |
| externalTrafficPolicy | String | Optional. If sticky session is enabled, add this parameter so requests are transferred to a fixed node. If a LoadBalancer Service with this parameter set to Local is created for a workload, the workload can be accessed only when the client is installed on the same node as the server. |
| port | Integer | Access port that is registered on the load balancer and mapped to the cluster-internal IP address. |
| targetPort | String | Container port on the CCE console. |
| Parameter | Type | Description |
|---|---|---|
| name | String | Name of the load balancer that is automatically created. The value is a string of 1 to 64 characters that consist of letters, digits, underscores (_), and hyphens (-). |
| type | String | Network type of the load balancer.
|
| bandwidth_name | String | Bandwidth name. The default value is cce-bandwidth-******. The value is a string of 1 to 64 characters that consist of letters, digits, underscores (_), hyphens (-), and periods (.). |
| bandwidth_chargemode | String | Bandwidth billing mode.
|
| bandwidth_size | Integer | Bandwidth size. Set this parameter based on the bandwidth range supported by the region. For details, see the description of the size field in Table 4 in Assigning an EIP. |
| bandwidth_sharetype | String | Whether the bandwidth is shared or dedicated. Options:
|
| eip_type | String | EIP type. For details, see the description of the type field in Table 3 in Assigning an EIP. |
Last Article: Specifying Add-ons to Be Installed During Cluster Creation
Next Article: How to Obtain Parameters in the API URI
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.