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



No comments:

Post a Comment

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...