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 -y
sudo wget
https://github.com/kubernetes/kops/releases/download/v1.16.1/kops-linux-amd64sudo chmod +x kops-linux-amd64
sudo 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 [storage.googleapis.com/kubernetes-release/r.. -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.local
Expose 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 export
KOPS_STATE_STORE=s3://kops2024.k8s.local
source .bashrc
Create sshkeys before creating cluster
ssh-keygen
Create 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....pub
Create Kubernetes cluster
kops update cluster ${NAME} --yes
OR
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 cluster
To list nodes
kubectl get nodes
To 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.