Using Kops to setup up Kubernetes Cluster

Sriw
Analytics Vidhya
Published in
5 min readSep 30, 2020

--

Kubernetes and Kops overview

Kubernetes is an open source, container orchestration platform. Applications packaged as Docker images can be easily deployed, scaled, and managed in a Kubernetes cluster. Some of the key features of Kubernetes are:

  • Self-healing
    Failed containers are restarted to ensure that the desired state of the application is maintained. If a node in the cluster dies, then the containers are rescheduled on a different node. Containers that do not respond to application-defined health check are terminated, and thus rescheduled.
  • Horizontal scaling
    Number of containers can be easily scaled up and down automatically based upon CPU utilization, or manually using a command.
  • Service discovery and load balancing
    Multiple containers can be grouped together discoverable using a DNS name. The service can be load balanced with integration to the native LB provided by the cloud provider.
  • Application upgrades and rollbacks
    Applications can be upgraded to a newer version without an impact to the existing one. If something goes wrong, Kubernetes rolls back the change.

Kops, short for Kubernetes Operations, is a set of tools for installing, operating, and deleting Kubernetes clusters in the cloud. A rolling upgrade of an older version of Kubernetes to a new version can also be performed. It also manages the cluster add-ons. After the cluster is created, the usual kubectl CLI can be used to manage resources in the cluster.

In earlier post I used Minikube for Local Deplyment of single node Kubernetes cluster and this post I will deploy N Node Cluster on AWS.

Link : https://medium.com/@sarthak3398/using-minikube-for-local-deplyment-of-single-node-kubernetes-cluster-25bb576d532b

Prerequisites:

  • AWS-cli setup
  • S3 bucket
  • Necessary Library

I have attached a pdf where I have added all the commands to install docker, kubectl and kops . Only move forward after completing this step.

AWS-cli setup

  1. Create an account on AWS.
  2. Go to Identity & Access Management (IAM), create a user and generate an access key to configure AWS on your machine. You need to give AdministratorAccess Permissions to this IAM user.
  3. Open the command line and configure AWS
aws configure

4. Provide access key and secret you just generated, along with that provide the region you are going to deploy your cluster in. AWS recommends users to choose regions geographically close to them to reduce latency and costs.

For those who are using AWS Educate Starter Account . Go to AWS Educate -> sign in -> AWS Account -> AWS Educate Starter Account -> Account Details

gedit ~/.aws/credentials

Delete the content of credentials file and paste the below content on credentials file

5. Go to S3 (Simple Storage Service) Bucket, it is a public cloud storage resource and create a bucket .

Now lets create a cluster on AWS using KOPS

The Kops CLI can be used to create a highly available cluster, with multiple master nodes spread across multiple Availability Zones. Workers can be spread across multiple zones as well. Some of the tasks that happen behind the scene during cluster creation are:

  • Provisioning EC2 instances
  • Setting up AWS resources such as networks, Auto Scaling groups, IAM users, and security groups
  • Installing Kubernetes.

As you can see no instances are running

6. Create AWS Kubernetes Cluster

kops create cluster --yes --state=s3://kops-storage-03091999 --zones=us-east-1a --node-count=2 --node-size=t2.micro --master-size=t2.micro --name=test.k8s.local

As you will run this command you will see two slave and one master node will spin up . You can verify it by going to EC2 Instance section in AWS Services

7. You can verify Kubernetes Cluster

kops validate cluster 
kops validate cluster -o json ##show output in json format
kops validate cluster -o yaml ##show output in yaml format

8. Now we start the Deployment on Kubernetes Cluster. We are deploying a docker image available publically on docker hub

sudo kubectl create deployment <Deployment_Name> --image=<Image_Name>kubectl create deployment magicalnginx --image=anshuldevops/ magicalnginx

9. Get Information of Running Deployments using

kubectl get deployments

10. kubectl describe deployment magicalnginx

11. Now we will make expose NGINX container via the internet via loadbalancer.This comaand also helps in load balancing.

 kubectl create service loadbalancer magicalnginx --tcp=80:80

Now when you go to EC2 Instance section in AWS Services you will see Load Balancer to 1 . Thus your loadbalancer is launched

12. To get Running Services use

kubectl get svc

This command will give the IP and port where your application is accessible .Go to browser and type the IP address with port number

Kubectl commands:

  • To list deployments : sudo kubectl get deployments
  • To delete a service : sudo kubectl delete service magicalnginx
  • To delete a particular deployment : sudo kubectl delete deployment magicalnginx

--

--

Sriw
Analytics Vidhya

Thanks for visiting my blogs. Hope you all find it usefull