Day 33 Task: Working with Namespaces and Services in Kubernetes

ยท

4 min read


Introduction

Today, in day 33 of our "90 Days of Challenge" blog series, we're exploring areas where Namespaces and Services in Kubernetes ๐ŸŒŒ Namespaces are performing within the critical internal functions of Kubernets, similar to environments around the city , which is capable of masting and managing plays an important role in the circulation patterns and environmental diversity. to set the namespace etc. It also includes navigating Kubernetes documentation for services, load balancing, and network performance. ๐Ÿ“š Armed with this knowledge, we are ready to upgrade our Kubernetes skills, enabling better application deployment and scalability. Letโ€™s embark on this journey of discovery and wealth! ๐Ÿš€


Namespaces

Namespaces in Kubernetes provide a tool to separate groups of objects in clusters. Object names can be unique within namespaces, but not across namespaces. Namespace-based scopes only apply to namespace-based objects (e.g. Deployments, Services, etc.) and not cluster-wide objects (e.g. StorageClass, Nodes, PersistentVolumes, etc.).

Initial namespaces

default

Kubernetes includes this namespace so that you can start using your new cluster without first creating a namespace.

kube-node-lease

This namespace holds Lease objects associated with each node. Node leases allow the kubelet to send heartbeats so that the control plane can detect node failure.

kube-public

This namespace is readable by all clients (including those not authenticated). This namespace is mostly reserved for cluster usage, in case that some resources should be visible and readable publicly throughout the whole cluster. The public aspect of this namespace is only a convention, not a requirement.

kube-system

The namespace for objects created by the Kubernetes system.

Working with Namespaces

Viewing namespaces

You can list the current namespaces in a cluster using:

kubectl get namespace

Setting the namespace for a request

To set the namespace for a current request, use the --namespace flag.

For example:

kubectl run nginx --image=nginx --namespace=<insert-namespace-name-here>
kubectl get pods --namespace=<insert-namespace-name-here>

Setting the namespace preference

You can permanently save the namespace for all subsequent kubectl commands in that context.

kubectl config set-context --current --namespace=<insert-namespace-name-here>
# Validate it
kubectl config view --minify | grep namespace:

Task 1 :

  • Create a Namespace for your Deployment

  • kubectl get namespace: This command is used to list all the namespaces present in your Kubernetes cluster. It provides information about the namespaces, including their names, status, and age.

  • kubectl get ns: This is a shorthand version of the previous command. It also lists all the namespaces in your Kubernetes cluster but uses the abbreviated form "ns" instead of "namespace".

  • kubectl create namespace node-app: This command creates a new namespace named "node-app" in your Kubernetes cluster. Namespaces are used to logically divide cluster resources, providing a way to organize and isolate them. In this case, you're creating a namespace specifically for managing resources related to a Node.js application (hence the name "node-app")

  •     kubectl get namespace
    

kubectl create namespace node-ap

Verify that the Namespace has been created by checking the status of the Namespaces in your cluster

kubectl get namespaces

Task 2:

Services in Kubernetes

Applications in Kubernetes draw access to clusters of Pods, providing a consistent way to expose them across the network. Each service defines a logical group of endpoints (usually Pods) and an access policy. For example, a 3-dimensional stateless image-workspace can be accessed via a Service without having to know the specific Pods behind it. The service decouples clients from backend implementation issues. Selectors are often used to define tasks to target specific types of Pods. Additionally, if your business uses HTTP, you can use Ingress to access web traffic. Ingress combines routing rules into a single object, making it easy to access multiple objects behind a single listener. For more advanced connection capabilities, the Gateway API provides extensions beyond Ingress and Service, allowing connection services to be configured within a cluster using CustomResourceDefinitions

Load Balancing:

    • Load balancing is a crucial aspect of Services in Kubernetes. When multiple Pods are behind a Service, Kubernetes automatically distributes incoming traffic among these Pods to prevent any single Pod from being overwhelmed.

      • Kubernetes uses a round-robin algorithm by default to distribute traffic evenly across Pods. It ensures high availability and scalability of applications by spreading the load across multiple instances.

Networking:

    • Networking in Kubernetes involves managing the communication between Pods, Nodes, and external systems.

      • Kubernetes networking encompasses various features such as network policies, which define rules for communication between Pods, and Ingress, which manages external access to services within the cluster.

      • Network plugins like Calico, Flannel, and Cilium handle networking in Kubernetes clusters, providing different functionalities and capabilities for networking and communication.

Conclusion

Namespaces and roles are the backbone of Kubernetes, empowering users to easily configure, manage, and run a variety of applications in a dynamic cloud-native environment If they provide strong access to namespaces , users can efficiently allocate resources, ensure separation and organization across tasks. Current services facilitate reliable connectivity and load balancing, enabling flexible deployments that effortlessly meet fluctuating demand. By optimizing these core features, Kubernetes users can unlock the full potential of containerized applications, driving speed, scalability and efficiency in todayโ€™s infrastructure landscapes

ย