==================== Kuberetes (k8s) ==================== Note: To learn kubernetes pre-requisite is Docker. => Docker is a containerization s/w => Docker is free & open source s/w => Using Docker we will package our "application code + application dependencies" as single unit for execution. That is called as Docker Image. => Once docker image is created then we can run that image in any machine without bothering about underlying softwares. Note: Docker will take care of s/w installation which are required to run our application. => Docker is used to run our app in any machine. ============= Kubernetes ============= => It is free and open source s/w => K8S developed by google company => K8S is used for Orchestration Note: Orchestration means management. => K8S is used to manage docker containers. Ex : create , stop, start, delete, scale up, scale down... =============== K8S Advantages =============== 1) Orchestration : Manage containers 2) Self Healing : If container damanged then it will create new one. 3) Load Balancing : Distribute requests to all running containers 4) Auto Scaling : Scale up and scale down containers on demand basis. ================= K8S Architecture ================= 1) Control Plane (Master Node) - API Server - Schedular - Controller Manager - ETCD 2) Worker Nodes (Slave Nodes) - kubelet - kube proxy - Docker Engine - POD - Container => To deploy our application using k8s we need to communicate with control plane. => We will use KUBECTL (CLI) to communicate with control plane. => 'API Server' will recieve the request given by kubectl and it will store that request in ETCD with pending status. => 'ETCD' is an internal database of k8s cluster. => Schedular will identify pending requests available in ETCD and it will identify worker node to schedule the task. Note: Schedular will identify worker node using kubelet. => Kubelet is called as Node Agent. It will maintain all the worker node information. => Kube Proxy will provide network for the cluster communication. => Controller Manager will verify all the taks are working as expected or not. => In Worker Node, Docker Engine will be available to run docker container. => In K8s, container will be created inside POD. => POD is a smallest building block that we can create in k8s cluster. => Inside POD, docker container will be created. Note: In K8s, everything will be represented as POD only. ================== K8S Cluster Setup =================== 1) Self Managed Cluster (we are responsible for everything) a) MiniKube (single node) --> only for learning/practice b) Kubeadm (Multi Node) --> We have to setup everything 2) Cloud Provider Managed Cluster (ready made cluster) a) AWS EKS (Elastic K8S Service) b) Azure AKS (Azure K8s Service) c) GCP GKE (Google K8S Engine) Note: Provider Managed clusters are commercial. ============== AWS EKS Setup ============== 🔥 Kubernetes Cluster Setup (AWS EKS) Video : https://youtu.be/is99tq4Zwsc?si=EtkF5rYbU9ydF8h8 @@ Git Repo : https://github.com/ashokitschool/DevOps-Documents/blob/main/05-EKS-Setup.md ======================== K8S Core Components ======================== 1) POD 2) Deployment 3) Service ============== What is POD ? ============== => POD is a smallest building block that will be created in k8s cluster. => In k8s, everything will be represented/managed as a POD only. => Inside POD, container will be created. => POD is accessible only with in the cluster. => To access our application which is running inside the POD then we have to expose the PODS. => To expose PODS we will use k8s services. ============= K8S Services ============== => In k8s we have 3 types of services. 1) Cluster IP 2) Node Port 3) Load Balancer => ClusterIP is used to map all pods to single IP to access with in cluster. => To expose the pods outside cluster we can use NodePort service. Note: When we use NodePort service we can access PODS which are running in particular worker node only. => If we want to access all the pods running in all worker nodes then we will expose pods using LoadBalancer service. Note: When we use LoadBalancer, internally EKS will create AWS LBR to access our pods outside of the cluster. =================== What is Deployment =================== => Deployment is a k8s resource which is used to manage k8s pods lifecycle. ====================================================== Deploy Spring Boot application using AWS EKS Cluster ====================================================== Step-1 : Create Docker Image and push into docker hub account ### Docker Image : ashokit/sb-logger-app Step-2 : Create k8s manifest yml to deploy our application using 'k8s deployment resource' and expose our pods using 'k8s Load Balancer service'. --- apiVersion: apps/v1 kind: Deployment metadata: name: javawebdeploy spec: replicas: 2 strategy: type: RollingUpdate selector: matchLabels: app: javawebapp template: metadata: name: javawebpod labels: app: javawebapp spec: containers: - name: javawebappcontainer image: ashokit/sb-logger-app ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: javawebsvc spec: type: LoadBalancer selector: app: javawebapp ports: - port: 80 targetPort: 8080 ... # check pods running $ kubectl get pods # deploy application using yml $ kubectl apply -f $ kubectl get pods # check logs of the pod $ kubectl logs Note: Go to AWS EC2 and check Load Balancer created. Access application using LBR DNS URL. =========== Assignment =========== @@@ Jenkins + Docker + K8S Integration Project - Reference Video : https://youtu.be/llBvl_iSLDw => Create CI CD pipeline using jenkins with below stages Stage-1 : Git Clone Stage-2 : Maven Build Stage-3 : Build Docker Image Stage-4 : K8S Deployment ---------------------------------- final ci cd pipeline ----------------------------- pipeline { agent any tools{ maven "Maven-3.9.9" } stages { stage('git clone') { steps { git 'https://github.com/ashokitschool/maven-web-app.git' } } stage('Mvn Build'){ steps{ sh 'mvn clean package' } } stage('Build Image'){ steps{ sh 'docker build -t ashokit/webapp .' } } stage('Deployment'){ steps{ sh 'kubectl apply -f deployment.yml' } } } } ---------------------------------------------------------------------------