# Day 34 : Working with Services in Kubernetes

Task 1 ) Create a Service for your todo-app Deployment

we need to create service.yml as below

```bash
apiVersion: v1
kind: Service
metadata:
  name: my-service
  namespace: my-namespace
spec:
  selector:
    app: node-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8000
```

you can apply the Service definition to your K8s (minikube) cluster using the `kubectl apply -f service.yml -n my-namespace` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685576459419/a68854b1-3ee8-446d-bcea-6e1dc07be24f.png align="center")

you can get cluster ip by running following command

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685576473052/504f444c-f0b5-465a-b5f7-4287aeff9b22.png align="center")

Now to check your application you need to do <mark>ssh to minikube </mark> and then run following command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685576517207/c642e323-0320-40f2-b171-92f82bacbc75.png align="center")

you will get response like above screenshot.

Task 2) Create a LoadBalancer Service for accessing the todo-app from outside the cluster

1. Create a YAML file called `load-balancer-service.yml` and add the following contents:
    

```bash
apiVersion: v1
kind: Service
metadata:
  name: node-app-lb
spec:
  type: LoadBalancer
  selector:
    app: node-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000
```

1. Save the file and apply the LoadBalancer service definition to your Kubernetes cluster using the following command:
    

```bash
kubectl apply -f load-balancer-service.yml -n my-namespac
```

1. To verify that the LoadBalancer service is working, you can access the `todo-app` from outside the cluster by using the external IP address assigned to the service. Run the following command to get the external IP:
    

```bash
kubectl get service todo-app-lb -n my-namespace
```

1. Open a web browser and enter the external IP address in the following format:
    
    ```bash
    http://your-inctance-ip:80
    ```
    

Congratulation your application is running on external IP

That was it for today. If you have queries /suggestions please comment below.

See you another day with another challenge, till then Keep Learning.
