Namespaces and Services in K8s

Β·

3 min read

Namespaces and Services in K8s

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.

Task 1:

  • Create a Namespace for your Deployment.

  • Use the command kubectl create namespace <namespace-name> to create a Namespace.

  • Update 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.

    Step 1: First, we must have pre-installed Docker, Minikube and Kubectl in the instance like in the previous blog.

    Step 2: Get inside the folder named k8s-project.

    Step 3: Create namespace "django-todolist" by using the command kubectl create namespace <namespace_name> & kubectl get namespace to check the namespace.

    Step 4: Now update deployment.yaml file as shown below to include the namespace.

    Step 5: Apply this updated deployment file by using kubectl apply -f deployment.yaml -n <namespace_name> .

    Step 6: Verify the Namespace by checking the status of the namespace in the cluster

Task 2:

Read about Services, Load Balancing, and Networking in Kubernetes.

  • K8s Services provide a stable IP address and DNS name, load balancing, and network access to the Pods. They can also load balance traffic to multiple pods and expose your application to external clients. There are several types of services in Kubernetes, including ClusterIP, NodePort, LoadBalancer, ExternalName, and Headless Services. It has a crucial role in communication between different components in a cluster and ensures the availability and reliability of applications running on a Kubernetes cluster.

  • In Kubernetes, load balancing refers to distributing incoming network traffic evenly across multiple pods in a cluster The load balancing concept as we correlate with AWS autoscaling can be accomplished using various strategies, such as round-robin, random or specific connections. Kubernetes provides a built-in load-balancing solution through the use of Services. For load balancing external traffic, an ingress controller like Nginx, Traefik, etc. can be used.

  • Networking in Kubernetes refers to how pods and services communicate with each other, as well as with resources outside the cluster. The K8s networking model is based on the concept of a flat network, in which all pods can communicate with each other directly. Each pod is assigned a unique IP address, and communication between pods is achieved through IP-based network communication.

  • Hence we can summarize services, load balancing and networking as essential for providing communication, stability, and security in a distributed environment.

References

Namespace

Services, Load balancing and Networking

Video


Thanks for your valuable time reading my blog.

Keep motivated and Keep learning.

🍁 🍁 🍁 🍁 🍁

Β