Discovering Kubernetes "Namespaces" Unveiling their advantages and understanding their necessity.
Kubernetes, also known as K8s, serves as an open-source container orchestration platform, streamlining the deployment, scaling, and administration of container-based applications. Within the Kubernetes environment, two pivotal elements—Namespaces and Services—play essential roles in structuring and presenting resources.
What are Namespaces and Services in k8s?
Kubernetes' Namespaces provide a means to organize and segregate resources within a cluster. They facilitate collaborative work among multiple teams, users, or applications within a Kubernetes cluster by creating virtual divisions.
Resources within one namespace remain isolated from those in other namespaces, even if they share the same name. Every Kubernetes resource, be it pods, services, or deployments, is associated with a namespace. Any resource generated without a specified namespace is automatically placed in the 'default' namespace, which Kubernetes creates by default for each cluster.
Today's task:
Task 1:
Create a Namespace for your Deployment
Use the command
kubectl create namespace <namespace-name>
to create a Namespace.-list all namespace with
kubectl get namespace
We can deploy our code with help of yaml file inspecific namespace with 2 ways
1) explicitly mention in command while applying with yaml (like below)
kubectl apply -f deployment.yml -n <namespace-name>
2) Update the deployment.yml file to include the Namespace
- In the above deploy.YAML file we have added namespace details in the metadata section.
- Apply the updated deployment using the command: Verify that the Namespace has been created by checking the status of the Namespaces in your cluster.
Task 2:
Read about Services, Load Balancing, and Networking in Kubernetes.
In Kubernetes, Services act as an abstract layer defining a logical grouping of Pods and their access policies. They facilitate seamless communication among cluster applications, shielding them from the complexities of individual Pod IP addresses. Services create stable endpoints for application connectivity, supporting dynamic scaling and failover.
Service types in Kubernetes:
ClusterIP: The default type, providing an internal stable IP address for inter-component communication within the cluster.
NodePort: Exposes the Service on a specific port across each node, enabling external access.
LoadBalancer: Automatically provisions an external load balancer to direct traffic, ideal for internet exposure.
ExternalName: Maps the Service to an externalName field, referencing services outside the cluster.
Load balancing
Load balancing,crucial for distributing incoming network traffic, is handled automatically by Services in Kubernetes. This ensures continuous availability and responsiveness, even during Pod failures or additions. Different load balancing strategies are employed based on the Service type:
Round Robin: Used by ClusterIP and NodePort Services, distributing requests among available Pods in a round-robin manner.
External Load Balancer: LoadBalancer type Services utilize external load balancers provided by cloud services for traffic distribution.
Kubernetes networking:
Pod-to-Pod Communication: Seamless communication between Pods within the same Node using their IP addresses, requiring no additional setup.
Service Discovery: DNS-based service discovery assigns each Service a DNS name resolving to its ClusterIP, simplifying discovery and connectivity for other components.
Ingress: Managed by Ingress controllers, allowing external access management, routing rules, SSL/TLS termination, and more.
Network Policies: Control the communication flow between Pods, defining rules for both ingress and egress traffic.
I trust today's blog has provided valuable insights, offering clarity on Kubernetes namespaces, load balancers, and networking concepts.
Thanks,
Kishor Chavan