The Next Frontier: Advancing Your Kubernetes Knowledge

The Next Frontier: Advancing Your Kubernetes Knowledge

In last blog we had learn about K8's architecture and installation, In this blog we will learn some advance part of Kubernetes.

Namespace Management:

Namespaces are virtual clusters within a Kubernetes cluster, allowing you to partition resources. namespace is logical entity which allows you to isolate your resources. (Pods, Volume, Deployment, Etc.). namespace is like group of pods, before creating pods you have to create namespace.

To create a namespace:

kubectl create namespace <namespace-name>

To list namespaces:

kubectl get namespaces

To switch to a different namespace:

kubectl config set-context --current --namespace=<namespace-name>

Understanding Manifest Files:

Manifest files in Kubernetes are YAML or JSON files that describe the desired state of Kubernetes resources such as Pods, Deployments, Services, and ConfigMaps. These files are used with the kubectl apply command to create, update, or delete resources in a Kubernetes cluster.

Pod:

A manifest file for a Pod looks like this:

apiVersion: v1
kind: Pod
metadata:
    name: test-pod
    namespace: #namespace_name
spec:
    containers:
        - name: my-container
        image: nginx:latest
        ports:
        - conatinerport: #container_port_no.

This manifest file describes a Pod named test-pod running an Nginx container.

For creating Pod you have run following command:

kubectl apply -f <file-name>

To list default namespace Pods in Master-Node:

kubectl get pods

To list specific namespace Pods in Master-Node:

kubect get pods -n <namespace-name>

To list Pods in detailed information:

kubectl get pods -n <namespace-name> -o wide

To enter in Pod:

kubectl exec -it <container-name> --bash

To delete Pod:

kubectl delete pod <pod-name> -n <namespace-name>

Deployment:

Deployment is configuration for pods. deployment provide declarative updates for pods and replica sets.

A manifest file for a Deployment looks like this:

apiVersion: apps/v1
kind: Deployment
metadata:
    name: #deployment_name
    namespace: #namespace_name
    labels:
        app: nginx
spec:
    replicas: 4 #no. of pods
    selector:
        matchLabels:
            app: nginx
    template:
        metadata:
            namespace: #namespace_name
            labels:
                app: nginx
        spec:
            containers:
            - name: my-container
            image: nginx:latest
            ports:
            - conatinerport: #container_port_no.

To create Deployment:

kubectl apply -f <file-name>

To list default namespace Deployment:

kubectl get deployment

To list specific namespace Deployment:

kubect get deployment -n <namespace-name>

To list Deployment in detailed information:

kubectl describe deployment <deployment-name> -n <namespace-name>

To change replica numbers:

kubectl scale deployment <deployment-name> --replicas=2 -n <namespace-name>

Service:

A manifest file for a Service looks like this:

apiVersion: v1
kind: Service
metadata:
    name: #service_name
    namespace: #namespace_name
spec:
    selector:
        app: nginx
    type: NodePort
    ports:
        - protocol: TCP
        port: 80 #node-port
        targetport: 80 #pod-port
        nodeport: 30007 #port range for nodeport 30000-32767

To create service:

kubectl apply -f <file-name>

ConfigMaps and Secrets:

ConfigMaps and Secrets are used to manage configuration data and sensitive information in Kubernetes. They can be mounted as volumes or passed as environment variables to Pods.

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
  key1: value1
  key2: value2

You can then use this ConfigMap in a Pod:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod-configmap
spec:
  containers:
  - name: my-container
    image: nginx:latest
    envFrom:
    - configMapRef:
        name: my-config

To delete Pod/Deployment/Service/ConfigMap:

kubectl delete -f <file-name>

In this blog post, we have explored some advanced Kubernetes configuration techniques using manifest files. Pods, Deployments, Services, and ConfigMaps are very powerful features that can help you manage and scale your containerized applications in Kubernetes effectively.

Kindly do follow and comment your doubts in comments section.

Thank You!