What are the different types of Services in Kubernetes?

Beginner

Answer

Service types determine how services are exposed:

  1. ClusterIP (default): Internal cluster access only
  2. NodePort: Exposes service on each node's IP at a static port
  3. LoadBalancer: Exposes service externally using cloud provider's load balancer
  4. ExternalName: Maps service to external DNS name
# NodePort Service
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: myapp
  ports:
  - port: 80
    targetPort: 8080
    nodePort: 30007