Day 33 Task: Working with Namespaces and Services in Kubernetes

Day 33 Task: Working with Namespaces and Services in Kubernetes

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. Namespaces are intended for use in environments with many users spread across multiple teams, or projects. Services are used to expose your Pods and Deployments to the network. Read more about Namespace Here

Today's task:

Task 1:

  1. Create a Namespace for your Deployment:

 kubectl create namespace <namespace-name>         

  • Update the deployment.yml file to include the Namespace.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-deployment
  namespace: deploy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: anandraval12/django-todo-app:latest
          ports:
            - containerPort: 8000        

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

kubectl get namespaces        

Task 2: Read about Services, Load Balancing, and Networking in Kubernetes

In Kubernetes, a Service is an abstraction that defines a logical set of Pods and a policy by which to access them. Services provide a stable IP address and DNS name, enabling reliable communication between different parts of an application. They also facilitate load balancing traffic across the Pods, ensuring even distribution of network traffic.

Key Points:

  1. Pod Communication: Each pod in Kubernetes gets a unique IP address, allowing direct communication between pods without the need for NAT (Network Address Translation), even if the pods are on different nodes.
  2. Services: A Service in Kubernetes allows you to expose a set of pods behind a stable, single IP or DNS name, enabling load balancing and internal/external access to your applications.
  3. Load Balancing: Services automatically handle load balancing between pods to distribute traffic evenly.
  4. Service Types: Different types of services (ClusterIP, NodePort, LoadBalancer) are available depending on whether you want the service to be accessible within the cluster or from outside.
  5. Ingress: Ingress is used to expose HTTP/HTTPS services with routing rules (like URL paths) and allows for more fine-grained traffic control.
  6. Network Policies: You can use Network Policies to control traffic flow between pods or between pods and external services at the IP address and port level.

Thank you for reading!

要查看或添加评论,请登录

Anand Raval的更多文章

社区洞察