# Day 34 Task: Working with Services in Kubernetes

## **Introduction**

Congratulations on mastering Deployments in Kubernetes on Day-33! Today, we'll dive into the world of Kubernetes Services and explore how they provide stable network identities to Pods while abstracting away the complexities of IP addresses.

## **Task-1: Creating a Service for your todo-app Deployment**

### **1.1 Service Definition (service.yml)**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702581731139/ff05b54f-8ac2-4c2b-a946-d4ae23fe6c77.png align="center")

### **1.2 Applying the Service Definition**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702582057035/a8a56c46-556b-4da0-8cee-d0febab343a8.png align="center")

### **1.3 Verifying Service Functionality**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702582074386/7b6a9b85-e0ba-47b3-9980-db596b00f98a.png align="center")

## **Task-2: Creating a ClusterIP Service**

### **2.1 ClusterIP Service Definition (cluster-ip-service.yml)**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702581731139/ff05b54f-8ac2-4c2b-a946-d4ae23fe6c77.png align="center")

### **2.2 Applying the ClusterIP Service Definition**

```bash
bashCopy codekubectl apply -f cluster-ip-service.yml -n <namespace-name>
```

### **2.3 Verifying ClusterIP Service Functionality**

```bash
bashCopy codekubectl run -it --rm --image=alpine test-pod -- sh
curl todo-app-clusterip-service.<namespace-name>.svc.cluster.local:80
```

## **Task-3: Creating a LoadBalancer Service**

### **3.1 LoadBalancer Service Definition (load-balancer-service.yml)**

```yaml
apiVersion: v1
kind: Service
metadata:
  name: todo-app-loadbalancer-service
spec:
  selector:
    app: todo-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: LoadBalancer
```

### **3.2 Applying the LoadBalancer Service Definition**

```bash
bashCopy codekubectl apply -f load-balancer-service.yml -n <namespace-name>
```

### **3.3 Verifying LoadBalancer Service Functionality**

```yaml
kubectl get svc -n <namespace-name>  # Note down the EXTERNAL-IP
curl <EXTERNAL-IP>:80
```

## **Conclusion**

In this tutorial, we explored the creation of Kubernetes Services for your todo-app Deployment, including ClusterIP and LoadBalancer types. By following these steps, you've successfully abstracted away the details of Pod IP addresses and created stable network identities for your application.
