DEV Community

Prithiviraj R
Prithiviraj R

Posted on

Managing Kubernetes Clusters with Rancher Orchestrator: Deploying on Amazon EC2 and EKS

If you're diving into Kubernetes, you might already know how complex it can be to manage clusters. This is where Rancher, a powerful open-source platform for managing Kubernetes, comes into play. In this blog, we’ll walk through how to use Rancher to create and manage Kubernetes clusters on Amazon EC2 and EKS (Elastic Kubernetes Service). Whether you're new to Kubernetes or just looking for a simpler way to manage your clusters, Rancher makes it easier.

What is Rancher?
Rancher is a complete container management platform that makes deploying, managing, and scaling Kubernetes clusters across multiple environments super simple. It provides a single pane of glass to manage clusters, whether they’re running on your local machines, on Amazon EC2, or even on managed services like AWS EKS.

Why Use Rancher for EC2 and EKS?
If you’re already using AWS EC2 or EKS, you know that setting up and managing Kubernetes can be a bit of a chore. Rancher simplifies this process by offering an easy-to-use interface and seamless integration with AWS services. It allows you to manage your clusters more efficiently, scale them with ease, and keep everything under control.

Step 1: Setting Up Rancher
To get started, the first thing we need to do is set up Rancher. The good news is that it's super easy to run Rancher on Docker. Here’s how you can get Rancher up and running on your machine or on an EC2 instance:

Install Docker: If you haven’t already, install Docker on your machine.

Run Rancher: Open your terminal and run this command to launch Rancher:

docker run -d --name rancher -d --privileged --restart=unless-stopped -p 80:80 -p 443:443 -v rancher-data:/var/lib/docker rancher/rancher:latest

Enter fullscreen mode Exit fullscreen mode

Image description

sudo docker run: Starts a Docker container.
--name rancher: Assigns the container the name rancher for easier identification.
-d: Runs the container in detached mode (in the background).
-p 80:80 and -p 443:443: Maps ports on the host to the container:
Port 80: HTTP access.
Port 443: HTTPS access.
-v rancher-data:/var/lib/rancher: Creates a Docker volume named rancher-data for persistent storage of Rancher's data. This ensures data is retained across container restarts.
rancher/rancher:latest: Specifies the Rancher image to use, with the latest tag.

Initial Setup: Once you access Rancher, it’ll prompt you to set an admin password and configure a few basic settings.

Image description

Image description

Step 2: Creating a Kubernetes Cluster on EC2
If you want to run Kubernetes on EC2, Rancher makes it easy to connect EC2 instances as worker nodes to your Kubernetes cluster. Here's how to do it:

Prepare EC2 Instances: Create a few EC2 instances (Ubuntu, Amazon Linux, or any other supported OS). Ensure these instances have the necessary IAM roles and security groups to interact with EKS if needed.

Add EC2 Nodes to Rancher: In Rancher’s UI, click on "Add Cluster," then select Custom. Rancher will generate a script you need to run on each EC2 instance. This script installs the necessary software on your instances and connects them to Rancher.

Verify the Cluster: Once all the EC2 instances are added, you can go to Rancher's dashboard and check the status of the cluster. You'll see a list of your nodes and their health. If everything looks good, your Kubernetes cluster on EC2 is ready to go!

Image description

Image description

Step 3: Creating a Kubernetes Cluster on EKS
If you prefer a managed Kubernetes service, Amazon EKS is a great option. Here’s how to use Rancher to set up an EKS cluster:

Integrate with EKS: In Rancher’s UI, click on "Add Cluster" and choose Amazon EKS. Rancher will ask you to connect it with your AWS account. You can do this by setting up the right IAM roles and providing the necessary credentials.

Configure Your EKS Cluster: Select your desired AWS region, Kubernetes version, and VPC settings. Rancher makes it easy to configure networking and node pools for your EKS cluster.

Launch the Cluster: After you’ve set your preferences, click “Create.” Rancher will automatically handle the provisioning of the EKS cluster for you. Once it's done, you’ll be able to manage it directly through Rancher.

Image description

Image description

Image description

Image description

Image description

Conclusion
Using Rancher to manage Kubernetes clusters on Amazon EC2 and EKS is a game-changer. It simplifies cluster setup, scaling, and management, making Kubernetes a lot more approachable, even if you're running multiple clusters in different environments.

If you haven't already, give Rancher a try and see how it can make your Kubernetes management much easier. It's a fantastic tool for developers, DevOps teams, and anyone looking to streamline their container orchestration.

Happy Learning!!

Prithiviraj Rengarajan
DevOps Engineer

Top comments (0)