You need to enable JavaScript to run this app.
Volcengine Kubernetes Engine

Volcengine Kubernetes Engine

Copy page
Download PDF
CLB
Creating CLB services through kubectl
Copy page
Download PDF
Creating CLB services through kubectl
VKE supports creating LoadBalancer Services. This topic describes how to create a LoadBalancer Service through a YAML file.​
Warning​
Before configuring a LoadBalancer Service, be sure to carefully read Considerations for using LoadBalancer services.​
Prerequisites​
tip​
Currently, only Deployment, StatefulSet, and DaemonSet are supported.​
Procedure​
  1. Create a YAML file for the Service. Here is an example file named service-demo.yaml :​
  • ​
    apiVersion: v1​
    kind: Service​
    metadata:​
    name: service-demo​
    spec:​
    selector:​
    app: nginx​
    ipFamilyPolicy: PreferDualStack​
    ipFamilies: ​
    - IPv6​
    - IPv4​
    ports:​
    - name: rule ​
    protocol: TCP ​
    port: 80​
    targetPort: 80​
    type: LoadBalancer​
    ​
Warning​
  • The system will create a CLB instance correspondingly based on the default settings when using the YAML file above to create a LoadBalancer service in an IPv4 cluster. If a custom CLB is required, we recommend using annotations to create it. For details, see Using annotations to configure LoadBalancer services.​
  • Dual-stack clusters do not support CLB instances of PUBLIC type. Therefore, when creating a LoadBalancer Service in a dual-stack cluster with a YAML file, add the annotation service.beta.kubernetes.io/volcengine-loadbalancer-address-type: "PRIVATE" to specify the CLB type as PRIVATE.​
  1. Execute the following command to create a service.​
  • ​
    kubectl apply -f service-demo.yaml​
    ​
Validating results​
  1. Execute the following command to view the service created.​
​
kubectl get svc -n default​
​
The expected output is as follows. EXTERNAL-IP indicates the public IP address of the CLB to which the Service is attached.​
​
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE​
service-demo LoadBalancer 10.xxx.xxx.xxx 180.xxx.xxx.xxx 80:30891/TCP 44s​
​
  1. Run the following command to view the details of the created Service.​
​
kubectl describe svc service-demo -n default​
​
The information below is what will be printed on the screen. The Annotation on the screen displays the information about the CLB, including CLB instance ID, subnet ID, and EIP billing model. You can search for the CLB instance by its ID on the LoadBalancer console page.​
tip​
For details about LoadBalancer service annotations, see Using annotations to configure LoadBalancer services.​
​
Name: service-demo​
Namespace: default​
Labels: service.beta.kubernetes.io/volcengine-loadbalancer-id=clb-3qe5tw***​
Annotations: service.beta.kubernetes.io/system-volcengine-loadbalancer-create-response-id: clb-3qe5twv8***​
service.beta.kubernetes.io/volcengine-loadbalancer-address-type: PUBLIC​
service.beta.kubernetes.io/volcengine-loadbalancer-bandwidth: 1​
service.beta.kubernetes.io/volcengine-loadbalancer-eip-billing-type: 3​
service.beta.kubernetes.io/volcengine-loadbalancer-health-check-flag: off​
service.beta.kubernetes.io/volcengine-loadbalancer-isp-type: BGP​
service.beta.kubernetes.io/volcengine-loadbalancer-name: k8s-7f328f46***​
service.beta.kubernetes.io/volcengine-loadbalancer-pass-through: false​
service.beta.kubernetes.io/volcengine-loadbalancer-scheduler: wrr​
service.beta.kubernetes.io/volcengine-loadbalancer-spec: small_1​
service.beta.kubernetes.io/volcengine-loadbalancer-subnet-id: subnet-3qe2d3p***​
Selector: app=nginx​
Type: LoadBalancer​
IP Family Policy: SingleStack​
IP Families: IPv4​
IP: 10.xxx.xxx.xxx​
IPs: 10.xxx.xxx.xxx​
LoadBalancer Ingress: 180.xxx.xxx.xxx​
Port: rule 80/TCP​
TargetPort: 80/TCP​
NodePort: rule 30429/TCP​
Endpoints: 192.168.112.4:80,192.168.128.9:80,192.168.48.3:80​
Session Affinity: None​
External Traffic Policy: Cluster​
Events:​
Type Reason Age From Message​
---- ------ ---- ---- -------​
Normal EnsuringLoadBalancer 71s (x4 over 83s) service-controller Ensuring load balancer​
Normal EnsuredLoadBalancer 70s (x2 over 71s) service-controller Ensured load balancer​
​
​
Last updated: 2026.07.24 14:51:36