Kubernetes

 


Kubernetes:

Kubernetes is a container orchestration tool. Also referred to as "k8s"

Components of k8s:

> Pod: Pod is the smallest unit of k8s, Abstraction over a container (layer over a container). Usually, one application per Pod is configured. Each Pod gets its own IP address.

> Service: Service is a network endpoint to connect to a pod. Pods can die easily, and a new one will get created in its place. and a new IP address is assigned. So we have a "Service" component. The service IP address will be constant even if the pod gets recreated. It also acts as a Loadbalancer.

        - External service:

        - Internal service:

> Ingress: For defining URL instead of IP address. Request first goes to Ingress then to Service. It routes traffic into the k8s cluster. 

> configMap: External configuration of your application will be saved in configMap. It is connected to the Pod.

> Secret: It is the same as configMap but used to store secret data, credentials. and these data will be saved in "base64" format. We can use this data as environment variables in the container.

> volumes: It attaches physical storage on a Pod or can attach cloud storage to the Pod.       

> Deployment: It's another layer on top of pods. We always create deployments and internally it will create replicaset and Pod.   


K8s Cluster:



Master node:

Every master node must run below four processes.

    Api server: It's a cluster gateway, acts as a gatekeeper for authentication.

    Scheduler: It will just decide on which worker node the pod should be scheduled. Based on the resources available on all the nodes and sends the request to the kubelet on that worker node.

    Controler manager: Detects cluster state change. If a pod gets destroyed, this will detect and sends the request to the scheduler to recreate the pod.

    etcd: It's a cluster brain. It's a key-value store. All the information about the cluster is saved in etcd.


Worker node:

Below three processes must be installed on a worker node.

    Container runtime: docker

    Kubelet: It interacts with both the container and the node. Its Kubernetes API, Its CLI to configure Kubernetes and manage apps

    Kube proxy: Forwards the requests.

Kubernetes setup:

There are multiple ways to set up Kubernetes, listed few below:

    Minikube:    It creates 1 node Kubernetes cluster, everything in one node. It requires a Hypervisor to be installed.

    KOPS: It's a multi-node Kubernetes cluster on AWS. It's a production-grade k8s cluster.

    kubeadm:    Its multi-node Kubernetes cluster anywhere. 

    Docker Desktop:    This docker package also includes kubernetes setup. It creates one node K8s cluster similar to Minikube. It also requires a Hypervisor to be installed. Best setup for testing and learning k8s. Download the setup for Windows and Mac from here.


To show the client version and the server version.

$ kubectl version

To show all the components in the cluster.

$ kubectl get all

To show all the pods 

$ kubectl get pods

To show all the pods full details

$ kubectl get pods -o wide

To show all the nodes

$ kubectl get nodes

To show all the services

$ kubectl get services

To show all the deployments

$ kubectl get deployment

To show all the ReplicaSets

$ kubectl get replicaset

To change the replicas of Pod.

$ kubectl scale deployment $deployment_name --replicas $number_of_replicas

To show all the secrets

$ kubectl get secret

To create a deployment with the mentioned image.

$ kubectl create deployment $deployment_name --image=$image_name

To show logs of a pod

$ kubectl logs $pod_name

To show all the config details of a pod

$ kubectl describe pod $pod_name

To open an interactive shell to the container.

$ kubectl exec -it $pod_name -- bin/bash

To show all the details about a service.

$ kubectl describe service $service_name

To delete the deployment, replicaset, and pod.

$ kubectl delete deployment $deployment_name

To create all the resources from a config file.

$ kubectl apply -f $file_name.yaml

To delete all the resources from a config file.

$ kubectl delete -f $file_name.yaml

Outputs updated config of the deployment from the "etcd", from here we can get the status of the deployment.

$ kubectl get deployment nginx-deployment -o yaml

To create a namespace.

$ kubectl create namespace $namespace_name

To show all the namespaces.

$ kubectl get namespace

To create any resource in a specific namespace, give "--namespace" or "-n" option.

$ kubectl create deployment $deployment_name --image=$image_name -n $namespace_name

To show any resource created in a specific namespace.

$ kubectl get deployment -n $namespace_name


Comments