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

Volcengine Kubernetes Engine

Copy page
Download PDF
Service
NodePort
Copy page
Download PDF
NodePort
NodePort exposes a service by opening a static port on the IP of every node in the cluster. This topic describes how to configure a NodePort service.​
Background information​
When you create a NodePort service in a cluster, the system opens a static port on the IP of every node. Other applications can then access the service by sending requests to Node_IP:Node_Port.​
The IP address of a node can be either private or public. Therefore, NodePort services can be made available internally or externally.​
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 refers to annotations in Kubernetes. Click Add annotation to add one to 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 NodePort.​
    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 Creating IPv4/IPv6 clusters with VKE.​
    Port mapping​
    Configure a port mapping rule:​
    • Name: enter a name for the port mapping between the service and container.​
    • Service level port: Enter a port through which the service will be accessed. 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. Currently, available protocols include TCP and UDP.​
    • Node port: the port exposed on the node, which can be an integer from 30000 to 32767. A port will be allocated automatically by the system if you leave it empty.​
    • Container port: 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: Specify the label of the Deployment to which the service will be bound.​
    • Associated workload: Select the Deployment to bind the service to. Currently, Deployment, StatefulSet, and DaemonSet are supported.​
    warning​
    Do not bind NodePort services to workloads deployed on Volcengine Container Instances.​
    External traffic policy​
    The policies that the service will use to forward inbound traffic: ​
    • Cluster: traffic is forwarded evenly to each pod of the workload.​
    • Local: traffic can only be forwarded to the local pods on the current node, which may cause unbalanced traffic distribution. However, the source IPs can be retained.​
    Session persistence​
    Whether to enable session persistence.​
    • Disabled by default.​
    • Check Configure timeout to enable session persistence and set its duration. The service ensures requests from the same IP are forwarded to a single backend server. We recommend setting a timeout longer than 120 seconds.​
    ​
  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. A YAML file for creating 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.​
    ports:​
    - name: rule #The name of the port mapping rule.​
    protocol: TCP # service protocol, which can either be TCP or UDP.​
    port: 80 # Service port.​
    nodePort: 30000 # NodePort, which can be an integer from 30000 to 32767.​
    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: NodePort # Service type.​
    ​
  1. Execute the following command to create a service.​
  • ​
    kubectl apply -f service-demo.yaml​
    ​
Result checking​
Viewing services​
The service you created can be found in the service list.​
If you did not specify a NodePort when creating a service, the system will allocate one for the service. You can click the service name to go to the Overview tab, and scroll to the Port mapping section to view the port number in the Container port column. ​
Access services​
Any successfully created service can be accessed through any node IP and node port within the same VPC or by any container in the cluster. It can also be accessed through a public IP if the node has one.​
​alt​​
​
Last updated: 2026.07.24 14:51:36