Wednesday, August 12, 2020

KOPS Setup on AWS

Kops is one of the installation model for  Kubernetes,  Kops will use to setup the Kubernetes cluster on  Cloud computing technologies like  AWS,GCP,VMware and Azure doesn't support the KOPS till now.

AWS (Amazon Web Services) is currently officially supported, with GCE in beta support, and VMware vSphere in alpha.

kops helps us to create, destroy, upgrade and maintain production-grade, highly available, Kubernetes clusters from the command line.

in this post we will see how to setup the Kubernetes cluster by using KOPS on AWS.

in order to setup Kubernetes cluster by using KOPS we needed below configuration setup

  •  Purchase Domain name
  • AWS Account with one EC2 instance to install the KOPS and Kubectl binaries to manage the cluster.
  • integration DNS with your AWS account by using Route53
  • S3 bucket
  • Create IAM access and secret keys  & Awscli configure
  • Create SSH keys
  • Create the Cluster by Using Kops
Now we will discuss each step in details to make Kubernetes works by KOPS.

1. Purchase Domain Name 

If you bought a domain with AWS, then you should already have a hosted zone in Route53, or if you not registered for domain for your own please follow.

Purchase one Domain Name from Godaddy or any other DNS providers, in my case i used sra1k8s.xyz(.xyz is lesser on cost)

2. Create EC2 Instance:

Launch one t2.micro Ec2 instance and login to the box with root(K8S-mgnt-instance) and execute the below commands to install Kubectl and KOPs binaries.

Kops:

wget https://github.com/kubernetes/kops/releases/download/v1.18.0-beta.1/kops-linux-amd64  

chmod 700 kops-linux-amd64

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

Verify the kops version

kubectl:

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

chmod 700 kubectl

mv kubectl /usr/local/bin/kubectl

verify the kubectl version

3. Integration DNS with your AWS account by using Route53

  • Note down the Name servers from Hosted zone details
in my case below are the Name server :              
  • ns-XXXX.awsdns-XX.org
  • ns-XXXX.awsdns-XX.net
  •    ns-XXXX.awsdns-XX.co.uk
  • ns-XXX.awsdns-XX.com
  • Now these 4 Name Servers has to be add in to the DNS which we created by Manage DNS option.

  • Verify the entered whether those are got updated or not  by using below command, it should match to our DNS records. 
            dig NS sra1k8s.xyz


4. Create S3 bucket to store Cluster state 

S3 is a location where it store the configuration of your cluster,and its state store it will be used while creating the cluster from KOPS.

State is stored here not only when you first create a cluster, but also you can change the state and apply changes to a running cluster.

Bucket Name : sra1k8s



4. Configure  AWS Access/Secret Key and AWS CLI

It is required to configure aws cli with access key and secret key to create cluster resources in AWS

follow the below steps to configure it.

(take the Security credentials by the Root user or you can create keys from IAM User) in my case im creating the user for KOPS.

adding user from IAM:

Install AWS-CLI:

        curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

        unzip awscliv2.zip

        sudo ./aws/install

        verify the Version : awscli --version

Configuring aws-cli :

Execute   aws configure and provide the below details 

AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXXXX

AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXX

Default region name [None]: us-east-1

Default output format [None]: json

to verify AWS-Cli run the below command

aws s3 ls

6. SSH Public & Private Keys

Generate teh SSH keys by using command : ssh-keygen

7. Create the Cluster by Using Kops

Create a kubernetes cluster using kops create command and required command line flags.It creates cloud-based resources such as networks and virtual machines.Once the infrastructure is in place Kubernetes will install on the virtual machines.

 pass your arguments and Execute the below command.

kops create cluster --name=sra1k8s.xyz --state=s3://sra1k8s --zones=us-east-1a --node-count=2 --node-size=t2.micro --master-size=t2.small --master-volume-size 15 --node-volume-size 10 --dns-zone=sra1k8s.xyz --yes

after executing the above command, you will get the output as below:

Wait for some time to deploy the cluster. if you want to check current status issue the command

watch -n 1 kubectl get nodes

to Verify use the command : kubectl get nodes


 

and also verify from AWS console .


also verify the DNS recods which are creted as part of the Cluster.


find some of the Kops command to administrate the Cluster.

kops validate cluster --state=s3://sra1k8s

kops get cluster --state=s3://sra1k8s

kops update cluster --name sra1k8s.xyz --yes --state=s3://sra1k8s 

kops rolling-update cluster  --name sra1k8s.xyz --yes --state=s3://sra1k8s 

To delete the Cluster use the below command:

kops delete cluster --name=sra1k8s.xyz --state=s3://sra1k8s  --yes


2 comments: