What are Namespaces and Services in k8s?
In Kubernetes, Namespaces are used to create isolated environments for resources. Each Namespace is like a separate cluster within the same physical cluster. Services are used to expose your Pods and Deployments to the network.
Today's task:
Task 1:
Create a Namespace for your Deployment
Use below command to create a Namespace
kubectl create namespace <namespace-name>
Update the deployment.yml file to include the Namespace
Apply the updated deployment using the command:
The kubectl apply command is used to create or update resources in a Kubernetes cluster. The -f flag is used to specify the file that contains the definition of the resources you want to create or update. The -n flag is used to specify the namespace in which the resources should be created or updated.
kubectl apply -f deployment.yaml -n <namespace-name>
Check pods and deployment created
Verify that the Namespace has been created by checking the status of the Namespaces in your cluster.
kubectl get namespaces
This will return a list of all namespaces in the cluster, including the one you just created. The status of the namespace should be Active, which indicates that it has been created and is ready to use.
Task 2:
Read about Services, Load Balancing, and Networking in Kubernetes.
Services:
Think of a Service in Kubernetes as a way to give a name and an address to a group of pods. Pods can come and go, but a Service provides a stable way for other parts of your application to find and connect to those pods. It's like a middleman that helps pods talk to each other, even if they're on different nodes.
Load Balancing:
Imagine you have multiple copies of your application running in different pods to handle lots of users. A Load Balancer in Kubernetes helps distribute incoming traffic evenly across these pods, making sure no single pod gets overwhelmed. It's like having a traffic cop that directs cars to different lanes so that the road doesn't get jammed.
Networking:
In Kubernetes, each pod gets its own unique IP address, and pods can communicate with each other over the network. Think of it like houses in a neighborhood having their own addresses to receive mail and talk to each other. Kubernetes handles setting up this network, so pods can find and talk to each other seamlessly.
In a nutshell:
Services: Helps pods communicate reliably and gives them a name and address.
Load Balancing: Shares incoming traffic among pods to keep everything running smoothly.
Networking: Makes sure pods have their own addresses and can talk to each other just like houses in a neighborhood.
Thanks for reading. Happy Learning.