
🌐 What is a Service in Kubernetes?
A Service is an abstraction that defines a stable way to access a set of Pods (usually grouped by a label selector). It exposes an application running in your cluster behind a single outward-facing endpoint, even when the workload is split across multiple backends.
Since Pods are ephemeral (they come and go), a Service ensures that your app always has a reliable network endpoint — even when Pods are recreated or rescheduled.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app.kubernetes.io/name: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
🔍 Key Characteristics
Feature | Description |
Stable IP and DNS | Services expose a constant virtual IP (ClusterIP) and DNS name. |
Load Balancing | Distributes traffic across matching Pods. |
Selector-based | Uses labels to find the target Pods. |
Decouples Clients | Clients don't need to know Pod IPs — just talk to the Service. |
Multiple Types | Different types let you expose services internally or externally. |
📦 Service Types

1. ClusterIP (default)
- Internal-only access.
- Exposes service on a cluster-internal IP.
- Cannot be accessed from outside the cluster.
➡️ Example: Frontend app talking to a backend service.
apiVersion: v1
kind: Service
metadata:
name: my-backend-service
spec:
type: ClusterIP # Optional field (default)
clusterIP: 10.10.0.1 # within service cluster ip range
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080

2. NodePort
- Exposes the service on each Node’s IP at a static port.
- Can be accessed externally using NodeIP:NodePort.

➡️ Example: Testing service externally on a fixed port.
apiVersion: v1
kind: Service
metadata:
name: my-frontend-service
spec:
type: NodePort
selector:
app: web
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080
nodePort: 30000 # 30000-32767, Optional field

3. LoadBalancer
- Integrates with cloud providers to create an external load balancer.
- Exposes service to the internet with an external IP.
➡️ Example: When you are using a cloud provider to host your Kubernetes cluster.
apiVersion: v1
kind: Service
metadata:
name: my-frontend-service
spec:
type: LoadBalancer
clusterIP: 10.0.171.123
loadBalancerIP: 123.123.123.123
selector:
app: web
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080

4. ExternalName
- Maps a service to an external DNS name instead of routing to Pods.
- No selector or pods involved.
➡️ Example: Accessing an external database via a local service name.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: ExternalName
externalName: my.database.example.com
🧠 Bonus: Headless Service
- Set clusterIP: None
- Directly returns Pod IPs instead of a proxy IP.
- Used with StatefulSets or for service discovery.
References
- Kubernetes — Service Types Overview | by Ashish Patel | DevOps Mojo | Medium
-
Powered by. ChatGPT
'CS > Kubernetes' 카테고리의 다른 글
[Kubernetes] Scheduling(2) (0) | 2025.04.04 |
---|---|
[Kubernetes] Scheduling(1) (0) | 2025.04.04 |
[Kubernetes] Replicaset & Deployment (1) | 2025.03.27 |
[Kubernetes] YAML (1) | 2025.03.27 |
[Kubernetes] Kubernetes concepts (1) | 2025.03.27 |

🌐 What is a Service in Kubernetes?
A Service is an abstraction that defines a stable way to access a set of Pods (usually grouped by a label selector). It exposes an application running in your cluster behind a single outward-facing endpoint, even when the workload is split across multiple backends.
Since Pods are ephemeral (they come and go), a Service ensures that your app always has a reliable network endpoint — even when Pods are recreated or rescheduled.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app.kubernetes.io/name: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
🔍 Key Characteristics
Feature | Description |
Stable IP and DNS | Services expose a constant virtual IP (ClusterIP) and DNS name. |
Load Balancing | Distributes traffic across matching Pods. |
Selector-based | Uses labels to find the target Pods. |
Decouples Clients | Clients don't need to know Pod IPs — just talk to the Service. |
Multiple Types | Different types let you expose services internally or externally. |
📦 Service Types

1. ClusterIP (default)
- Internal-only access.
- Exposes service on a cluster-internal IP.
- Cannot be accessed from outside the cluster.
➡️ Example: Frontend app talking to a backend service.
apiVersion: v1
kind: Service
metadata:
name: my-backend-service
spec:
type: ClusterIP # Optional field (default)
clusterIP: 10.10.0.1 # within service cluster ip range
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080

2. NodePort
- Exposes the service on each Node’s IP at a static port.
- Can be accessed externally using NodeIP:NodePort.

➡️ Example: Testing service externally on a fixed port.
apiVersion: v1
kind: Service
metadata:
name: my-frontend-service
spec:
type: NodePort
selector:
app: web
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080
nodePort: 30000 # 30000-32767, Optional field

3. LoadBalancer
- Integrates with cloud providers to create an external load balancer.
- Exposes service to the internet with an external IP.
➡️ Example: When you are using a cloud provider to host your Kubernetes cluster.
apiVersion: v1
kind: Service
metadata:
name: my-frontend-service
spec:
type: LoadBalancer
clusterIP: 10.0.171.123
loadBalancerIP: 123.123.123.123
selector:
app: web
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080

4. ExternalName
- Maps a service to an external DNS name instead of routing to Pods.
- No selector or pods involved.
➡️ Example: Accessing an external database via a local service name.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: ExternalName
externalName: my.database.example.com
🧠 Bonus: Headless Service
- Set clusterIP: None
- Directly returns Pod IPs instead of a proxy IP.
- Used with StatefulSets or for service discovery.
References
- Kubernetes — Service Types Overview | by Ashish Patel | DevOps Mojo | Medium
-
Powered by. ChatGPT
'CS > Kubernetes' 카테고리의 다른 글
[Kubernetes] Scheduling(2) (0) | 2025.04.04 |
---|---|
[Kubernetes] Scheduling(1) (0) | 2025.04.04 |
[Kubernetes] Replicaset & Deployment (1) | 2025.03.27 |
[Kubernetes] YAML (1) | 2025.03.27 |
[Kubernetes] Kubernetes concepts (1) | 2025.03.27 |