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

Volcengine Kubernetes Engine

Copy page
Download PDF
Service
ClusterIP
Copy page
Download PDF
ClusterIP
ClusterIP allows workloads to be exposed to other workloads within the same cluster through services. This topic describes how to configure a ClusterIP service.​
Background information​
When creating a ClusterIP service in a cluster, the system generates an internal domain name for the service in the format of service-name.namespace.svc.cluster.local:port. For example, after you create a service named nginx with port 80 in the default namespace, you can access the service and its backend pods within the cluster by using nginx:80 or nginx.default:80.​
If you want to directly connect to pods instead of communicating through the load balancer and service IP, you can create a headless service. A headless service does not have a ClusterIP. When DNS queries are performed inside the cluster, DNS records for all pods are returned, so you can directly access the IP addresses of all pods.​
The following table shows the main differences between ClusterIP and headless services.​
​
Item​
ClusterIP​
Headless Service​
ClusterIP​
Yes​
None​
DNS resolution for services​
The ClusterIPs of Services will be returned as results.​
IPs of all pods will be returned as results.​
Accessed by other applications​
Services are the farthest destinations that other applications can see. The iptables acts as a load balancer to determine which pod the traffic is further forwarded to.​
Pods can be directly accessed through IPs.​
Application scenarios​
Where services are required to provide load balancing for pods.​
  • Where direct connections to pods are required. For example, Kafka pods deployed in a cluster need to be accessed directly by clients.​
  • Scenarios where clients handle load balancing. For example, when two applications are deployed in a cluster and the clients handle load-balancing requests themselves, no proxy service is needed.​
​
Prerequisites​
Deployments have been created. For details, see Creating Deployments, Creating StatefulSets, and Creating DaemonSets.​
tip​
Currently, only Deployment, StatefulSet, and DaemonSet are supported.​
Procedure​
Creating via console​
  1. Log in to the VKE console.​
  1. Click Cluster in the left navigation bar.​
  1. On the cluster list page, click the name of the cluster in which you want to create services.​
  1. On the cluster management page, select Services and Ingresses > Service in the left navigation bar, then click Create Service.​
  • Basic information​
  • ​
    Parameter​
    Description​
    Name​
    Enter a name for the service. Make sure the name is unique under the same namespace.​
    Namespace​
    Select the namespace to which the service belongs. It is recommended that you select the namespace created by yourself or the default namespace created by the system. For details about namespaces, see Namespace overview.​
    Label​
    Click Add new to add labels to the service. Labels are used to define various attributes of services, facilitating batch filtering and other operations.​
    Annotation​
    It is an annotation in Kubernetes. Click Add annotation to add one for the service by creating a key-value pair.​
    ​
  • Access configuration​
  • ​
    Parameter​
    Description​
    Access type​
    Select an access type for the service. In this case, select ClusterIP.​
    Communication protocol​
    [beta·apply for trial] IPv4 and IPv6 protocols can be configured with different options to cover specific scenarios. The options include:​
    • IPv4: IPv4 addresses only.​
    • IPv6: IPv6 addresses only.​
    • IPv4&IPv6: Both protocols are allowed, but the IPv4 addresses will be used by default.​
    • IPv6&IPv4: Both protocols are allowed, but the IPv6 addresses will be used by default.​
    tip​
    For details about how to create IPv4/IPv6 clusters, see Create IPv4/IPv6 clusters with VKE.​
    Port mapping​
    Create a port mapping:​
    • Name: Enter a name for the port mapping between the service and container.​
    • Service level port: Enter a port used to access the service. Duplicate ports are not allowed for services using the same protocol.​
    tip​
    In clusters using the VPC-CNI network model, duplicate ports are not allowed for services even across different protocols. That is, no services can share the same port number regardless of whether they use TCP or UDP.​
    • Protocol: Select a protocol for the service. Available protocols include TCP and UDP.​
    • Container port: Specify the port of the container, which is a port number through which the deployment provides services externally. e.g., the default port number for Nginx is 80.​
    Label selector​
    Services are bound to back-end pods through label selectors.​
    • Add new: add the label of the Deployment to which the service will be bound. You can find deployment labels by clicking Workload in the left navigation bar of the cluster management page.​
    • Associated workload: Select the deployment to which the service will be bound. Currently, only Deployment, StatefulSet, and DaemonSet are supported.​
    Session persistence​
    Whether to enable session persistence.​
    • Disabled by default.​
    • Check Configure timeout to enable session persistence and set its duration. The service will forward all requests from the same IP to a single backend server. We recommend setting a timeout longer than 120 seconds.​
    tip​
    Headless services do not support session persistence and the timeout setting will not take effect.​
    ​
  1. Click Confirm to finish the configuration.​
Creating via kubectl command line​
tip​
Make sure the following requirements are met before getting started:​
  • Successfully connected to the target cluster with kubectl. For details, please seeConnect to a cluster.​
  1. Create a YAML file for the service.The following code is the content of a sample YAML file named service-demo.yaml:​
  • ​
    apiVersion: v1​
    kind: Service​
    metadata:​
    name: service-demo # Service name.​
    spec:​
    selector:​
    app: nginx # Bind the service to backend pods via a label selector.​
    ipFamilyPolicy: PreferDualStack # Preferred protocol stack SingleStack means only one protocol stack is applied, PreferDualStack means two protocol stacks can be applied simultaneously.​
    ipFamilies: # The communication protocols actually used. Single-stack can have IPv4 and IPv6 as the options; dual-stack can have IPv4&IPv6 and IPv6&IPv4 as the options.​
    - IPv6​
    - IPv4​
    ports:​
    - name: rule #The name of the port mapping rule.​
    protocol: TCP # service protocol, which can either be TCP or UDP.​
    port: 8080 # Service port.​
    targetPort: 80 # Container port, a port number or port name through which the deployment provides service, e.g., the default port number for Nginx is 80.​
    type: ClusterIP # Service type.​
    ​
  1. Execute the following command to create a service.​
  • ​
    kubectl apply -f service-demo.yaml​
    ​
Result checking​
Viewing the services​
The service you created successfully can be found in the service list, which displays cluster IPs (i.e. ClusterIP) and internal endpoints (i.e., internal domain names)​
Testing the connections to services​
You can access the service in several ways as described below:​
  • Accessing the service using ClusterIP:Port.​
  • Accessing the service using service-demo:80 within the same namespace.​
  • Accessing the service in another namespace using service-demo.default:80 ​
​
Last updated: 2026.07.24 14:51:36