Setting up a Kubernetes cluster with Kops
Deploying the Dockerized application in a virtual machine or Elastic Compute Cloud (EC2) instance requires more maintenance activity for scaling the application and managing the environment. If we use Elastic Container Service for Kubernetes (EKS), the master is managed by Amazon Web Services (AWS). This is not beneficial as we do not have any control of the master, apart from increasing costs.
CloudifyOps recommends implementing a Kubernetes cluster using the KOPS method in AWS
This ensures the master and worker nodes are in our control and reduces the cost in comparison to EKS. The application can be scaled using Horizontal Pod Autoscaler (HPA).
What is a Kubernetes cluster?
A Kubernetes cluster is a set of nodes that run containerized applications. Containerizing applications packages an app with its dependencies and some necessary services. They are more lightweight and flexible than virtual machines.?
Kubernetes clusters enable applications to be easily developed, moved and managed.?
The clusters allow containers to run across multiple machines and environments: virtual, physical, cloud-based, and on-premises. Kubernetes containers are not restricted to a specific operating system, unlike virtual machines, and have the ability to share operating systems and run anywhere.
Kubernetes clusters consist of one master node and a number of worker nodes. These nodes can either be physical computers or virtual machines, depending on the cluster.
The master node controls the state of the cluster; for example, which applications are running and their corresponding container images. The master node is the origin for all task assignments. It coordinates processes such as:
We can build a Kubernetes cluster in different ways:
Requirements to create a Kubernetes cluster with KOPS:
How to Set Up:?
Step 1: Prepare your Host Environment
Install an Ubuntu 20.04 server. This will be the management server that holds all the required scripts to create a cluster and the entire configuration.
Install Kubectl Binary:
Kubectl is a command-line tool that simplifies the management of Kubernetes clusters. It lets you run commands against them.
The following command helps to download the latest version of Kubectl
Provide read write and execution permissions for Kubectl folder?
Move kubectl folder to the /usr/local/bin
To verify the installation, run the below command?
Install kops Binary
KOPS is a set of tools that can be used to install, run, and delete Kubernetes clusters in the cloud. It can also manage the add-ons for the cluster.
Downloading the KOPS binary
Provide read write executable permissions to the kops-linux-amd64
Move kops-linux-amd64 directory to the /usr/local/bin and rename it as a kops
To verify the KOPS installation, run the following
Install AWS CLI tools
AWS CLI is used to communicate with the AWS cloud environment. While creating the cluster, we will write a state file to the S3 bucket, which the? AWS CLI will help in writing to that location.
Before downloading AWS CLI, we need to install unzip in it?
Once the AWS CLI installation is complete, we can verify by running the below command.
领英推荐
Step 1: Configure AWS CLI tools
To configure this, we can use a user with AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY or use a role with required permissions.
We create and attach a role with administrator permissions to the management instance.
Generate SSH key:
In the process of cluster creation, EC2 instances will be created as masters and slaves. The SSH keys will be attached to the master and slaves. We can login to the master and slave servers using a private key file.
To generate SSH key, run the below command
Step 2: Configure Route 53 Domains & S3 bucket
Creating a dedicated S3 bucket for KOPS will allow you to store all of your cluster's details. In this guide, we shall call this bucket kops-state-store.
To create the s3 bucket, run the following
??? --bucket <.bucket-name.> \
??? --region us-east-1
Route53:
If you bought your domain elsewhere, and would like to dedicate the entire domain to AWS, you should follow?this guide .
Step 3: Kubernetes cluster creation
We have configured all requirements to spin up a cluster. Now we can spin up a cluster by running the following command:
--zones=us-east-1a --yes?
If you are deploying a cluster using the above command, the clusters will have default volume sizes (node of?124GB and master?of 64GB). To ensure we have control of the cluster, we can use customized command while creating the cluster.
kops create cluster --name=bittergourd.xyz \
--state=s3://<.s3-bucket-name.> --zones=us-east-1a,us-east-1b,us-east-1c\
?--node-count=1 --node-size=t3.medium \
--master-size=t3.medium --master-volume-size 20 --node-volume-size 10 \
--dns-zone=<.hostedzone-name.> --yes
It is recommended to have same names for cluster and DNS. With the above command, we can create a single master and a single node cluster with the limited size attached to the instances. It will take 10 minutes to bring up the cluster once you hit enter. You can check the cluster state with the below command
Once the cluster is up, you will get the below output.
We can export a state location to the bashrc. For KOPS to read a state file location from the bashrc profile every time, we run the KOPS commands.
We can increase and decrease the size of the cluster by editing the instance groups?
By increasing the maximum and minimum numbers, we can scale up and? down the cluster.
Reference Links:
To learn more about these cutting edge technologies & real time industry applied best practices, follow our?LinkedIn Page . To explore our services, visit our?website .