├── EKS-Setup.MD ├── README.md ├── helm-commands.MD ├── hpa ├── CPU-hpa.md ├── Metric-server.md └── memory-hpa.md └── jenkins ├── Docker-Setup.MD ├── Jenkins-setup-helm.MD ├── Jenkinsserver-Installation.MD └── Maven-Git-Setup.MD /EKS-Setup.MD: -------------------------------------------------------------------------------- 1 | # Setup Kubernetes on Amazon EKS 2 | 3 | You can follow same procedure in the official AWS document [Getting started with Amazon EKS – eksctl](https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html) 4 | 5 | #### Pre-requisites: 6 | - an EC2 Instance (Kubernetes Management Host) 7 | 8 | # 9 | 1. Install and setup kubectl on Management host 10 | a. Download kubectl version 1.19.6 11 | b. Grant execution permissions to kubectl executable 12 | c. Move kubectl onto /usr/local/bin 13 | d. Test that your kubectl installation was successful 14 | ```sh 15 | curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/kubectl 16 | chmod +x ./kubectl 17 | mv ./kubectl /usr/local/bin 18 | kubectl version --short --client 19 | ``` 20 | 2. Install and setup eksctl on Management Host 21 | a. Download and extract the latest release 22 | b. Move the extracted binary to /usr/local/bin 23 | c. Test that your eksclt installation was successful 24 | ```sh 25 | curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp 26 | sudo mv /tmp/eksctl /usr/local/bin 27 | eksctl version 28 | ``` 29 | 30 | 3. Create an IAM Role and attache it to EC2 instance Management Host 31 | `Note: create IAM user with programmatic access if your bootstrap system is outside of AWS` 32 | IAM user should have access to 33 | IAM 34 | EC2 35 | VPC 36 | CloudFormation 37 | 38 | 4. Create EKS cluster and nodes from EC2 Management Host 39 | ```sh 40 | eksctl create cluster --name cluster-name \ 41 | --region region-name \ 42 | --node-type instance-type \ 43 | --nodes-min 2 \ 44 | --nodes-max 2 \ 45 | --zones , 46 | 47 | example: 48 | eksctl create cluster --name cloudfreak-cluster \ 49 | --region ap-south-1 \ 50 | --node-type t2.medium \ 51 | ``` 52 | 53 | 5. To delete the EKS clsuter 54 | ```sh 55 | eksctl delete cluster cloudfreak-cluster --region ap-south-1 56 | ``` 57 | 58 | 6. Validate your cluster using by creating by checking nodes and by creating a pod 59 | ```sh 60 | kubectl get nodes 61 | kubectl run pod tomcat --image=tomcat 62 | ``` 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docs -------------------------------------------------------------------------------- /helm-commands.MD: -------------------------------------------------------------------------------- 1 | # Add stable to helm 2 | 3 | ```sh 4 | helm repo add stable https://charts.helm.sh/stable 5 | helm repo search 6 | 7 | helm install repo stable/ 8 | 9 | helm pull 10 | 11 | helm package 12 | 13 | helm uninstall RELEASE_NAME 14 | ``` 15 | -------------------------------------------------------------------------------- /hpa/CPU-hpa.md: -------------------------------------------------------------------------------- 1 | # Configure Horizontal Pod Autoscaler 2 | 3 | ## Modify deployment.yaml with Resource limits 4 | ```sh 5 | 6 | resources: 7 | limits: 8 | cpu: '1' 9 | memory: "500Mi" 10 | requests: 11 | cpu: '1' 12 | memory: "500Mi" 13 | ``` 14 | ## hpa.yaml file in helm chart 15 | ```sh 16 | apiVersion: autoscaling/v1 17 | kind: HorizontalPodAutoscaler 18 | metadata: 19 | name: petclicnic-hpa 20 | spec: 21 | maxReplicas: 5 22 | minReplicas: 1 23 | scaleTargetRef: 24 | apiVersion: extensions/v1beta1 25 | kind: Deployment 26 | name: petclinic-deployment 27 | targetCPUUtilizationPercentage: 50 28 | ``` 29 | ## Install siege package on K8 Master 30 | 31 | ### Siege is a stress tester for HTTP/HTTPS 32 | 33 | 34 | ### If EKS or AKS Management Host OS is RHEL, then execute below commands 35 | ```sh 36 | yum -y install epel-release 37 | yum -y install siege 38 | ``` 39 | ### If EKS Management Host OS is Amazon Linux, then execute below commands 40 | ```sh 41 | sudo amazon-linux-extras install epel 42 | yum install siege -y 43 | ``` 44 | ### Send fake load to Application URL 45 | ```sh 46 | siege -q -c 5 -t 2m http://ip:port 47 | q = quiet mode 48 | c = concurrent 49 | 2m = time period 50 | ``` 51 | -------------------------------------------------------------------------------- /hpa/Metric-server.md: -------------------------------------------------------------------------------- 1 | # Metric server is required for Horizontal Pod Autoscaler 2 | 3 | ## What is Metric Server? 4 | ```sh 5 | It collects metrics like CPU, memory or Disk IO consumption for containers or nodes, from the Summary API, exposed by Kubelet on each node. 6 | ``` 7 | 8 | ## Enable 4443 port on Master and Worker Nodes 9 | ```sh 10 | 4443 11 | ``` 12 | ## Clone Metric-server helm chart on K8 Master 13 | ```sh 14 | git clone https://github.com/prawinkorvi/metric-server.git 15 | ``` 16 | 17 | ## Create Metric Server 18 | ```sh 19 | kubectl create -f . 20 | kubectl top pods 21 | kubectl top nodes 22 | ``` 23 | 24 | -------------------------------------------------------------------------------- /hpa/memory-hpa.md: -------------------------------------------------------------------------------- 1 | # Auto scaling of Pods Based on Memory Utilization 2 | 3 | 4 | ## memory-hpa.yaml in Application Helm chart 5 | ```sh 6 | apiVersion: autoscaling/v2beta1 7 | kind: HorizontalPodAutoscaler 8 | metadata: 9 | name: petclinic-memory-hpa 10 | spec: 11 | maxReplicas: 5 12 | minReplicas: 1 13 | scaleTargetRef: 14 | apiVersion: extensions/v1beta1 15 | kind: Deployment 16 | name: petclinic-deployment 17 | metrics: 18 | - type: Resource 19 | resource: 20 | name: memory 21 | targetAverageUtilization: 50 22 | ``` 23 | 24 | ## Install stress package inside the Application pod 25 | ```sh 26 | apt-get update 27 | apt-get install stress 28 | ``` 29 | ## Execute stress command to increase memory utilization on pod 30 | ```sh 31 | stress --vm 1 --vm-bytes 250M 32 | ``` 33 | -------------------------------------------------------------------------------- /jenkins/Docker-Setup.MD: -------------------------------------------------------------------------------- 1 | ## Install Docker 2 | ```sh 3 | yum install docker 4 | systemctl start docker 5 | systemctl enable docker 6 | ``` 7 | 8 | ## provide permissions to jenkins user in jenkins server to access docker 9 | ```sh 10 | sudo groupadd docker 11 | sudo usermod -aG docker jenkins 12 | sudo chmod 777 /var/run/docker.sock 13 | ``` 14 | ## Add Jenkins user into sudoers file to get sudo access 15 | ```sh 16 | vi /etc/sudoers 17 | jenkins ALL=(ALL) NOPASSWD: ALL 18 | ``` 19 | 20 | 21 | -------------------------------------------------------------------------------- /jenkins/Jenkins-setup-helm.MD: -------------------------------------------------------------------------------- 1 | ### Jenkins server setup with Helm to deploy into Kubernetes cluster 2 | 3 | ## Download and Install helm 4 | ```sh 5 | curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 6 | chmod 700 get_helm.sh 7 | ./get_helm.sh 8 | ``` 9 | 10 | ## Test with helm command 11 | ```sh 12 | helm version 13 | helm list 14 | ``` 15 | 16 | ## Copy config file from EKS Management host to Jenkins home directory 17 | ```sh 18 | mkdir /var/lib/jenkins/.kube 19 | copy config file under .kube directory with jenkins ownership 20 | ``` 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /jenkins/Jenkinsserver-Installation.MD: -------------------------------------------------------------------------------- 1 | # Jenkins server Installation 2 | 3 | ### Prerequisites 4 | 1. EC2 Linux 7.x Instance 5 | 6 | 2. Java v11 7 | 8 | ## Install Java 9 | We will be using open java for our demo, Get latest version from http://openjdk.java.net/install/ 10 | ```sh 11 | yum install java-11* 12 | 13 | ``` 14 | 15 | ### Confirm Java Version 16 | Lets install java and set the java home 17 | ```sh 18 | java -version 19 | find / -name java-11* | head -n 4 20 | /etc/alternatives/java-11-amazon-corretto 21 | /etc/alternatives/java-11 22 | /usr/lib/jvm/java-11-amazon-corretto.x86_64 23 | /usr/lib/jvm/java-11-amazon-corretto 24 | 25 | vi .bash_profile 26 | JAVA_HOME=/usr/lib/jvm/java-11-amazon-corretto.x86_64 27 | export JAVA_HOME 28 | PATH=$PATH:$JAVA_HOME 29 | # To set it permanently update your .bash_profile 30 | source ~/.bash_profile 31 | ``` 32 | _The output should be something like this,_ 33 | ``` 34 | [root@~]# java -version 35 | openjdk version "11.0.17" 2022-10-18 LTS 36 | OpenJDK Runtime Environment Corretto-11.0.17.8.1 (build 11.0.17+8-LTS) 37 | OpenJDK 64-Bit Server VM Corretto-11.0.17.8.1 (build 11.0.17+8-LTS, mixed mode) 38 | ``` 39 | 40 | ## Install Jenkins 41 | You can install jenkins using the rpm or by setting up the repo. We will setup the repo so that we can update it easily in future. 42 | Get latest version of jenkins from https://pkg.jenkins.io/redhat-stable/ 43 | ```sh 44 | yum -y install wget 45 | wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo 46 | rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key 47 | yum -y install jenkins 48 | ``` 49 | 50 | ### Start Jenkins 51 | ```sh 52 | # Start jenkins service 53 | systemctl start jenkins 54 | 55 | # Setup Jenkins to start at boot, 56 | systemctl enable jenkins 57 | ``` 58 | 59 | #### Accessing Jenkins 60 | By default jenkins runs at port `8080`, You can access jenkins at 61 | ```sh 62 | http://YOUR-SERVER-PUBLIC-IP:8080 63 | ``` 64 | #### Configure Jenkins 65 | - The default Username is `admin` 66 | - Grab the default password 67 | - Password Location:`/var/lib/jenkins/secrets/initialAdminPassword` 68 | - `Skip` Plugin Installation; _We can do it later_ 69 | - Change admin password 70 | - `Admin` > `Configure` > `Password` 71 | - Configure `java` path 72 | - `Manage Jenkins` > `Global Tool Configuration` > `JDK` 73 | - Create another admin user id 74 | 75 | ### Test Jenkins Jobs 76 | 1. Create “new item” 77 | 1. Enter an item name – `My-First-Project` 78 | - Chose `Freestyle` project 79 | 1. Under Build section 80 | Execute shell : echo "Welcome to Jenkins Demo" 81 | 1. Save your job 82 | 1. Build job 83 | 1. Check "console output" 84 | -------------------------------------------------------------------------------- /jenkins/Maven-Git-Setup.MD: -------------------------------------------------------------------------------- 1 | # Install and Configure Maven & git in Jenkins server 2 | 3 | ## Install Maven 4 | ```sh 5 | yum install wget 6 | wget https://mirror.lyrahosting.com/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz 7 | tar -xvzf apache-maven-3.8.1-bin.tar.gz 8 | export M2_HOME=/opt/apache-maven-3.8.1 9 | export M2=$M2_HOME/bin 10 | PATH=$PATH:$M2 11 | # To set it permanently update your .bash_profile 12 | source ~/.bash_profile 13 | 14 | Validate Maven 15 | 16 | mvn version 17 | ``` 18 | 19 | ## Install git 20 | ```sh 21 | yum install git 22 | 23 | 24 | ``` 25 | 26 | ## Assign shell to jenkins user 27 | 28 | ```sh 29 | vi /etc/passwd 30 | change shell from /bin/false to /bin/bash 31 | ``` 32 | 33 | --------------------------------------------------------------------------------