Setting Up Rancher OS on AWS EC2

A Detailed Walkthrough for Installing and Configuring Rancher on an EC2 Instance

Melissa (Mel) Foster
Women in Technology
7 min readJul 7, 2024

--

Adobe Free Stock Image & Unedited Logos

If you’re advancing in your DevOps journey, I’m thrilled you found this article. This project is perfect for those eager to delve deeper and challenge themselves. I decided to explore another method by setting up Rancher OS on an EC2 instance, offering a solid foundation for future Kubernetes cluster management.

A little background //

Rancher is an open-sourced Kubernetes orchestration platform providing additional management features on top of Docker.

K8 or Kubernetes is an open-source orchestration system used for automating deployment, scaling, and management of containerized applications.

Still new to K8? Try checking out this project to start and come back to this one. If you are intrigued and ready to follow the white rabbit, read on.

Business Utilization of Rancher OS on AWS EC2 //

Deploying Rancher OS on an AWS EC2 instance can significantly benefit businesses by providing a strong and scalable platform for managing containerized applications. Here are several ways this setup can be utilized for business purposes:

  • Efficient Container Orchestration:
    Rancher offers a user-friendly interface for managing Kubernetes clusters, simplifying the process of container orchestration. This can lead to increased operational efficiency and reduced complexity in managing large-scale container deployments.
  • Scalability and Flexibility:
    AWS EC2 instances provide scalable computing resources, allowing businesses to adjust their infrastructure based on demand. This flexibility ensures that businesses can handle varying workloads without overprovisioning resources, leading to cost savings.
  • Opportunity to enhanced DevOps Practices:
    In an upcoming project, I aim to promote best DevOps practices by implementing Rancher through CI/CD pipeline. This setup will empower teams to deploy updates quickly and reliably, thereby enhancing the overall software development lifecycle.
  • Cost Management:
    Although this project moves away from the AWS Free Tier, it can still be budget-friendly by carefully managing the EC2 instances. By stopping instances when not in use and selecting appropriate instance types, businesses can control costs effectively.
  • Streamlined Development and Testing Environments:
    Rancher on EC2 provides an isolated environment for development and testing, allowing teams to experiment with new features and updates without affecting the production environment. This separation helps in identifying issues early in the development cycle.

Objectives //

  • Install and Configure Rancher OS on an EC2 Instance
  • Set Up Docker on EC2
  • Deploy Rancher on Docker
  • Verify and Access Rancher

To follow along with this project you will need //

  • Access to AWS
    NOTE: This is not a Free-Tier Project
  • Configured Visual Studio Code installed on OS
    Note: You can choose to work through this project in another cloud environment that you are familiar with. Just ensure it is configured with your AWS CLI.
  • AWS Access Key & Secret Key
  • Attention to Details

Now that we’ve outlined the business objectives and project goals, let’s jump right in!

Launching your EC2//

Navigate to your AWS Console, then to your EC2 Dashboard.

  • Select Launch instance
  • Name your EC2
  • Select Ubuntu 22.04 LTS

This time we are moving away from Free-tier, as K8 needs a min. of 2CPu and 2GB Ram to operate.

  • Turn on All generations
  • Use Search Bar and Type t3a
  • Select t3a.medium
Special Note: This project is not free tier but can be budgeted to not be expensive as long as you stop any EC2s you create
  • Create a key pair

Configure Security Group//

  • Allow SHH & All HTTP Traffic for demo purposes
  • Launch

In Visual Studio Code connect to EC2//

In VS Code, navigate to the lower left hand corner and select the two arrow icon. Once you click the icon a new remote window will open.

  • Click Icon to Open Remote Window
  • Select Connect to Host…
  • Select Configure SSH Hosts…
  • Select the first path: C:\Users\yourusername\.ssh\config

This process might feel familiar if you followed along with my previous Docker Swarm project . We will now update our .ssh config file with our EC2.

Note: Be aware of case sensitivity, spelling, and punctuation. Even an extra space at the end can cause connectivity issues.

  • Update Config → File → Save and close
  • Navigate back to lower left hand corner and select double arrow icon
  • Select Connect to Host
  • Select EC2 Name
  • Select Linux as we are using Ubuntu as our OS Platform
  • Launch Terminal
  • Update & Upgrade
sudo apt update
sudo apt upgrade -y
  • Install required dependencies for Docker
sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y
  • Install Docker
sudo apt install docker.io
  • Verify Docker by either of the following commands:
sudo docker version 

or

sudo docker hello-world
  • Verify Docker is up and running
sudo systemctl status docker
Select Ctrl +C to exit back to the command line

If you are like me and just hate typing in sudo, we can save a few key strokes by entering in this command:

sudo usermod -aG docker ${USER}
  • Reboot
    (This will restart your environment, follow prompt to relaunch VS Code window)

Install Rancher on Docker Container //

Awesome, feeling good! Before we create any new containers, we can run a command to show both running and stopped containers.
Note: I included this step just incase you started or possibly restarted this project using the same EC2 Instance.

docker ps -a

Your screen should show zero, and we can move to installing Rancher detached on port 80 and port 443 with privilege.

  • Install Rancher on a detached container using port 80
docker run -d --restart=unless-stopped -p 80:80 -p 443:443 -v /opt/rancher:/var/lib/rancher --privileged rancher/rancher:latest
  • Verify Container
Awesome, feeling good! Before we create any new containerswe can run a command to show both running and stopped containers. 
Note: I included this step just incase you started or possibly restarted this project using the same EC2 Instance.
Docker Container Running Ranch on Port 80

Verifying & Configuring Rancher //

Next let’s verify our Rancher on our Public IP Address off of our EC2.
If you are like me, you might have run into a privacy error.

  • Select Proceed

With our container id we looked up previously we can run the command provided to locate the password to enter.

docker logs  container-id  2>&1 | grep "Bootstrap Password:"

Next you will be prompted to enter a new password or select a random generated password. Whichever you choose, note it down securely.

Congratulations on successfully setting up Rancher OS on your AWS EC2 instance! This walkthrough has equipped you with the foundational skills to effectively manage Kubernetes clusters using Rancher. Whether you’re aiming to streamline container orchestration or prepare for advanced Kubernetes deployments, I hope you find that this project offers valuable insights and practical knowledge. I encourage you to continue exploring and experimenting to further enhance your DevOps capabilities. Stay tuned for future projects that will build upon the skills you’ve developed here!

Join me on https://www.linkedin.com/in/melissafoster08/ or follow me at https://github.com/mel-foster

All Screen Capture Images ©Melissa (Mel) Foster

--

--

Melissa (Mel) Foster
Women in Technology

𝔻𝕖𝕧𝕆𝕡𝕤 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿 |𝒲𝑜𝓂𝑒𝓃 𝐼𝓃 𝒯𝑒𝒸𝒽 𝒜𝒹𝓋𝑜𝒸𝒶𝓉𝑒 | 𝚂𝚘𝚌𝚒𝚊𝚕 𝙼𝚎𝚍𝚒𝚊 𝙲𝚛𝚎𝚊𝚝𝚘𝚛 | Photographer