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
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.

you can get cluster ip by running following command

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

you will get response like above screenshot.
Task 2) Create a LoadBalancer Service for accessing the todo-app from outside the cluster
- Create a YAML file called
load-balancer-service.ymland add the following contents:
apiVersion: v1
kind: Service
metadata:
name: node-app-lb
spec:
type: LoadBalancer
selector:
app: node-app
ports:
- protocol: TCP
port: 80
targetPort: 3000
- Save the file and apply the LoadBalancer service definition to your Kubernetes cluster using the following command:
kubectl apply -f load-balancer-service.yml -n my-namespac
- To verify that the LoadBalancer service is working, you can access the
todo-appfrom outside the cluster by using the external IP address assigned to the service. Run the following command to get the external IP:
kubectl get service todo-app-lb -n my-namespace
Open a web browser and enter the external IP address in the following format:
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.



