Spotinst and Nirmata: Providing a Simple Way to Create and Manage Your Kubernetes Infrastructure Using Excess Capacity Instances

Reading Time: 7 minutes

Kubernetes is a powerful container orchestration platform that quickly became the standard. The only problem with Kubernetes is that it can be somewhat difficult to create and maintain clusters in production. Luckily, companies like Nirmata are focusing on making it easy to deploy New Kubernetes environments at the click of a mouse. While Nirmata can help quickly spin up Kubernetes clusters, costs will soon become an issue and that is where Spotinst Elastigroup comes in to help. In this post, I will discuss how to get started with Nirmata and how to use Elastigroup to reduce costs by provisioning excess-capacity infrastructure for Kubernetes.

Download the K8s Cost Savings Guide

Prerequisites

Before we can continue, we need to cover the prerequisites so that you can follow along with the technical instructions.

  1. A Spotinst account
  2. An AWS account
  3. A Nirmata account

What is Spotinst Elastigroup

Elastigroup is an application scaling service by Spotinst designed to optimize performance and costs. Using predictive algorithms, Elastigroup reliably leverages Spot Instances and supports all major cloud providers such as AWS, Microsoft Azure, and Google Cloud while removing the risk and complexity, providing a simple orchestration and management at scale.

Spotinst Elastigroup predicts EC2 Spot markets behavior, capacity trends, pricing, and interruptions rate. Whenever there’s a risk of interruption, Elastigroup acts accordingly up to 15 minutes ahead of time, ensuring 100% availability. To play along with this blog post, you will need access to the Spotinst Console. If you do not have access yet, please sign up for a 14-day free trial.

What is Nirmata?

Nirmata allows organizations to easily deploy and operate Kubernetes Clusters and Applications on any cloud. You can compose a cluster from Host Groups. This flexible composition allows using heterogeneous resources, and even use different pricing strategies to provide resources for your cluster. Nirmata can also easily discover existing Kubernetes clusters to provide complete visibility and management. This capability allows you to use managed Kubernetes services from cloud providers (EKS, AKS, GKE, etc.) to create the clusters, and use Nirmata for intelligent, policy-based workload management.

Creating a Nirmata Host Group and Elastigroup

Nirmata offers a generous 1-month free trial to learn their platform. When your account is set up, we can create a Host group which is a collection of nodes running Docker and the Nirmata Agent. The agent communicates with the Nirmata SaaS to install Kubernetes, manage the nodes, and report statistics on the cluster. In the console, navigate to Host Groups, choose Direct Connect, and then click Add Host Group.

Enter a name for the new Host Group and click Finish:

Now you should be at the new Host Group page. Save the output for Step 2 for the USER DATA section when creating a new Elastigroup later in this post.

The next step is to create the hosts for the Nirmata Host Groups using Elastigroup. To create an Elastigroup, navigate to the Spotinst Console and create a new Stateful Elastigroup.


Fill in the General tab with the following:

  • Enter a name for the group.
  • Choose the appropriate region and VPC for your AWS account.
  • Choose Linux/UNIX for Product
  • For Image, choose the Ubuntu image for your Region
  • Choose your EC2 Security Group and Key Pair

Click Next to continue.

An important section to pay attention to is the SPOT MARKET SCORING section. Spot Market Scoring is a unique feature that helps you choose the best spot markets. The scoring section provides a visual aid showing the number of separate spot markets available based on the number of Availability Zones and Spot Types selected. The scale goes from 0-100 where 0 is a non-functional market and 100 will provide the best price and longevity for the spot instance. With the Spot Market explained, let’s proceed with the configuration.

Click Next to continue.

This section is important because it handles disk and network persistence for the instances. In a Kubernetes cluster, each node is identified by an IP address and is responsible for running Pods. if a new instance was added to the cluster without disk and network persistence, the instance will be added as a new node with no data. With that in mind, It is important to persist the root and data volumes so Elastigroup can create new instances if one is replaced. WIth the original private IP and volumes attached, the instance will join the cluster without any issues.

The USER DATA section contains a startup script for the instances that will install Docker and the Nirmata agent. Substitute the “sudo curl” line with the command referenced when creating the Nirmata Host Group earlier.

It is important to choose “Associate public IP” for the instances to be able to communicate with Nirmata. After the Agent is installed, this node will be managed by Nirmata to setup Kubernetes later in this post.

Click Next twice followed by Create.

After creating the Elastigroup, you will be able to see information such as the number of instances, potential costs, savings, and manage how many instances are running.

Let’s make sure that the hosts are registered with Nirmata by navigating to the All Hosts page in the web console.

Excellent, all three hosts created by Elastigroup are connected to Nirmata. With a Host Group configured and running, we can install Kubernetes.

Creating a Kubernetes Cluster with Nirmata Using Spot Instances

Navigate to the Clusters section of the Nirmata Web Console and click on Add Cluster. In the proceeding window, click on Install a new Kubernetes cluster.

Enter a name and the Host Group that was created earlier. Click Create Cluster and your Kubernetes cluster will be created in a few minutes.

After the Kubernetes cluster is created, you will be presented with a dashboard that displays important information such as registered nodes, running pods, capacity details, resources used, and much more. With the cluster running, let’s create a sample application and see how to scale the infrastructure with Spotinst Elastigroup.

Running a Sample Application

To create an application, we will first need to upload a Kubernetes manifest for our sample application – WordPress – to the Catalog section of Nirmata Web Console. The WordPress environment will consist of three Docker containers: MySQL, PhpFPM, and Nginx.

Save the following manifest as wordpress.yaml and then upload it.


With the application manifest stored on Nirmata, we can now create an environment to run the application on. Navigate to the Environments page in the Web Console and create a dev environment for WordPress

To launch WordPress in the dev environment, click on “Run an application in this environment”.

In the proceeding window, enter the following and click Run Application.

After WordPress is deployed, we will be able to see the details for each Pod.

With WordPress running, let’s learn how to scale up the Kubernetes Infrastructure.

 

Scaling Up the Kubernetes Infrastructure with Elastigroup

Elastigroup makes it very easy to add additional capacity for your workloads. Navigate to the Elastigroup created for Nirmata and choose Actions followed by Manage Capacity. In the proceeding window, enter 3 in the “Increment group instanced by” text field.

Finally, click LAUNCH.

After a few minutes, you should see the number of nodes increase.

The nodes should automatically join the Nirmata Host Group. To verify this, navigate back to the All Hosts page in the Nirmata Web Console.

Excellent, the new instances are now registered. After a few minutes, Nirmata will install and configure Kubernetes on the new instances. Let’s verify that Kubernetes can see the new nodes by accessing the terminal under the cluster section of the page.

In the proceeding window, click Connect Terminal. To view a list of registered nodes in the Kubernetes cluster, we can use kubectl as shown below:

The environment for the Nirmata Kubernetes cluster has been up and running for a while and it would be interesting to see how much Elastigroup reduced costs. Let’s navigate back to the Spotinst Console and see.

Wow, Elastigroup was able to reduce infrastructure costs by 69%!

Conclusion

In this post, I explained how to get started with Nirmata to automatically create a Kubernetes cluster on Spot instances using Elastigroup. Nirmata makes it very simple to control a cluster of Docker hosts and install and manage a Kubernetes cluster. With Elastigroup, organizations can easily scale their infrastructure to add capacity as needed for their workloads and reduce computing costs by taking advantage of excess capacity instances. For the duration of running Nirmata for this blog post, Elastigroup was able to reduce costs by 69%. Imagine the savings running this environment 24/7.