What Is a Service in Kubernetes? A Complete A-Z Guide to Service Types and Configuration
Sep 24, 2026In the Kubernetes world, Pods have one defining characteristic: they are ephemeral. They are constantly created, terminated, and replaced. Each time this happens, a Pod’s IP address changes. This creates a challenging problem: How can A communicate with B if B’s IP address keeps changing? The answer is Kubernetes Service. Let’s explore it with Viettel IDC.

What Is a Service in Kubernetes?
In Kubernetes, a Service is an important entity that represents a group of Pods running an application or a specific functional component. A Service maintains network access policies and is responsible for enforcing these policies for every incoming request.
Simply put, if Pods are the “workers” that directly handle tasks, then a Kubernetes Service is the “manager” that coordinates traffic, ensuring that requests from clients always reach the right destination.
The introduction of Kubernetes Services stems from one of the most fundamental characteristics of Pods: their short and unstable lifecycle. In Kubernetes, Pods can be replaced at any time due to scaling, hardware failures, or software updates. Although Kubernetes ensures application availability through replicas, it does not guarantee the permanent existence of any particular individual Pod.
This leads to a major networking challenge:
- Each time a Pod is recreated, it receives an entirely new IP address.
- If an application attempts to connect directly to another Pod’s IP address, the connection will be lost as soon as that Pod is replaced.
- Pods that need to communicate with each other cannot rely on the individual IP addresses of the underlying Pods.
To solve this problem, Kubernetes Service acts as an intermediary:
- ClusterIP: When a Service is created, it is assigned a virtual IP address called a ClusterIP. This address remains stable throughout the Service’s lifecycle until the Service is explicitly deleted.
- Traffic Forwarding Mechanism: Instead of connecting directly to a Pod, application components connect to the Service’s address. The Kubernetes Service then acts as a traffic router, forwarding the request to a suitable and healthy Pod within the group it manages.
Thanks to this mechanism, a Kubernetes Service acts as a reliable endpoint, decoupling the dependency between communicating components.
In addition to using Kubernetes Services, applications specifically designed for the Kubernetes platform (Kubernetes-native applications) have an alternative approach: making requests directly through the Kubernetes API Server. The API Server can automatically expose and maintain endpoints for running Pods. However, this approach is generally more complex and is intended for advanced use cases, while Services remain the standard and most effective solution for most application architectures today.
Structure of a Kubernetes Service
Technically, a Kubernetes Service operates as an abstract entity that links a group of Pods through an identifying name and a stable IP address. This mechanism is the key to enabling Pods to discover each other and route requests accurately in a distributed environment.
To correctly connect applications, Kubernetes Services use the combination of Labels and Selectors to filter and identify the appropriate targets. A standard Kubernetes Service configuration typically includes the following key components:
- Label Selector: This is the most important component, acting as a filter to identify the list of target Pods to which the Service will route traffic.
- ClusterIP: An internal virtual IP address assigned to the Service, serving as a stable connection endpoint.
- Port Number: The port on which the Service listens for incoming requests.
- TargetPort: An optional port mapping that specifies the particular port on the Container to which traffic will be forwarded. (For example, the Service listens on port 80 but forwards traffic to port 8080 on the Container.)
How to Create a Service in Kubernetes
The standard and most professional way to configure a Kubernetes Service is by using a YAML Manifest. This file acts as a blueprint that defines how the Service operates and connects to Pods.
Basic YAML File Structure
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 8080
To master Kubernetes Services, you need to clearly understand the three core components in the Manifest:
- metadata:name: This is the logical name of the Service. More importantly, it becomes the Service’s internal DNS name. Other applications within the Cluster can access this Service simply by using the name my-service.
- spec:selector: This is the membership “filter.” The Service searches for and routes traffic to all Pods whose labels match this declaration (in the example above, app: nginx).
- spec:ports: Defines the communication ports.
-
port: The port that the Service opens to listen for incoming requests.
-
targetPort: The actual port on which the application inside the Pod is running. The Service receives requests on the port and forwards them to the targetPort.
Deployment command: To deploy this Service object to the Cluster, use the familiar kubectl command:
kubectl apply -f /path/to/service-manifest.yaml

Types of Services in Kubernetes
1. ClusterIP
ClusterIP is the default type of Kubernetes Service. It assigns an internal IP address (Cluster-Internal IP) to the Service. Only objects within the Cluster can access this Service.
Example Manifest:
apiVersion: v1
kind: Service
metadata:
name: my-clusterip-service
spec:
type: ClusterIP
clusterIP: 10.10.5.10 (Optional) A specific IP can be set within the Cluster’s IP range
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080
2. NodePort
NodePort is an extension of ClusterIP. It allows a Service to be accessed from outside the Cluster by opening a specific port on all Nodes (servers). When you access IP_of_any_Node:NodePort, traffic is forwarded to the ClusterIP and then to the Pod.
Note:
- Default port range: 30000 - 32767.
- The kube-proxy component on each Node is responsible for listening and forwarding packets (NAT).
- Commonly used for manually configuring Load Balancers or in Dev/Test environments.
Example Manifest:
apiVersion: v1
kind: Service
metadata:
name: my-nodeport-service
spec:
type: NodePort
selector:
app: nginx
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080
nodePort: 30000 (Optional) Fixes the externally exposed port
3. LoadBalancer
LoadBalancer is the most common type of Kubernetes Service when operating on Cloud platforms (such as Viettel IDC, AWS, and GCP). It builds on top of NodePort while adding integration with the Cloud provider’s Load Balancer.
The LoadBalancer mechanism automatically requests the Cloud provider to allocate a Public IP. Traffic from the Internet follows the path:
External Load Balancer → NodePort → ClusterIP → Pod
This helps distribute traffic efficiently while providing a stable public IP address for end users.
Example Manifest:
apiVersion: v1
kind: Service
metadata:
name: my-loadbalancer-service
spec:
type: LoadBalancer
clusterIP: 10.0.160.135
loadBalancerIP: 168.196.90.10 (Requires the Cloud Provider to allocate this specific IP, if supported)
selector:
app: nginx
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080
4. ExternalName
The ExternalName Service type is quite special because it does not use Selectors and does not define any ports or IP addresses. Instead, it maps the Service to an external DNS domain name through a CNAME record.
Applications:
- Connecting a Pod to a Database located outside the Kubernetes Cluster (for example, my.database.domain.com).
- Allowing a Pod in one Namespace to access a Service in another Namespace as if it were a local service.
Example Manifest:
apiVersion: v1
kind: Service
metadata:
name: my-externalname-service
spec:
type: ExternalName
externalName: my.database.domain.com (The target domain name to point to)
Conclusion
Kubernetes Service is not merely a naming mechanism; it is the backbone that keeps communication within the Cluster operational. It completely solves the ephemeral nature of Pods, acting as an intelligent traffic router that ensures every connection request, whether originating internally or from the Internet, reaches the correct destination regardless of the continuous changes occurring to the underlying Pods.
However, there is a significant gap between theory and real-world operations. To simplify this process and focus resources on core application development, businesses can choose Viettel Open Kubernetes Service (vOKS). Built on Viettel IDC’s powerful Cloud infrastructure, vOKS provides built-in, internationally standardized Load Balancer integration, enabling your system to automatically distribute traffic and ensure high availability with just a few clicks.
Discover powerful and reliable Kubernetes infrastructure at: https://viettelidc.com.vn/en/viettel-kubernetes-service
For consultation and information about Viettel’s services, you can contact Viettel IDC directly through the following channels:
- Hotline: 1800 8088 (toll-free)
- Fanpage: https://www.facebook.com/viettelidc
- Website: https://viettelidc.com.vn
Featured news
Related news
Kubernetes vs Serverless? Which Is the Right Choice for Enterprise Architecture?
In the Cloud Native era, Kubernetes vs Serverless represents a classic clash between two philosophies: Maximum control or ultimate convenience? If Kubernetes can be considered the solid backbone for complex Microservices systems, Serverless is the speed-driven launchpad that helps optimize costs for enterprises. So, which one is the right fit for your architecture?
What Is Kubespray? A Production-Ready Kubernetes Deployment Solution for Enterprises
Kubernetes has revolutionized Container orchestration, providing an efficient and flexible solution for application deployment. However, manually setting up and maintaining a Kubernetes Cluster is often highly complex and can easily become overwhelming.
What Is Minikube? A Beginner’s Guide to Running Kubernetes
Do you want to start learning Kubernetes but are concerned about server rental costs or complicated configuration? Minikube is the perfect answer. So, what is Minikube, and how does this tool turn your laptop into a “pocket-sized” Kubernetes Cluster that you can use for completely free hands-on practice?
What Is a Helm Chart? The Most Effective Way to Manage Kubernetes Applications
Are you overwhelmed by having to manage dozens of separate YAML configuration files every time you deploy an application to Kubernetes? That’s when you need Helm Chart – a solution often described as the key to escaping configuration hell.
What Is a Namespace in Kubernetes? A Complete A-Z Guide to Creating and Managing Namespaces
A Kubernetes Cluster is like a huge office building. Without proper zoning, resource conflicts between departments (Dev, Test, Prod) are inevitable. Kubernetes Namespaces are the essential partitions that divide physical infrastructure into multiple Virtual Clusters, ensuring effective isolation and management.
Kubernetes Cost Optimization: Effective Cloud Cost Reduction Strategies for Businesses
Kubernetes enables businesses to deploy and operate containerized applications at scale with greater flexibility. However, this flexibility also comes with increasingly complex cost management challenges. Kubernetes cost optimization is not simply about cutting resources or shrinking the cluster.
What Is the Vertical Pod Autoscaler? Effectively Optimizing Pod Resources in Kubernetes
In Kubernetes, manually setting CPU and memory resources for Pods can easily lead to either resource shortages or infrastructure waste. Improper configuration can cause applications to slow down, experience OOMKilled errors, or prevent the cluster from fully utilizing its available capacity. The Vertical Pod Autoscaler provides a smarter approach by automatically recommending and adjusting resources based on actual usage.
What Is the Kubernetes Scheduler? How Kubernetes Decides Where Pods Run
In Kubernetes, a Pod does not automatically start running immediately after it is created. It first needs to be assigned to a suitable node within the cluster. This task is handled by the Kubernetes Scheduler, whose role is to determine where a Pod should run. The Scheduler helps allocate resources efficiently, maintain system stability, and optimize overall performance.
Kubernetes vs Docker: Understanding the Key Differences for Effective Container Deployment
During the application containerization process, many people who are new to DevOps often confuse Docker and Kubernetes as two tools with the same role, and some even believe that learning only one of them is sufficient. In reality, Docker and Kubernetes solve two completely different problems, but they are closely connected within modern deployment architectures.
Comment ()