DEV Community

leroykayanda
leroykayanda

Posted on • Edited on

Bash script to initialize an EKS cluster with common components eg autoscaler, container insights etc

The script sets up the components below.

  1. VPC CNI prefix mode
  2. Horizontal Pod Autoscaler
  3. A LimitRange
  4. Cluster Autoscaler
  5. Prometheus, Loki and Grafana
  6. AWS Load Balancer controller
  7. EKS container insights
  8. EFS CSI
  9. Create cluster
  10. Delete cluster
  11. Istio

Github repo is here.

The following needs to be installed on the machine the script is run on:

  1. eksctl
  2. helm v3
  3. kubectl
  4. aws cli

You select which components you wish to install by adding switches. The ones below are needed as parameters for various parts of the script.

./eks-init.sh -cluster my_cluster_name -region us-east-1 -aws_account 123456789

Other flags are as below:

-prefix_mode  : Set up VPC CNI prefix mode 
-hpa  : Set up Horizontal Pod Autoscaler
-limit_range : Set up a Limitrange 
-autoscaler  : Install cluster autoscaler 
-grafana  : Set up Grafana
-insights  : Set up EKS container insights
-create : Create a clsuter using eksctl
-nuke : <cluster_name> Delete cluster
-istio : Set up Istio
Enter fullscreen mode Exit fullscreen mode
-lb_controller : Install the AWS Load Balancer Controller add-on
Enter fullscreen mode Exit fullscreen mode

This has the dependencies below.

-iam_oidc : Create an IAM OIDC provider for your cluster
-ecr_repo : Amazon container image registry from here

So the cmd would be:

./eks-init.sh -cluster my_cluster_name -region us-east-1 -aws_account 123456789 -iam_oidc -ecr_repo 602401143452.dkr.ecr.us-east-1.amazonaws.com

-efs : Set up EFS CSI for cluster storage
Enter fullscreen mode Exit fullscreen mode

This has the dependencies below:

-az1_mp <AZ1 Subnet ID for EFS Mount Point> 
-az2_mp <AZ2 Subnet ID for EFS Mount Point>
Enter fullscreen mode Exit fullscreen mode

./eks-init.sh -cluster my_cluster_name -region us-east-1 -aws_account 123456789 -efs -az1_mp subnet-123 -az2_mp subnet-456

You specify 2 subnets IDs in different AZs to be used for EFS mount points.

To install everything, you would use:

./eks-init.sh -cluster my_cluster_name -region us-east-1 -aws_account 123456789 -prefix_mode -hpa -limit_range -autoscaler -grafana -insights -lb_controller -iam_oidc -ecr_repo 602401143452.dkr.ecr.us-east-1.amazonaws.com -efs -az1_mp subnet-123 -az2_mp subnet-456 -istio

It may however be advisable to install one component at a time so that you can test to ensure everything is okay before installing the next component.

Top comments (0)