Skip to content

ludesdeveloper/pulumi-managed-nodes-autoscale-eks

Repository files navigation

PROVISION MANAGED NODES AUTOSCALE EKS WITH PULUMI

Requirement

  1. AWS CLI installed
  2. Configure AWS CLI
  3. Pulumi installed
  4. Pulumi logged in
  5. Helm instaled
  6. NPM installed
  7. Kubectl installed

How To

  1. Clone repository
git clone https://github.com/ludesdeveloper/pulumi-managed-nodes-autoscale-eks.git 
  1. Change directory
cd pulumi-managed-nodes-autoscale-eks
  1. Install dependencies
npm install
  1. Initialize Pulumi stack
pulumi stack init
  1. Set Pulumi region
pulumi config set aws:region ap-southeast-1
  1. Provision EKS with pulumi
pulumi up --yes

Give name of your stack, (dev) or other name you prefered

  1. Copy kubeconfig to your kubeconfig directory (warning, this will replace your kubeconfig file)
pulumi stack output kubeConfig > ~/.kube/config
  1. Make sure your cluster is ready
kubectl get nodes
  1. You can run script below to apply cluster autoscaler or manually copy paste line inside init-autoscale-cluster.sh script
./init-autoscale-cluster.sh

Before Testing

  1. Usually when testing, I open 3 tabs terminal to check, and every check consist of : auto scale log
kubectl -n kube-system logs -f deployment.apps/cluster-autoscaler
  1. Check Nodes
watch kubectl get nodes
  1. Check Pods
watch kubectl get pods -o wide

Testing

  1. Apply nginx-deployment
kubectl apply -f nginx-deployment.yaml
  1. Scale up nginx pod
kubectl scale deployment/nginx-deployment --replicas=20

You will see pending in your pod, and kubernetes will trigger scale up for nodes, wait for a while. You also can check in your EC2 dashboard AWS, AWS will try to create new instance

  1. Scale down nginx pod
kubectl scale deployment/nginx-deployment --replicas=3

Scale down will takes time around 10 minutes, until cluster remove unnecessary nodes

Cleanup

  1. Destroy pulumi
pulumi destroy --yes
  1. Remove pulumi stack
pulumi stack rm dev

Type name of your stack

Source Articles

How to Scale Your Amazon EKS Cluster: EC2, Managed Node Groups, and Fargate

Amazon EKS Pulumi Crosswalk

Autoscaling - Amazon EKS