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:
Create a Namespace for your Deployment
Use the command
kubectl create namespace <namespace-name>
to create a NamespaceUpdate 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.
Let's start
Create a Namespace: Use the command below to create a namespace:
kubectl create namespace <namespace-name>
Verify the creation of the namespace by listing all namespaces:
kubectl get namespace
Update the Deployment YAML file: Update your
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: Apply the deployment using the following command:
kubectl apply -f deployment.yml -n <namespace-name>
or
assign namespace as default and you can use further command without namespace
kubectl config set-context --current --namespace=<name space name>
kubectl apply -f deployment.yml
Verify the Namespace: Check the status of the namespaces to ensure the new namespace is active:
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.
Read about Services, Load Balancing, and Networking in Kubernetes. Refer official documentation of kubernetes Link
Let's do task 2
Read about Services, Load Balancing, and Networking in Kubernetes. Refer official documentation of kubernetes Link
Key Points:
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.
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.
Load Balancing: Services automatically handle load balancing between pods to distribute traffic evenly.
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.
Ingress: Ingress is used to expose HTTP/HTTPS services with routing rules (like URL paths) and allows for more fine-grained traffic control.
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.
For more details, you can visit the official documentation of Kubernetes here: Kubernetes Networking and Services Documentation.
Thankyou for reading !!!!!!