This section uses the Nginx workload as an example to describe how to set the workload access type to LoadBalancer (ELB).
The file names are user-defined. nginx-deployment.yaml and nginx-elb-svc.yaml are merely example file names.
vi nginx-deployment.yaml
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx spec: replicas: 1 selector: matchLabels: app: nginx strategy: type: RollingUpdate template: metadata: labels: app: nginx spec: containers: - image: nginx imagePullPolicy: Always name: nginx imagePullSecrets: - name: default-secret
vi nginx-elb-svc.yaml
Before enabling session stickness, ensure that the following conditions are met:
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.enterpriseID: debb7ae2-6d2f-4e6c-a0aa-1ccafd92b8eb kubernetes.io/elb.autocreate: '{"type":"public","bandwidth_name":"cce-bandwidth-1551163379627","bandwidth_chargemode":"traffic","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 an enhanced load balancer is in use. |
kubernetes.io/session-affinity-mode |
String |
Optional. If session stickness is enabled, add this parameter. The value SOURCE_IP indicates that listeners ensure session stickiness based on source IP addresses. |
kubernetes.io/elb.id |
String |
Optional. This parameter is mandatory if an existing load balancer is used. It indicates the ID of an enhanced 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.enterpriseID |
String |
Optional. This parameter is mandatory if a public/private network load balancer will be automatically created. This parameter indicates the name of the ELB enterprise project in which the ELB will be created. |
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 enhanced load balancer and an EIP. This parameter is also mandatory if a private network load balancer will be automatically created. The system will create an enhanced load balancer. 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 session stickness 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. The value is traffic, indicating that the billing is based on traffic. |
bandwidth_size |
Integer |
Bandwidth size. Set this parameter based on the bandwidth range supported by the region. |
bandwidth_sharetype |
String |
Bandwidth sharing mode.
|
eip_type |
String |
EIP type. |
kubectl create -f nginx-deployment.yaml
If information similar to the following is displayed, the workload is being created.
deployment "nginx" created
kubectl get po
If information similar to the following is displayed, the workload is running.
NAME READY STATUS RESTARTS AGE etcd-0 0/1 ImagePullBackOff 0 1h icagent-m9dkt 0/0 Running 0 3d nginx-2601814895-c1xhw 1/1 Running 0 6s
kubectl create -f nginx-elb-svc.yaml
If information similar to the following is displayed, the service has been created.
service "nginx" created
kubectl get svc
If information similar to the following is displayed, the service access type has been set successfully, and the workload is accessible.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE etcd-svc ClusterIP None <none> 3120/TCP 1h kubernetes ClusterIP 10.247.0.1 <none> 443/TCP 3d nginx LoadBalancer 10.247.130.196 10.78.42.242 80:31540/TCP 51s