How to deploy a K8S cluster on AWS with kops
This article describe how to quickly deploy a workable K8S cluster on AWS.
Install the kubectl and kops binary on the machine
- Assume that you're using a Linux machine. Execute the following commands to install kubectl:
curl -Lo kubectl -s -L chmod +x ./kubectlsudo mv ./kubectl /usr/local/bin/kubectl- Execute the following commands to install kops:
curl -Lo kops -s | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64chmod +x ./kopssudo mv ./kops /usr/local/bin/
Setup the AWS environment on the machine
- Configure the aws env with the valid credentials:
aws configure- Create a dedicated IAM user with the necessary permissions to kops:
aws iam create-group --group-name kopsaws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonEC2FullAccess --group-name kopsaws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonRoute53FullAccess --group-name kopsaws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess --group-name kopsaws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/IAMFullAccess --group-name kopsaws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonVPCFullAccess --group-name kopsaws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonSQSFullAccess --group-name kopsaws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonEventBridgeFullAccess --group-name kopsaws iam create-user --user-name kopsaws iam add-user-to-group --user-name kops --group-name kopsaws iam create-access-key --user-name kops- Re-confugure the aws env with the newly created IAM users:
aws configure # Use your new access and secret key hereaws iam list-users # you should see a list of all your IAM users hereexport AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id)export AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key)
Create the S3 Buckets for the Cluster Store
- Create the s3 bucket for the cluster state store
aws s3api create-bucket \--bucket my-kops-k8s-state-store \--region us-east-1- Enable the versioning of the bucket in case you ever need to revert or recover a previous state store.
aws s3api put-bucket-versioning --bucket my-kops-k8s-state-store --versioning-configuration Status=Enabled- Create the bucket with the ACL as the cluster OIDC store
aws s3api create-bucket \--bucket my-kops-k8s-oidc-store \--region us-east-1 \--object-ownership BucketOwnerPreferredaws s3api put-public-access-block \--bucket my-kops-k8s-oidc-store \--public-access-block-configuration BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=falseaws s3api put-bucket-acl \--bucket my-kops-k8s-oidc-store \--acl public-read- Enable the encryption for the bucket as the cluster state store
aws s3api put-bucket-encryption --bucket my-kops-k8s-state-store --server-side-encryption-configuration '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'
Create your first K8S cluster with kops
- Export the env vars for your cluster
export NAME=mykopscluster.k8s.localexport KOPS_STATE_STORE=s3://my-kops-k8s-state-store
- Find the available AZ in the current region
aws ec2 describe-availability-zones --region us-east-1- Create the k8s cluster with kops
kops create cluster \--name=${NAME} \--cloud=aws \--zones=us-east-1a \--discovery-store=s3://my-kops-k8s-oidc-store/${NAME}/discovery- Confirm the final configuration to build the cluster
kops update cluster --name ${NAME} --yes --admin- Validate the cluster status till it's ready.
kops validate cluster --wait 10m- Check the node status
kubectl get nodes

- Check the system pod
kubectl -n kube-system get po

Cleanup
Delete the cluster simply with command below after it is used.
kops delete cluster --name ${NAME} --yesEnjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article