Working with Namespaces and Services in Kubernetes. Day33 of 90daysofdevops under guidance of ShubhamLondhe.
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.
Create a namespace using the command “kubectl create namespace <name>” and give the command “kubectl get namespaces” to check whether a new namespace has been created or not.
Use the command
kubectl create namespace <namespace-name>
to create a NamespaceUpdate the deployment.yml file to include the Namespace
Apply the updated deployment using the command:
kubectl apply -f deployment.yml -n <namespace-name>
Verify that the Namespace has been created by checking the status of the Namespaces in your cluster.
To check the namespaces in the cluster run the following commands:
kubectl get namespaces
Task 2:
- Read about Services, Load Balancing, and Networking in Kubernetes.
Kubernetes Services, Load Balancing, and Networking are essential components for managing and connecting containerized applications within a cluster.
Services: A Kubernetes Service is an abstraction layer that defines a set of pods and the policies used to access them. Services provide a stable endpoint for accessing a set of pods. They abstract the underlying pod IP addresses, enabling seamless communication within the cluster and external access from outside.
Load Balancing: Load balancing is the process of distributing incoming network traffic across multiple backend servers to ensure that no single server is overwhelmed. In Kubernetes, this is typically achieved by using a Service of type LoadBalancer, which creates an external load balancer in the cluster's network and distributes traffic to the pods of the Service.
Networking: Kubernetes networking involves the interconnection of pods across the cluster. It utilizes a software-defined network (SDN) to assign unique IP addresses to pods and allows them to communicate seamlessly. The Container Network Interface (CNI) is a critical component that enables this. Networking policies can be enforced to control communication between pods and provide security.
In summary, Kubernetes Services, Load Balancing, and Networking collectively enable seamless communication, load distribution, and external access for containerized applications, making it a powerful platform for managing container workloads.