Saturday, September 28, 2024

AWS: EKS, Kubernetes (Home Lab)

 Launch ec2 instance and creates 3 machines







In Master machine: 

sudo su

wget https://raw.githubusercontent.com/akshu20791/Deployment-script/main/k8s-master.sh

ls -l

ls

chmod 777 k8s-master.sh

ls -l

./k8s-master.sh








node1 and node2

sudo su (if not done)

 wget https://raw.githubusercontent.com/akshu20791/Deployment-script/main/k8s-nodes.sh

ls

ls -l

chmod 777 k8s-nodes.sh

ls -l

./k8s-nodes.sh


Master configuration

## Install Docker

sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installDocker.sh -P /tmp

sudo chmod 755 /tmp/installDocker.sh

sudo bash /tmp/installDocker.sh

sudo systemctl restart docker.service



## Install CRI-Docker

sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installCRIDockerd.sh -P /tmp

sudo chmod 755 /tmp/installCRIDockerd.sh

sudo bash /tmp/installCRIDockerd.sh

sudo systemctl restart cri-docker.service



## Install kubernetes



sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installK8S.sh -P /tmp

sudo chmod 755 /tmp/installK8S.sh

sudo bash /tmp/installK8S.sh



## Initialize kubernetes Master Node

 

   sudo kubeadm init --cri-socket unix:///var/run/cri-dockerd.sock --ignore-preflight-errors=all



   sudo mkdir -p $HOME/.kube

   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

   sudo chown $(id -u):$(id -g) $HOME/.kube/config



   ## install networking driver -- Weave/flannel/canal/calico etc... 



   ## below installs calico networking driver 

    

   kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.1/manifests/calico.yaml


Node configuration

## Install Docker



sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installDocker.sh -P /tmp

sudo chmod 755 /tmp/installDocker.sh

sudo bash /tmp/installDocker.sh

sudo systemctl restart docker.service



## Install CRI-Docker



sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installCRIDockerd.sh -P /tmp



sudo chmod 755 /tmp/installCRIDockerd.sh

sudo bash /tmp/installCRIDockerd.sh

sudo systemctl restart cri-docker.service



## Install kuubernetes


## Install kubeadm,kubelet,kubectl

sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installK8S.sh -P /tmp

sudo chmod 755 /tmp/installK8S.sh

sudo bash /tmp/installK8S.sh







After k8s installation is done . we need to connect nodes with the master via tokens 

### generate token in master:  (run below command in k8s master) 


kubeadm token create --print-join-command 


## whatever token comes up ...copy the token and paste it in notepad and after that in the command you will see 6443 written ...after that paste --cri-socket unix:///var/run/cri-dockerd.sock

Now paste the tokens in the nodes one by one 


Create an Elastic Kubernetes Service cluster





Ater the EKS cluster is created then create the node group








#sudo su

# apt update

#we will now install aws cli


curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

apt install unzip -y

unzip awscliv2.zip

sudo ./aws/install


We will generate access key and secret access keys 

Go to iam -> go to user which is already created for you





We will connect this machine with eks cluster

aws eks --region example_region update-kubeconfig --name cluster_name












 vi pod1.yml

kind: Pod

apiVersion: v1

metadata:

  name: mypod

spec:

  containers:

    - name: c00

      image: ubuntu

      command: ["/bin/bash", "-c","while true; do echo hello world; sleep 10; done"] 









kubectl apply -f pod1.yml



kubectl get pods



Cloud: Terraform, Cloudformation (Home Lab)

 Create an EC2 instance by terraform code


-Create an ubuntu ec2 machine wherein I will install terraform to perform the tasks in the cloud

- Download terraform









sudo su


wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

sudo apt update && sudo apt install terraform















Lets now create  a directory inside the machine where we will write terraform scripts


# mkdir terraform 

# cd terraform


Generate an access key and secret key





Documentation : https://registry.terraform.io/providers/hashicorp/aws/latest/docs


nano connection.tf 

(remember that all the terraform scripts ends with .tf) 









Press x > y > enter

now, write the code to create ec2 instance via terraform
























resource "aws_instance" "web" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t3.micro"

  tags = {
    Name = "HelloWorld"
  }


















##now we have written two terraform files (tf). Execute them.


terraform init














terraform apply --auto-approve




























Resources created






Cloudformation

Create a cloudformation stack








Fork a GitHub repository














Back to cloudformation

sync from Git













specify stack details

-Link a Git repository
-Create a connection
-Connect to GitHub > install a new app


















































Go back to cloudfrmation page
Create Role





























Submit


























The machine is created via terraform cloud formation















Waviz Project: Building a Visualizer Without External Libraries

  Back in the day , music visualizers were magic. Whether it was the old Windows Media Player or Winamp, watching sound morph into motion fe...