# ๐Ÿ”— Services in Kubernetes (SVC) A **Service** in Kubernetes provides a stable networking interface to access a set of pods. It allows for decoupling between client applications and the underlying pods by using DNS names and selectors. --- ## ๐ŸŒ Service Basics ### ๐Ÿ“Œ Service Flow ``` Service โžก๏ธ Endpoint โžก๏ธ Pods ```` - Services abstract access to a group of pods. - Services automatically get a DNS name in the cluster. - They use selectors to route traffic to matching pods. --- ## ๐Ÿงญ Service Types 1. **ClusterIP** (default) - Accessible only within the cluster. 2. **NodePort** - Exposes the service on a static port on each node. 3. **LoadBalancer** - Provisions an external IP via a cloud provider to expose the service. --- ## ๐Ÿงช Useful Commands ### ๐Ÿ” Get Endpoints ```bash kubectl get ep -n ```` ### ๐Ÿ“„ Get Services ```bash kubectl get svc -n ``` --- ## ๐Ÿงพ Example Service Manifest ```yaml apiVersion: v1 kind: Service metadata: name: nginx namespace: ns labels: app: web-server spec: type: ClusterIP # Options: ClusterIP, NodePort, LoadBalancer selector: app: nginx ports: - name: http # Port name is optional but useful port: 80 # Service port targetPort: 8080 # Container port ``` > ๐Ÿ” **Note:** The `selector` must match pod labels for the service to route traffic correctly. > ๐Ÿง  **Tip:** Use `kubectl describe svc ` to troubleshoot or verify service-to-pod connectivity. > ๐ŸŒ Services are resolved by DNS using the format: `..svc.cluster.local`.