Working with Namespaces and Services in Kubernetes (Part-4)

Amit ParadAmit Parad
3 min read

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.

  • We can deploy our code with help of yaml file in specific namespace with 2 ways

    1. Explicitly mention in command while applying with yaml (like below) kubectl apply -f deployment.yml -n <namespace-name>

Below in pod.yml file the namespace information is not available.

2. I have created namespace with "Kubectl create namespace"

  1. Updated the deployment.yml file to include the Namespace

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

Thank You!!

Happy Learning !!

0
Subscribe to my newsletter

Read articles from Amit Parad directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Amit Parad
Amit Parad

Experienced Cloud / DevOps Engineer with a passion for automating infrastructure and streamlining software delivery processes. Skilled in AWS, Docker, Kubernetes, CI/CD pipelines, Ansible, Terraform & Jenkins. Proven ability to collaborate with development, operations, and QA teams to ensure efficient and reliable deployments.