Deploy Rancher on AWS EKS using Terraform & Helm Charts
Tags: aws, kubernetes, rancher, terraform
Published: 2023-11-14 12:39:42

Step-by-step guide to deploy Rancher on AWS EKS using Terraform and Helm Charts.

## AWS Cloud Hands-on Lab Practice Series

![Project Overview Image](https://cdn-images-1.medium.com/max/3280/1*A2jj2ULwSANDW_t61kXISQ.png)

> **Project Overview —**

This project revolves around AWS EKS where we deploy Rancher (platform for Kubernetes management). Rancher is a Kubernetes management tool to deploy and run clusters anywhere and on any provider. Amazon EKS & Rancher is a vital combination when it comes to managing multi-cluster Kubernetes workloads from a Single Dashboard.

> **SOLUTIONS ARCHITECTURE OVERVIEW -**

![Architecture Overview Image](https://cdn-images-1.medium.com/max/2000/1*534LYZABqKVxQjK6j5ZrbA.png)

> **First, let’s understand the real-world use case:**

- **Hybrid Cloud Management for a Global E-Commerce Platform:**
  Imagine a large e-commerce platform that serves customers globally. The platform’s infrastructure spans multiple regions to ensure low-latency access and high availability. Rancher provides a unified dashboard for managing EKS clusters spread across various regions.

- **Finance: Multi-Tiered Application Deployment:**
  A financial institution is migrating its legacy monolithic applications to a microservices architecture on AWS EKS. Rancher simplifies the deployment of microservices across EKS clusters in different regions.

- **Retail: Seasonal Application Scaling:**
  A retail chain experiences significant fluctuations in website traffic during holiday seasons. Rancher enables automated scaling of applications based on predefined policies.

- **Manufacturing: Edge Computing for IoT Devices:**
  A manufacturing company utilizes IoT devices across its facilities to monitor and optimize production processes. Rancher supports the deployment of Kubernetes clusters at the edge, close to IoT devices.

- **Media and Entertainment: Content Delivery Optimization:**
  A media streaming service operates globally and needs to optimize content delivery for users. Rancher integrates with AWS services like Amazon CloudFront for efficient content caching.

These diverse use cases demonstrate the versatility of Rancher on AWS EKS in addressing industry-specific challenges and enhancing the management of Kubernetes clusters in various contexts. Rancher simplifies operations, enhances security, and provides a unified platform for managing the hybrid cloud environment.

> **Prerequisite —**

1. AWS ACCOUNT with admin privileges.
2. AWS EC2 Instance (Bastion Host)
3. [Terraform Installation Guide](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli)
4. [HELM Installation Guide](https://helm.sh/docs/intro/install/)
5. [KUBECTL Installation Guide](https://kubernetes.io/docs/tasks/tools/)

> **AWS Services Usage —**

- AWS EKS
- AWS IAM
- AWS EC2
- AWS ELB
- AWS VPC

> **Step-by-Step Guide -**

**Step 1: Clone the repo & check the versions of installed tools**

- Login to AWS EC2 instance (Bastion Host).
- Install tools — Terraform, helm, kubectl, aws cli.
- Check versions: `aws version`, `kubectl version`, `helm version`.
- Now clone the Git Repo: [Terraform Repo Link](https://github.com/Kunal-Shah107/Rancher-EKS)
- Give Star & Follow me on [GitHub](https://github.com/Kunal-Shah107)
- Repo has 3 files — `main.tf`, `variables.tf`, & `terraform.tf`

**Step 2: Deploying AWS resources through Terraform.**

Now go to the folder location & run below commands.

```sh
Terraform init
Terraform validate
Terraform plan
Terraform apply
```

![](https://cdn-images-1.medium.com/max/2658/1*bpQ5nRr5ETqIoH8MnpbRkg.png)

- This will deploy infrastructure resources in AWS.
- It will take around 15–20 mins to get it deployed.
- It will have 1 EKS master cluster & 2 worker nodes (ec2 spot instances) attached to the AWS EKS master cluster.

**STEP 3 : Add Helm Repositories**

- helm repo add devpro [https://devpro.github.io/helm-charts](https://devpro.github.io/helm-charts)

- This repository contains Helm charts to build clusters with all components running in containers.

```sh
helm repo add jetstack https://charts.jetstack.io
    
helm repo add ingress-nginx  https://kubernetes.github.io/ingress-nginx

helm repo add rancher-latest https://releases.rancher.com/server-charts/latest

helm repo update

helm repo list
```

![](https://cdn-images-1.medium.com/max/2000/1*QPKILWAcCUmVJNfC9i3pQQ.png)

**STEP 4 : Access the EKS Cluster through kubectl**

- Run below mentioned commands from EC2 Bastion:

```sh
aws eks - region me-south-1 update-kubeconfig - name <eks_cluster_name>

kubectl get nodes

kubectl get all -A
```

* **TIP** — If you face any permission issue then change permission for ~/.kube/config

* This confirms that **Cluster on EKS is ready with requested worker nodes.**

**STEP 5 : Ngnix Ingress Installation (exposing to Internet)**

- Run below mentioned command :

```sh
helm upgrade --install \
      ingress-nginx ingress-nginx/ingress-nginx \
      --namespace ingress-nginx \
      --set controller.service.type=LoadBalancer \
      --version 4.8.3 \
      --create-namespace
```

![](https://cdn-images-1.medium.com/max/2000/1*X9G_rH7iqrpkL5ihWqT0Iw.png)

- **Check the services:** kubectl get services -n ingress-nginx

- Copy & save Loadbalancer DNS ( It will used in step 7)

![](https://cdn-images-1.medium.com/max/2648/1*bkycicu0EroTqgE4rfSTIA.png)

**STEP 6 : Install Certificates manager.**

- Set env variables

- **CERT_MANAGER_VERSION=v1.12.4**
- **RANCHER_VERSION=2.7.6**

- **kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/${CERT_MANAGER_VERSION}/cert-manager.crds.yaml**

```sh
helm upgrade --install cert-manager jetstack/cert-manager \
      --namespace cert-manager \
      --create-namespace \
     --version $CERT_MANAGER_VERSION
```

- **Check the pods :** kubectl get pods -namespace cert-manager ( 3 pods should be in Running status)

![](https://cdn-images-1.medium.com/max/2654/1*nZe5H8qIhcyTu83bRRSv-Q.png)

![](https://cdn-images-1.medium.com/max/2000/1*vu0VfOCY02UaUcRsrcW7gQ.png)

![](https://cdn-images-1.medium.com/max/2000/1*4VDoq9kVkmGQ4d0Blrnw8w.png)

* Lets have new certificate from **letsencrypt**

```sh
helm upgrade --install letsencrypt devpro/letsencrypt \
      --set registration.emailAddress=$EMAIL_ADDRESS \
      --namespace cert-manager
```

- **Now run this command :** kubectl get clusterissuer -n cert-manager ( 2 Cluster issuers should be True)

![](https://cdn-images-1.medium.com/max/2000/1*EPQtyyS-VCBVuoXo5nzO8A.png)

![](https://cdn-images-1.medium.com/max/2000/1*yet_0_0SJnZX7P5MTNI2DQ.png)

**STEP 7 : Install Rancher**

```sh
- kubectl create namespace cattle-system

helm upgrade --install rancher rancher-latest/rancher \
--namespace cattle-system \
--set hostname=<LOAD_BALANCER_DNS> \
--set 'ingress.extraAnnotations.cert-manager\.io/cluster-issuer=letsencrypt-prod' \
--set ingress.ingressClassName=nginx \
--set ingress.tls.source=secret \
--set ingress.tls.secretName=rancher-tls \
--set replicas=2 \
--version $RANCHER_VERSION**
```

![](https://cdn-images-1.medium.com/max/2000/1*pZRYjK3hgoN4Cemr-9tRTQ.png)

- Check the status of installation & wait for it to complete.

```sh
kubectl -n cattle-system rollout status deploy/rancher

kubectl get secret - namespace cattle-system bootstrap-secret -o go-template='{{ .data.bootstrapPassword|base64decode}}{{ "\n" }}'
```

![](https://cdn-images-1.medium.com/max/2648/1*YsbSSr-YH2qA0iVjajuyJA.png)

**STEP 8 : Accessing the Rancher UI**

- Copy Load balancer DNS URL & Paste on browser for Initial setup of Rancher.

- You will be asked for password ( copied earlier )

- Hit Log in with Local User.

- Define the admin password, check the box and click on “Continue”. (store it)

- Finally, Rancher is running and you can explore “local” cluster.

![](https://cdn-images-1.medium.com/max/3078/1*ituiMkc_yqQwYjRxudJrGA.png)

![](https://cdn-images-1.medium.com/max/2904/1*w0zYBhDWoihQ72jQTbDoXA.png)

![](https://cdn-images-1.medium.com/max/3836/1*IiU4VGyu5n8_MkNhhGAzSQ.png)

![](https://cdn-images-1.medium.com/max/3816/1*lucxUU4sQcP-eHIGmnpj9A.png)

**STEP 9 : Check AWS EKS Console**

![](https://cdn-images-1.medium.com/max/3708/1*KlG39iAZio2R_6TEgFAveA.png)

![](https://cdn-images-1.medium.com/max/2882/1*qSYHfbgx5fZheGRUQvrFpg.png)

![](https://cdn-images-1.medium.com/max/3096/1*uiCUCFVEuJsndax1TMVT9g.png)

**STEP 10 : Decommission**

* Run below command to destroy all resources.

```sh
kubectl delete ns cert-manager
    
kubectl delete ns ingress-nginx
    
terraform destroy --auto-approve
```

## Congrats ! We have successfully completed lab for Deploying Rancher on AWS EKS using Terraform & Helm Charts.

![](https://cdn-images-1.medium.com/max/3144/1*BxfgHQkXG7JLHn9ohjYVeg.png)

*I am Kunal Shah, AWS Certified Solutions Architect, helping clients to achieve optimal solutions on the Cloud. Cloud Enabler by choice, DevOps Practitioner having 8+ Years of overall experience in the IT industry.*

*I love to talk about Cloud Technology, DevOps, Digital Transformation, Analytics, Infrastructure, Dev Tools, Operational efficiency, Serverless, Cost Optimization, Cloud Networking & Security.*

#aws #community #builders #devops #eks #managed #kubernetes #solution #rancher #solution #management #centralize #dashboard #easy #management #scalability #operational #efficiency #robust #infrastructure #highly #available #reliable #controlled #design #acloudguy

*You can reach out to me @ [acloudguy.in](https://acloudguy.in/)*