Table of contents
- Day 34 Task: Working with Services in Kubernetes
- What are Services in K8s?
- Task-1:
- Task-2:
- Task-3:
- Create a LoadBalancer Service definition for your todo-app Deployment in a YAML file.
- Apply the LoadBalancer Service definition to your K8s (minikube) cluster using the command.
- Verify that the LoadBalancer Service is working by accessing the app from outside the cluster in your Namespace.
- Day 34 task is completed!
Day 34 Task: Working with Services in Kubernetes
Congratulation🎊 on your learning on Deployments in K8s on Day-33
What are Services in K8s?
In Kubernetes, Services are objects that provide stable network identities to Pods and abstract away the details of Pod IP addresses. Services allow Pods to receive traffic from other Pods, Services, and external clients.
Task-1:
Create a Service for your app Deployment to make it accessible from outside the cluster
Create a Service definition for your todo-app Deployment in a YAML file.
Apply the Service definition to your K8s (minikube) cluster using the command
kubectl apply -f service.yml -n <namespace-name>
kubectl apply -f service.yml -n test-ns
Verify that the Service is working by accessing the app using the Service's IP and Port in your Namespace.
As our app is running on pod and pod is running on Minikube and Minikube is running on ec2 instance. We have a service for directing traffic from minikube node to the container app. But minikube is itself running as virtualization on ec2 instance via docker engine. Hence we need to forward traffic from ec2 to minikube node--->
kubectl port-forward --address 0.0.0.0 svc/my-webapp-service --namespace test-ns 30430:80
Task-2:
Create a ClusterIP Service for accessing the app from within the cluster
Create a ClusterIP Service definition for your app Deployment in a YAML file.
Apply the ClusterIP Service definition to your K8s (minikube) cluster using the command.
kubectl apply -f cluster-ip-service.yml -n <namespace-name>
kubectl apply -f clusterIP-service.yml -n test-ns
Verify that the ClusterIP Service is working by accessing the todo-app from another Pod in the cluster in your Namespace.
kubectl port-forward --address 0.0.0.0 svc/my-webapp-service --namespace test-ns 8501:80
Task-3:
Create a LoadBalancer Service for accessing the app from outside the cluster
Create a LoadBalancer Service definition for your todo-app Deployment in a YAML file.
Apply the LoadBalancer Service definition to your K8s (minikube) cluster using the command.
kubectl apply -f load-balancer-service.yml -n <namespace-name>
kubectl apply -f loadbalancer-service.yml -n test-ns
Verify that the LoadBalancer Service is working by accessing the app from outside the cluster in your Namespace.
kubectl port-forward --address 0.0.0.0 svc/my-webapp-service --namespace test-ns 30430:80
Need help with Services in Kubernetes? Check out the Kubernetes documentation for assistance.
Happy Learning :)
Day 34 task is completed!
90DaysOfDevOps Tasks👇