> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kubernetes Services

> Kubernetes Services provide stable network identities and route traffic to Pods using label selectors, offering ClusterIP NodePort and LoadBalancer types for internal and external access.

Brief recap: Pods are the smallest deployable units in Kubernetes and host your application containers. Pods are ephemeral — they can be created and terminated to match the desired cluster state. Because Pod IPs can change, we need a stable way for components (for example, a frontend and a backend) to discover and communicate with each other.

Kubernetes Services provide that stable network identity. A Service exposes an IP and DNS name plus a routing policy that forwards traffic to one or more matching Pods. Instead of relying on individual Pod IPs, other components use the Service to reach the application instances.

When you create a back-end Service, you typically configure a selector that matches labels on backend Pods. The Service then routes traffic to those Pods, maintaining a stable access point even as Pods are recreated.

![A diagram of a Kubernetes cluster showing Backend and Frontend deployments with individual pods and IPs. A Backend Service (ClusterIP 10.96.0.12) is shown routing traffic to the backend pods.](https://mintcdn.com/kodekloud-c4ac6d9a/UK3oaG81L_yXeDcP/images/Kubernetes-and-Cloud-Native-Associate-KCNA/Container-Orchestration-Service-Mesh/Kubernetes-Services/k8s-cluster-backend-service-clusterip-10960012.jpg?fit=max\&auto=format\&n=UK3oaG81L_yXeDcP\&q=85\&s=fdb20986785846f2161aad3962d7cb59)

Services match Pods using labels and selectors. Add labels to Pods (or their owning controllers like Deployments), and configure the Service `selector` to match those labels so the Service knows which endpoints receive traffic.

## How Services select Pods

Services select Pods with label selectors. You typically label your Deployment (or Pod template) and then reference the same label set in the Service spec. This decouples service discovery from Pod lifecycle — traffic flows to whatever Pods currently match the selector.

Example concepts:

* Label on Pod/Deployment: `app: backend`
* Service selector: `app: backend`
* Service routes to all Pods whose labels match the selector

## Common Service types

There are three common Service types you’ll encounter in Kubernetes:

| Service Type | Purpose | How it’s reached |
| - | - | - |
| ClusterIP (default) | Internal-only virtual IP for access within the cluster | Pods/containers reach it via the ClusterIP or the Service DNS name |
| NodePort | Exposes the Service on a static port on every Node | External clients use `http://<node-ip>:<node-port>` (NodePort range typically 30000–32767) |
| LoadBalancer | Requests a cloud provider load balancer to expose the Service externally | Cloud load balancer forwards to NodePort/ClusterIP backends; makes Service reachable from the internet |

![A slide titled "Kubernetes Services" showing three illustrated service types: NodePort, ClusterIP, and LoadBalancer. Each box depicts a rectangular pod/service with blue dots indicating how traffic connects to the service (single external node for NodePort, internal access for ClusterIP, and multiple external points for LoadBalancer).](https://mintcdn.com/kodekloud-c4ac6d9a/UK3oaG81L_yXeDcP/images/Kubernetes-and-Cloud-Native-Associate-KCNA/Container-Orchestration-Service-Mesh/Kubernetes-Services/kubernetes-services-nodeport-clusterip-loadbalancer.jpg?fit=max\&auto=format\&n=UK3oaG81L_yXeDcP\&q=85\&s=1a8e7f8eb7ad63d1946b2803d3bf87a3)

Be careful when exposing Services externally. `NodePort` and `LoadBalancer` make your application reachable outside the cluster — ensure proper authentication, network policies, and firewall rules are in place.

## Example: labels + Service YAML

Below is a minimal example demonstrating a Deployment with labels and a ClusterIP Service that selects those Pods.

Deployment (snippet):

```yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: backend
  template:
    metadata:
      labels:
        app: backend
    spec:
      containers:
      - name: backend
        image: my-backend-image:latest
        ports:
        - containerPort: 8080
```

ClusterIP Service (snippet):

```yaml theme={null}
apiVersion: v1
kind: Service
metadata:
  name: backend-service
spec:
  type: ClusterIP
  selector:
    app: backend
  ports:
  - port: 80
    targetPort: 8080
```

Commands to inspect Services and endpoints:

* `kubectl get svc` — list Services
* `kubectl describe svc backend-service` — view Service details
* `kubectl get endpoints backend-service` — view which Pod IPs the Service routes to

## Further reading and references

* Kubernetes Services documentation: [https://kubernetes.io/docs/concepts/services-networking/service/](https://kubernetes.io/docs/concepts/services-networking/service/)
* Kubernetes networking concepts: [https://kubernetes.io/docs/concepts/cluster-administration/networking/](https://kubernetes.io/docs/concepts/cluster-administration/networking/)

That’s a concise overview of Kubernetes Services and how they provide stable network identities and routing to Pods.

> **[Watch Video](https://learn.kodekloud.com/user/courses/kubernetes-and-cloud-native-associate-kcna/module/aeecda11-7f2e-48c5-9c54-5409f2d9d8d8/lesson/d007e0dc-bd68-4ea6-9f5d-20278c5cbc71)**


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.