Day 33 Task: Working with Namespaces and Services in Kubernetes.

What Is a Kubernetes Namespace?

A Namespace is a Kubernetes object that helps group and structure other Kubernetes objects and partitions them in a Kubernetes cluster. This concept allows you to organize or isolate your Kubernetes resources in a box-like form according to their purpose across multiple users and projects in a cluster.

Characteristics of Kubernetes Namespaces:

  • It provides scope for names

  • It has unique names for resources within but not across namespaces

  • It does not allow for nesting inside each other

  • It is used in an environment with many users spread across multiple teams and projects

  • A Kubernetes object can only be in one Namespace.

Task 1:

Create a Namespace for your Deployment

Use the below command to create a Namespace

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.

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

What is a Service in Kubernetes?

For Kubernetes, a service is an abstraction that represents a set of logical pods where an application or component is running, as well as embedding an access policy to those pods. Actual pods are ephemeral, Kubernetes guarantees the availability of pods and replicas specified but not the liveliness of each individual pod. This means that other pods that need to communicate with this application or component cannot rely on the underlying individual pod’s IP addresses.

A service gets allocated a virtual IP address as well (called a clusterIP in Kubernetes), and lives until explicitly destroyed. Requests to the service get redirected to the appropriate pods, thus the service serves as a stable endpoint used for inter-component or application communication. For Kubernetes-native applications, requests can also be made via an API in Kubernetes’ apiserver which automatically exposes and maintains the actual pods endpoints at any moment.

What is a Load Balancing in Kubernetes?

A load balancer service acts as a traffic controller, routing client requests to the nodes capable of serving them quickly and efficiently. When one host goes down, the load balancer redistributes its workload among the remaining nodes. On the other hand, when a new node joins a cluster, the service automatically starts sending requests to PODs attached to it.

In Kubernetes clusters, a Load Balancer service performs the following tasks:

  • Distributing network loads and service requests efficiently across multiple instances

  • Enabling autoscaling in response to demand changes

  • Ensuring High Availability by sending workloads to healthy PODs

What is a Networking in Kubernetes?

Networking in Kubernetes is responsible for providing network connectivity between pods and between the cluster and external networks. This includes routing, IP address management, and network policy enforcement. In Kubernetes, networking is implemented using plugins that integrate with the underlying network infrastructure.

In summary, services, load balancing, and networking are key components in the infrastructure of a Kubernetes cluster, and they are essential for providing communication, stability, and security in a distributed application environment.

Thank you for reading!! I hope you find this article helpful......