How I used KOPS To Setup a K8S Cluster in AWS

I'm a DevOps Engineer with a Passion for Cloud Technology and a Love for Teaching.
Step 1:
Create an Ubuntu EC2 instance in AWS
Step2:
Install AWSCLI
#Using snaps to install aws cli
sudo snap install aws-cli --classic#To verify the installation
aws --version
Manual Installation Using the AWS CLI Bundle
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
#after downloading the aws cli bundle , unzip the bundle unzip
#Run the installer with the correct python path
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws #Verify the installer aws --version
Install kops on ubuntu instance:
#Install wget if not installed
sudo apt install wget -ysudo wgethttps://github.com/kubernetes/kops/releases/download/v1.16.1/kops-linux-amd64sudo chmod +x kops-linux-amd64sudo mv kops-linux-amd64/usr/local/bin/kops#check the version
kops version#To check the installation path
which kops#output is like this: /usr/local/bin/kop
- Install kubectl
sudo curl -LO [https://storage.googleapis.com/kubernetes-release/release/$(curl](https://storage.googleapis.com/kubernetes-release/release/$(curl) -s https://storage.googleapis.com/kubernetesrelease/release/stable.txt)/bin/linux/amd64/kubectl/bin/linux/amd64/kubectl)
sudo chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
To check the version
kubectl version --client
- Create an IAM role from Console or CLI with below Policies.
AmazonEC2FullAccess
AmazonRoute53FullAccess
AmazonS3FullAccess
IAMFullAccess
AmazonVPCFullAccess
AmazonSQSFullAccess
AmazonEventBridgeFullAccess
create an S3 bucket Execute below command in KOPS Server use unique bucket name if you get bucket name exists error.
aws s3 mb s3://ex:
S3 bucket name should be unique across AWS
aws s3 mb s3://kops2024.k8s.localExpose environment variable:Add env variables in bashrc
vi .bashrc #Add the export command at the end of the file
Give Unique Name And S3 Bucket which you created.
export NAME=kops2024.k8s.local exportKOPS_STATE_STORE=s3://kops2024.k8s.localsource .bashrcCreate sshkeys before creating cluster
ssh-keygenCreate Kubernetes cluster definitions on S3 bucket
kops create cluster --zones=us-east-1 --networking weave --master-size t2.medium --master-count 1 --node-size t2.micro --node-count=2 --name=${NAME} --state=${KOPS_STATE_STORE}kops create secret --name=${NAME} sshpublickey admin -i /home/ubuntu/.ssh/id_ed255....pubCreate Kubernetes cluster
kops update cluster ${NAME} --yesOR
kops create cluster
--name=${NAME}
--cloud=aws
--zones=us-east-1aTo customize cluster configuration
kops edit cluster --name ${NAME}Validate your cluster(KOPS will take some time to create cluster ,Execute below command after few minutes 3-5 minutes)
kops validate clusterTo list nodes
kubectl get nodesTo Delete Cluster
kops delete cluster --name=${NAME} --state=${KOPS_STATE_STORE} --yes
Note: Operating a Kubernetes cluster on AWS incurs costs, so it’s advisable to delete your cluster once you’ve completed your experiments to avoid unnecessary expenses.



