Day 33 Task: Working with Namespaces and Services in Kubernetes

Day 33 Task: Working with Namespaces and Services in Kubernetes

ยท

3 min read

This is#90DaysofDevopschallengeunder the guidance ofShubhamLondhesir.

Introduction:

Welcome to Day 33 of your 90 Days of DevOps Challenge! Today, let's dive into Namespaces and Services in Kubernetes, two essential concepts that help manage and connect applications within a Kubernetes cluster.

Understanding Namespaces:

In Kubernetes, Namespaces serve as virtual clusters, enabling you to partition resources and logically isolate applications within a single physical cluster. Think of Namespaces as separate environments where you can deploy and manage your resources independently.

๐Ÿ’ก
Imagine your Kubernetes cluster as a big city, and Namespaces are like neighborhoods within that city. Each neighborhood (Namespace) contains its own set of resources and keeps them separate from other neighborhoods. This helps keep things organized and prevents one application from interfering with another.

Task 1: Creating a Namespace for Your Deployment

To create a Namespace, you use the kubectl create namespace command followed by the name you want to give your Namespace. Here's how you do it:

# Create a Namespace
kubectl create namespace <namespace-name>

apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: todo-app
    namespace: dev
    labels:
      app: todo
  spec:
    replicas: 2
    selector:
      matchLabels:
        app: todo
    template:
      metadata:
        labels:
          app: todo
      spec:
        containers:
        - name: todo
          image: estebanmorenoit/my-web-app
          ports:
          - containerPort: 3000

After creating the Namespace, you update your deployment configuration file (deployment.yml) to specify which Namespace your application should belong to. Then, you apply the changes using the kubectl apply command, like this:

# Apply the updated deployment
kubectl apply -f deployment.yaml -n dev

Make sure to check that the Namespace has been created successfully by looking at the list of Namespaces in your cluster.

kubectl get deployment -A

Exploring Services in Kubernetes:

Now, let's talk about Services. In Kubernetes, Services help your applications communicate with each other. They act as middlemen, making sure that traffic gets routed to the right places, even as your applications move around or change.

Task 2: Learning about Services, Load Balancing, and Networking

Take some time to explore Services, Load Balancing, and Networking in Kubernetes. The official Kubernetes documentation provides detailed explanations and examples to help you understand these concepts better.

Conclusion:

Namespaces and Services are crucial features in Kubernetes for organizing and connecting applications within a cluster. Namespaces create virtual clusters, isolating resources like neighborhoods in a city, ensuring efficient management and preventing interference. Services act as middlemen, directing traffic between applications, ensuring proper communication and scalability. Understanding and using Namespaces and Services effectively improves deployment efficiency and enhances performance in Kubernetes environments.

๐Ÿ’ก
If you have any questions, just leave them in the comments section. I'm here to help!
๐Ÿ’ก
If you found this post useful, please give it a thumbs up ๐Ÿ‘ and consider following for more helpful content. ๐Ÿ˜Š

Thanks for taking the time to read! ๐Ÿ’š[

](medium.com/tag/kubernetes?source=post_page-..)

Did you find this article valuable?

Support Akash Dhengale by becoming a sponsor. Any amount is appreciated!

ย