Getting Start with K8s || Basic

Getting Start with K8s || Basic

Kubernetes (also known as k8s or “kube”)?is an open source container orchestration platform that automates many of the manual processes involved in deploying, managing, and scaling containerized applications.

Originally developed and designed by engineers at Google as the Borg project, Kubernetes was donated to the Cloud Native Computing Foundation (CNCF) in 2015. Red Hat? was one of the first companies to work with Google on Kubernetes, even prior to launch, and has become the 2nd-most leading contributor to the Kubernetes upstream project.?

Kubernetes: Its flow the master and slave(worker) Node Architecture.

Master Node: Responsible for the management of Kubernetes cluster. Entry point for all administrative tasks.

Kubernetes can have single master node or can have multi master node


Master Node:

API Server: API server is the entry point for all the REST commands used to control the cluster. It Also interaction point of Kubernetes.

Kubernetes api server act as the front end for the Kubernetes cluster. The user management devices, third party tools command line interface all are talk to api server to interact with k8s cluster

Etcd: Distributed key-value store which stores the cluster state. Used as Back-End for K8s, provide high availability of data related to cluster State. If you lost your cluster you can recover from etcd. It should be externalized from master node if master node is down, you are not able to recover your cluster.

Scheduler: Regulates the tasks on slave nodes. Stores the resource usage information for each slave node

Controller: Runs multiple Controller utility in single process, Carry on Automated tasks in K8s Cluster.Controller watch the resource in the cluster using Kubernetes API.

Desired State vs Actual State:

  • In Kubernetes, the "desired state" is what you specify (e.g., in a YAML file), such as the number of replicas in a deployment.
  • The "actual state" is what the system is currently doing (e.g., how many replicas are running at any given time).
  • The controller's job is to ensure the desired state matches the actual state.

Controller Loop:

Controllers operate in a continuous loop, called the "reconciliation loop." The controller regularly checks the current state, compares it to the desired state, and then takes corrective action if there is a difference.

For example, if you set a deployment to have 3 replicas, but there are only 2 running, the controller will launch another pod to meet the desired count.

Types of Controllers: Kubernetes provides several types of controllers, each responsible for managing different aspects of the cluster. Some of the core controllers include:

  1. ReplicationController (deprecated in favor of Deployments) — Ensures that a specified number of pod replicas are running at any given time.
  2. DeploymentController — Manages rolling updates for deployments and ensures that the desired number of replicas are running.
  3. StatefulSetController — Manages the deployment and scaling of stateful applications, ensuring that pods have stable, unique identities.
  4. DaemonSetController — Ensures that a specified pod runs on all (or some) nodes in the cluster.
  5. JobController — Ensures that a specified number of pods are successfully completed for batch jobs.
  6. CronJobController — Manages the running of scheduled jobs (similar to cron jobs in Linux).
  7. ReplicaSetController — Ensures that a specified number of pod replicas are running at all times (ReplicaSet is often used by Deployments).
  8. NamespaceController — Manages namespaces and their cleanup.
  9. IngressController — Manages ingress resources and handles routing of external traffic to services inside the cluster.

How Controllers Work:

  1. Watch: Controllers watch the resources in the cluster (e.g., Pods, Deployments, etc.) using the Kubernetes API.
  2. Compare: They compare the current state with the desired state.
  3. Act: If there is a discrepancy, the controller takes action (e.g., create, update, delete resources) to bring the current state closer to the desired state.

Custom Controllers: Kubernetes also allows developers to create custom controllers. These controllers can extend Kubernetes' functionality to meet the specific needs of an application or service.

Worker Node:

It’s a physical server or you can say a VM where the container managed by cluster run. Worker node contain all the necessary service to manage. The networking between the containers, communicate with the master node and assign resource to the scheduled container.

Kubelet: K8s agent executed on the worker nodes that will direct communicate with master nodes api-server. Execution of ports and services of worker node it gets instruction from api server.

Kubelet gets the configuration of a pod from API server and ensuring that the describe containers are up and running.

Pods: It’s a group of one or more containers with shared storage/network and a specification for how to run the containers can share the same shared content and same IP but reach other pods via localhost

Single pod can run on multiple machines and single machine can run multiple pods.

90% - 95% of architecture follows single pod single container

Kube-Proxy: Kube-proxy runs on each node to deal with individual host sub-netting and ensure that the services are available to external parties

Kube-Proxy is a Kubernetes agent installed on every node in the cluster. It monitors the changes that happen to Service objects and their endpoints. If changes occur, it translates them into actual network rules inside the node.


Kubectl: Kubectl is a official CLI for K8s but you can also communicate via REST Api

Kubeadm : Simplifies the process?of building k8s Cluster.

Namespace: A virtual k8s cluster

Kubelet: Manages containers on an individual node.

Kompose: Helps to Translate Docker Compose file into K8s Object also ability to ship container docker compose to K8s.

Kustomize: Configuration management tool for K8s object Configuration, similar to helm and have availability to create re-usable templates for K8s.


Kubernetes Installation:

K8s can be installed in Two Ways-

·??????? Kubernetes HA Deployment ( 1-Master | 2-Worker )

Suitable for production like Setup

·??????? Single Node Deployment (Minikube K8s Cluster)

Suitable for Development for Development/Practice

kubectl is a command line tool that enables communications between the Kubernetes API and the control plane. kubectl allows application deployment, cluster resource management, and resource monitoring.

Kubernetes has become the go-to container orchestration platform for deploying, managing, and scaling containerized applications. In this guide, we’ll walk you through the process of setting up your development environment on Ubuntu and getting started with Kubernetes using kubectl, Docker, and Minikube.

Installing kubectl

Kubectl is the command-line tool used to interact with Kubernetes clusters. Let’s start by installing kubectl on Ubuntu:

Installing Docker

Docker is a popular platform for building, shipping, and running applications in containers. Let’s install Docker on Ubuntu:

sudo apt update         
sudo apt install docker.io -y 
sudo systemctl start docker 
sudo systemctl enable docker 
sudo apt install -y apt-transport-https ca-certificates curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - 
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list        

To verify the installation, run:

sudo snap install kubectl --classic        
kubectl version - -client        

Installing Minikube

Minikube is a tool that allows you to run Kubernetes clusters locally for development and testing purposes. Here’s how you can install Minikube on Ubuntu:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

sudo install minikube-linux-amd64 /usr/local/bin/minikube

minikube version        

Starting Minikube with Docker Driver

Now that we have Minikube installed, let’s start a Minikube cluster using the Docker driver:

minikube start --driver=docker

# If you encounter root privileges error, run:

minikube start --driver=docker --force

minikube status

kubectl cluster-info

kubectl config view

kubectl get nodes

kubectl get pods

minikube dashboard        

********** Interact Cluster Using KubeCtl **********

1. Use the kubectl create command to create a Deployment that manages a Pod. The Pod runs a Container based on the provided Docker image.

kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.10

root@minicube:~# kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.10        

deployment.apps/hello-node created

2. View the Deployment:

kubectl get deployments        
root@minicube:~# kubectl get deployments
NAME         READY   UP-TO-DATE   AVAILABLE   AGE
hello-node   1/1     1            1           110s        

3. View the Pod:

kubectl get pods

root@minicube:~# kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
hello-node-6fd4cc4555-zckbr   1/1     Running   0          2m47s        

4. Expose the Pod to the public internet using the kubectl expose command:

kubectl expose deployment hello-node --type=LoadBalancer --port=8080        
root@minicube:~# kubectl expose deployment hello-node --type=LoadBalancer --port=8080        

service/hello-node exposed?

root@minicube:~# kubectl get services
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
hello-node   LoadBalancer   10.100.223.219   <pending>     8080:31656/TCP   10s
kubernetes   ClusterIP      10.96.0.1        <none>        443/TCP          45m        

**The --type=LoadBalancer flag indicates that you want to expose your Service outside of the cluster.?

5. View the Service you created:

minikube service hello-node

root@minicube:~# minikube service hello-node        

|-----------|------------|-------------|---------------------------|

| NAMESPACE |??? NAME??? | TARGET PORT |??????????? URL??????????? |

|-----------|------------|-------------|---------------------------|

| default?? | hello-node |??????? 8080 | https://192.168.49.2:31656 |

|-----------|------------|-------------|---------------------------|

* Opening service default/hello-node in default browser...

? https://192.168.49.2:31656

CleanUP -

1. Remove service

kubectl delete service hello-node        

2. Remove Deployments-

kubectl delete deployment hello-node        
root@minicube:~# kubectl get deployment
NAME         READY   UP-TO-DATE   AVAILABLE   AGE
hello-node   1/1     1            1           21h         

To get information on Namespace

root@minicube:~# kubectl get namespaces
NAME                   STATUS   AGE
default                Active   23h
kube-node-lease        Active   23h
kube-public            Active   23h
kube-system            Active   23h
kubernetes-dashboard   Active   23h        

if did not get any pods from default information

root@minicube:~# kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
hello-node-6fd4cc4555-zckbr   1/1     Running   0          24h        

When you specify the namespace you will get more data

root@minicube:~# kubectl get pods --namespace kube-system
NAME                               READY   STATUS    RESTARTS        AGE
coredns-6f6b679f8f-hlfwb           1/1     Running   0               24h
etcd-minikube                      1/1     Running   0               24h
kube-apiserver-minikube            1/1     Running   0               24h
kube-controller-manager-minikube   1/1     Running   1 (24h ago)     24h
kube-proxy-wpzqj                   1/1     Running   0               24h
kube-scheduler-minikube            1/1     Running   0               24h
storage-provisioner                1/1     Running   19 (106m ago)   24h        

To get all namespace information

root@minicube:~# kubectl get pods --all-namespaces        

Create a namespace

root@minicube:~# kubectl create namespace levelup360
namespace/levelup360 created        

To verify

root@minicube:~# kubectl get namespaces
NAME                   STATUS   AGE
default                Active   24h
kube-node-lease        Active   24h
kube-public            Active   24h
kube-system            Active   24h
kubernetes-dashboard   Active   24h
levelup360             Active   25s        


Syed Asif Reza, PMP?,PMI-ACP?, ITIL?, AWS CSAA, CCP, PCVE V5, LCMC

Head of Solution Architecture, Presales, Transformation at Link3 Technologies Limited

4 个月

Very informative

回复

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

SHAHARIA SIFAT的更多文章

  • Kubernetes Cluster Management

    Kubernetes Cluster Management

    Prerequisites Two or more servers running Ubuntu 22.04.

  • Managing Data in Docker

    Managing Data in Docker

    Container Data Management Persistent Data Data Volumes Bind Mount point in Containers Container are immutable once…

    2 条评论
  • Install and Configure Fail2ban on Ubuntu

    Install and Configure Fail2ban on Ubuntu

    Any service that is exposed to the Internet is at risk of malware attacks. For example, if you are running a service on…

    2 条评论
  • CI/CD with Monitoring | Jenkins | Docker| Kubernetes| Monitoring | DevSecOps

    CI/CD with Monitoring | Jenkins | Docker| Kubernetes| Monitoring | DevSecOps

    Total Number of server 4 Server1: Jenkins, Docker, Trivy and Sonarqube Server2: Prometheus and Grafana Steps:- Step 1 —…

    1 条评论
  • Installing Docker on Windows Server 2022: A Step-by-Step Guide

    Installing Docker on Windows Server 2022: A Step-by-Step Guide

    Step 1: Install DockerMsftProvider Module To kickstart the installation process, we need to install the…

  • Prometheus

    Prometheus

    Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its…

    1 条评论
  • Docker Networks

    Docker Networks

    Docker networking is the system that allows communication between Docker containers and the outside world, including…

  • Elastic Stack 8 : Install Elasticsearch

    Elastic Stack 8 : Install Elasticsearch

    Import the Elasticsearch PGP Keyedit We sign all of our packages with the Elasticsearch Signing Key (PGP key D88E42B4…

    3 条评论

社区洞察

其他会员也浏览了