ClusterIP expose service nội bộ trong cluster. NodePort mở port trên nodes. LoadBalancer yêu cầu cloud/load balancer provider tạo load balancer bên ngoài. ExternalName map service sang DNS name ngoài cluster.
Ví dụ ClusterIP:
yaml
apiVersion: v1
kind: Service
metadata:
name: api
spec:
selector:
app: api
ports:
- port: 80
targetPort: 8000Phần quan trọng là selector phải match labels của Pods, nếu không Service sẽ không có endpoints.
ClusterIP exposes a service inside the cluster. NodePort opens a port on nodes. LoadBalancer asks the cloud/load balancer provider to create an external load balancer. ExternalName maps a service to an external DNS name.
ClusterIP example:
yaml
apiVersion: v1
kind: Service
metadata:
name: api
spec:
selector:
app: api
ports:
- port: 80
targetPort: 8000The key point is that the selector must match Pod labels, otherwise the Service has no endpoints.