Service Types
ClusterIP (Default)
Internal-only. Other pods in the cluster can reach it by name.
apiVersion: v1
kind: Service
metadata:
name: api
spec:
selector:
app: api
ports:
- port: 80
targetPort: 3000# Access from another pod
curl http://api.default.svc.cluster.local
# Or just
curl http://apiNodePort
Exposes the service on every node's IP at a static port (30000-32767):
apiVersion: v1
kind: Service
metadata:
name: api
spec:
type: NodePort
selector:
app: api
ports:
- port: 80
targetPort: 3000
nodePort: 30080Access at http://.
LoadBalancer
Creates a cloud load balancer (AWS ALB/NLB, GCP LB, Azure LB):
apiVersion: v1
kind: Service
metadata:
name: api
spec:
type: LoadBalancer
selector:
app: api
ports:
- port: 80
targetPort: 3000kubectl get svc api
# EXTERNAL-IP shows the load balancer addressWhen to Use Which
| Type | Use Case |
|---|---|
| ClusterIP | Internal microservice communication |
| NodePort | Development, bare-metal clusters |
| LoadBalancer | Production cloud deployments (one LB per service) |
| Ingress | Production (one LB, multiple services via routing) |
Master this topic with hands-on labs
Go beyond reading — build real projects in sandboxed environments with expert video guidance.
Browse Courses →Ingress
Route external traffic to multiple services through a single load balancer:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api
port:
number: 80
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
number: 80Install Ingress Controller
Ingress resources need a controller to work:
# Nginx Ingress Controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.10.0/deploy/static/provider/cloud/deploy.yaml
# Verify
kubectl get pods -n ingress-nginxTLS with Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
ingressClassName: nginx
tls:
- hosts:
- api.example.com
secretName: api-tls
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api
port:
number: 80Get weekly IT automation tips
Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.
Subscribe Free →Path-Based Routing
Route different paths to different services:
spec:
rules:
- host: example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api
port:
number: 80
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
number: 80Debugging Services
# Check endpoints (pods backing the service)
kubectl get endpoints api
# No endpoints? Labels don't match
kubectl get pods --show-labels
kubectl describe svc api
# Test from inside cluster
kubectl run curl --image=curlimages/curl --rm -it -- curl http://api
# Check Ingress
kubectl describe ingress app-ingress
kubectl get ingressRelated Posts
- Kubernetes Pod Troubleshooting for pod issues - kubectl Cheat Sheet for DevOps for essential commands - Local Kubernetes with Kind for testing locally -e ---
Ready to go deeper? Explore our hands-on DevOps courses — from Docker and Terraform to MLflow on Kubernetes.
Ready to learn by doing?
Stop reading tutorials — start building. Expert video courses with hands-on labs in real sandboxed environments.
Related Articles
Kubernetes Ingress Controllers Guide
Configure Kubernetes Ingress for HTTP routing. Nginx controller setup, TLS termination, path-based routing, and rate limiting.
Traefik Kubernetes Ingress Guide
Traefik is a cloud-native reverse proxy and ingress controller for Kubernetes. Learn how to configure routing, TLS termination, middlewares, and canary.
Kubernetes Service Types Explained
Kubernetes service types explained. ClusterIP, NodePort, LoadBalancer, ExternalName, and headless services with YAML examples.
Kubernetes Storage PV and PVC Guide
Kubernetes persistent storage explained: PVs, PVCs, StorageClasses, dynamic provisioning, StatefulSets, and backup strategies.
Kubernetes Troubleshooting Checklist
Kubernetes troubleshooting checklist. Pod failures, CrashLoopBackOff, networking issues, DNS resolution, and storage fixes.
Kubescape Kubernetes Security Scan
Kubescape scans Kubernetes clusters against NSA, MITRE, and CIS benchmarks. Learn how to audit cluster security, fix misconfigurations, and integrate.
Explore topics
Browse more articles on the topics covered here.