How to Setup a Kubernetes Cluster in AWS using KOPS.

Michael Mensah
4 min readApr 10, 2022

--

The purpose of todays Mini Project with Mensah is to setup a Kubernetes cluster using the Kops method.

KOPS, also know as Kubernetes Operations, is an open-source project which helps you create, destroy, upgrade and maintain production-grade, highly available, Kubernetes cluster and is also used to provision cloud infrastructure. Please visit website to read more — https://kops.sigs.k8s.io/

  1. The first step in the process in setting up a cluster using the KOPS method is to create a Bootstrap Server. Bootstrap server can be your local system or an EC2 instance created in AWS. Bootstrap server is only needed to setup the K8s cluster by running the kops commands to initialize the cluster.

2. Install Kubectl with the command

  • curl -LO “https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl”
  • chmod +x kubectl
  • mv kubectl /usr/local/bin/kubectl

3. Install Kops

4. Create an IAM Role and attach the role to the K8 bootstrap server. This is because the Kops will need access to the cloud environment and resources and permissions to be able to create the cluster.

Attached the IAM Role created to the EC2 K8 bootstrap server.

5. Configure Route53

Custom domain is required to setup Kubernetes cluster using Kops, so that Kops can create required resource records in that domain in Route 53. example — “mensahdev.com”

Gossip is an alternate option if you want to deploy a cluster without custom domain in Route 53. To use gossip-based DNS, configure the cluster domain name to end with .k8s.local. example — “mensahcloud.k8s.local

6. Create Cluster State Storage (S3 Bucket)

To store the state of your cluster, and the representation of your cluster, we need to create a dedicated S3 bucket for kops to use. This bucket will become the source of truth for our cluster configuration.

7. Setup SSH Keys — SSH keys will be used by Kops to setup the Kubernetes cluster to have a custom authentication token to be generated between master and client.

Create SSH Keys by running “ssh-keygen -t rsa”, which creates keys in default location $HOME/.ssh.

8. Create cluster configuration

Congratulations!! You have setup all prerequisites on the bootstrap server.

We’re ready to start creating our k8s cluster! setup below environment variables to start creating cluster configuration.

Custom Domain

  1. export NAME= Your domain name
  2. export KOPS_STATE_STORE=s3://you bucket name

Gossip Domain — Am using the gossip domain because I don’t have a custom domain yet

  1. export NAME=mensahcloud.k8s.local
  2. export KOPS_STATE_STORE=s3://mybucketmensahcloud

9. Create a cluster

kops create cluster — — zones=us-east-1a,us-east-1b ${NAME}

10. Update the cluster with the command

kops update cluster — — name mensahdev.k8s.local — — yes — — admin

11. Nodes have been created. You have your Master and 2 worker nodes.

Kubectl get nodes — Master and 2 worker nodes

Kops also setup Auto Scaling groups.

12. Delete cluster.

kops delete cluster — — name=mensahcloud.k8s.local — — yes

Thank you for stopping by page. Much love and much appreciation.

--

--