9 Steps to Setup Kubernetes on AWS using KOPS

InIn this article We are going to perform How to Setup Kubernetes on AWS using KOPS.

What is KOPS in Kubernetes?

Kops (Kubernetes Operations) used to you create, destroy, upgrade and maintain production-grade, highly available, Kubernetes clusters using command line.

Kubernetes KOPS Features

  • Automatic creation of Kubernetes clusters in AWS and GCE 
  • We can create multi master with HA
  • Automatic creation of VPC, Security Groups, etc., while creating Cluster
  • Support Public and Private DNS
  • Runs in Auto scaling
  • We can Add and Edit the Cluster configuration such as Master and worker nodes

Below are prerequisites to setup kubernetes on aws using kops.

  1. AWS account 
  2. Create a Domain to Access Kubernetes API
  3. Create a Hosted Zone in Route53 and point AWS nameserver to Domain
  4. Create a S3 bucket with Versioning Enabled to store Kubernetes Kops cluster state
  5. IAM user with full S3, EC2, Route53 and VPC access 
  6. Ubuntu 20.04/18.04/16.04 LTS with minimal installation
  7. AWS-CLI

Assuming you have created Ubuntu Instance in your AWS account.

Step 1: Install AWS CLI on Ubuntu

Download the aws cli bundle using below command

 sudo curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip 

Install the unzip and python on Ubuntu if not installed

 sudo apt install unzip python

Extract the aws cli bundle setup

 sudo unzip awscli-bundle.zip 

Configure the AWS CLI on Ubuntu

sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Verify the AWS CLI version

aws --version

Output:

aws-cli/1.18.97 Python/2.7.18rc1 Linux/5.4.0-1015-aws botocore/1.17.20

Step 2: Install Kubectl Binary with CURL on Ubuntu

Download kubectl binary with curl on Ubuntu using below command

sudo curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl

Make the kubectl binary executable

sudo chmod +x ./kubectl 

Move kubectl to /usr/local/bin/kubectl directory

sudo mv ./kubectl /usr/local/bin/kubectl 

Step 3: Install KOPS on Ubuntu Instance

Download the KOPS  setup on Ubuntu using curl

curl -LO 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-amd64

set the execution permission

sudo chmod +x kops-linux-amd64

move the kops to /usr/local/bin directory

sudo mv kops-linux-amd64 /usr/local/bin/kops 

Step 4: Creating Domain and Hosted Zone in AWS

Kubernetes kops need DNS to discover within cluster and to connect Kubernetes API Server from Clients

You can create either public or private hosted zone, if you created public hosted zone you have to point AWS nameservers in Domain.

Here We have domain in GoDaddy, created public hosted zone in AWS and pointed AWS nameservers in GoDaddy Domain

We have created domain k8s.fosstechnix.com,

Step 5: Create and configure IAM User in AWS

Create IAM user in AWS using login console -> IAM -> ADD User -> Username -> Select Programmatic access -> then you will get Access Key ID and Secret Access Key.

Configure AWS CLI with your Access Key ID,  Secret Access  key and region

aws configure

Step 6: Create IAM User with full S3, EC2, Route53 and VPC access in AWS

Now create IAM user with full S3, EC2, Route 53 and VPC access in your AWS account as shown below

  1. AmazonS3FullAccess 
  2. AmazonEC2FullAccess 
  3. AmazonRoute53FullAccess 
  4. IAMFullAccess 
  5. AmazonVPCFullAccess 

kubernetes kops IAM access

Step 7: Creating S3 Bucket using command line

Create the S3 bucket to store Kubernetes cluster states

aws s3 mb s3://k8s.fosstechnix.info

Enable versioning on S3 bucket

aws s3api put-bucket-versioning --bucket k8s.fosstechnix.info --versioning-configuration Status=Enabled

Export kops state

export KOPS_STATE_STORE=s3://k8s.fosstechnix.info

Step 8: Create SSH Keys

Create ssh keys on Ubuntu instance to exchange kubernetes cluster and connect

ssh-keygen 

Step 9: Setup Kubernetes on AWS using KOPS

Create Kubernetes  on AWS using Kops using below command

 kops create cluster --cloud=aws --zones=ap-south-1a --name=k8s.fosstechnix.info --dns-zone=k8s.fosstechnix.info --dns public

if you want to install calico networking along with setup of Kubernetes KOPS add –networking with calico as shown below

kops create cluster --cloud=aws --zones=ap-south-1a --networking calico --name=k8s.fosstechnix.info --dns-zone=k8s.fosstechnix.info --dns public

If you want to create K8s cluster using multimaster and different availability zone use below command

kops create cluster --cloud=aws --zones=ap-south-1a,ap-south-1b --networking calico --master-size t3.medium --master-count 3 --node-size t3.xlarge --node-count 3 --name=k8s.fosstechnix.info --dns-zone=k8s.fosstechnix.info --dns public 

Sample Output:

Must specify --yes to apply changes 

 Cluster configuration has been created. 

 Suggestions: 

 * list clusters with: kops get cluster 

 * edit this cluster with: kops edit cluster k8s.fosstechnix.info

 * edit your node instance group: kops edit ig --name=k8s.fosstechnix.info nodes 

 * edit your master instance group: kops edit ig --name=k8s.fosstechnix.info master-ap-south-1a-1 

 Finally configure your cluster with: kops update cluster --name k8s.fosstechnix.info --yes 

Configure the k8s kops cluster using below command,

kops update cluster k8s.fosstechnix.info --yes 

Sample Output:

Cluster is starting.  It should be ready in a few minutes. 

 Suggestions: 

 * validate cluster: kops validate cluster 

 * list nodes: kubectl get nodes --show-labels 

 * ssh to the master: ssh -i ~/.ssh/id_rsa [email protected]k8s.fosstechnix.info

 * the admin user is specific to Debian. If not using Debian please use the appropriate user based on your OS. 

 * read about installing addons at: https://github.com/kubernetes/kops/blob/master/docs/operations/addons.md

Validate the Kubernetes KOPS cluster

kops validate cluster 

To list the nodes

kubectl get nodes  

To get Cluster Information

kubectl cluster-info 

To delete Kubernetes KOPS cluster

kops delete cluster k8s.fosstechnix.info --yes 

Finally We have covered Setup Kubernetes on AWS using KOPS

Conclusion

We have covered How to Setup Kubernetes on AWS using KOPS, install kops, install kubectl, creating S3 bucket,

Related Articles:

How to Setup Kubernetes Dashboard

How To Setup Kubernetes Cluster Using Kubeadm on Ubuntu 18.04/16.04 LTS

Deploy to Kubernetes using Helm and GitLab

Reference:

Kubernetes Official Guide

Shivdas Kanade

I am Shivdas Kanade working as Senior Site Reliability Engineer(SRE) on Cloud, DevOps, Docker and Kubernetes . Believes in Sharing Knowledge.

2 thoughts on “9 Steps to Setup Kubernetes on AWS using KOPS”

    • Hello Ashwath,

      Please use below syntax for private DNS
      kops create cluster –cloud=aws –zones=ap-south-1a –name=k8s.fosstechnix.com –dns-zone=k8s.fosstechnix.com –dns private

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link