Create a Kubernetes cluster on AWS by kops

Ha Doan
3 min readFeb 9, 2020

--

  • kops helps you create, destroy, upgrade and maintain production-grade, highly available, Kubernetes clusters from the command line. It supports AWS, GCE, DigitalOcean, OpenStack. For more detail please check at https://github.com/kubernetes/kops. In this article, I’ll list out steps to create a K8s Cluster in AWS and running in EC2
  • Step 1: Create a bootstrap EC2 instance

Create a Linux bootstrap EC2 instance from AWS Console to run all commands, the instance type is t2.nano

  • Step 2: Install Kops in the bootstrap instance
curl -Lo kops https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d ‘“‘ -f 4)/kops-linux-amd64chmod +x ./kopssudo mv ./kops /usr/local/bin/
  • Step 3: Create IAM user account for kops by commands, you can also create users by going to AWS Console to create in Web UI.

After creating kops username, you get access key and secret key. Add these keys to Linux instance by running the commands

export AWS_ACCESS_KEY_ID=YOUR_KEY
export AWS_SECRET_ACCESS_KEY=YOUR_SECRET
  • Step 4: Create new S3 bucket from the AWS portal to store stages of kops, I name it example-state-store
  • Step 5: Set name and state store for kops
export NAME=your-cluster-name.k8s.local
export KOPS_STATE_STORE=s3://example-state-store
  • Step 6: Create new k8s Cluster by run kops command
kops create cluster — zones ap-southeast-1a,ap-southeast-1b,ap-southeast-1c ${NAME}

ap-southeast-1a,ap-southeast-1b,ap-southeast-1c are zones that you want to deploy EC2 instances, you can see all zone by run command

aws ec2 describe-availability-zones — region your-region (e.g ap-southeast-1)
  • Step 7: Edit your nodes or master

Edit your node by run command

kops edit ig nodes — name ${NAME}

for example, following is my edited configuration

You can also edit other instance groups, to list all instance groups run following command

kops get ig

Step 8: Generate ssh key and secret for kops

ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsakops create secret — name ${NAME} sshpublickey admin -i ~/.ssh/id_rsa.pub

Step 9: Deploy your k8s cluster by run command

kops update cluster — name ${NAME} — yes

Continuing to validate your cluster creation by command, after a few minutes you can see your cluster is up!

kops validate cluster

If success, go to EC2 instances to see all your results as below

Step 10: Delete your cluster

After testing deployment your cluster, you can delete by run

kops delete cluster — name ${NAME} — yes

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response