Autoscaling an EKS Cluster

Hands-On Lab

 

Photo of Mark Richman

Mark Richman

AWS Training Architect II in Content

Length

01:00:00

Difficulty

Intermediate

Welcome to this hands-on AWS lab! In this lab, we will deploy the Cluster Autoscaler to an Elastic Container Service for Kubernetes (or EKS) cluster. The Cluster Autoscaler is a default Kubernetes component that can scale either pods or nodes in a cluster. It automatically increases the size of an Auto Scaling group so that pods can continue to be placed successfully.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Autoscaling an EKS Cluster

Introduction

Welcome to this hands-on AWS lab! In this lab, we will deploy the Cluster Autoscaler to an Elastic Container Service for Kubernetes (or EKS) cluster.

The Cluster Autoscaler is a default Kubernetes component that can scale either pods or nodes in a cluster. It automatically increases the size of an Auto Scaling group so that pods can continue to be placed successfully.

Connecting to the Lab

  1. Open your terminal application, and run the following command. (Remember to replace <PUBLIC_IP> with the public IP you were provided on the lab instructions page.)
    ssh cloud_user@<PUBLIC_IP>
  2. Enter your password at the prompt.

Modify the Min/Max Sizes of the Autoscaling Group

  1. In your browser, log in to the AWS Management Console with the credentials provided on the lab instructions page. Make sure you are using the us-east-1 (N. Virginia) region.
    • Navigate to the EC2 service.
    • Click Autoscaling Groups in the left sidebar.
    • Select the autoscaling group that has already been created for you.
    • Note the name of the autoscaling group (we'll need it later).
    • Click Actions > Edit.
    • In the Edit details menu, configure the following settings:
    • Min: 2
    • Max: 8
    • Click Save.

Configure the Cluster Autoscaler

  1. Go back to your terminal application
  2. List the contents of the home directory.
    ls
  3. Edit the cluster_autoscaler.yaml file.
    vim cluster_autoscaler.yaml
  4. Locate the <AUTOSCALING GROUP NAME>placeholder, and replace it with the autoscaling group name we found in the AWS Management Console.
  5. Press Escape, then type :wq to quit the vim text editor.

Apply the IAM Policy to the Worker Node Group Role

  1. List the contents of the asg-policy.json file.
    cat asg-policy.json
    • Copy the content of asg-policy.json to your clipboard.
    • Switch to the AWS Management Console.
    • Navigate to the IAM service.
    • Click Roles in the left sidebar.
    • Type "node" in the search bar.
    • Click the name of the role that appears in the search results to open it.
    • Click + Add inline policy.
    • Click the JSON tab.
    • Delete the default text from the policy editor, and paste in the content of asg-policy.json you copied to your clipboard earlier.
    • Click Review policy.
    • Name the policy "CA".
    • Click Create policy.

Deploy the Cluster Autoscaler

  1. Go back to your terminal application.
  2. Run the following command:
    kubectl apply -f cluster_autoscaler.yaml
  3. Check the cluster autoscaler logs.
    kubectl logs -f deployment/cluster-autoscaler -n kube-system
  4. Press Ctrl + C to exit the logs.

Deploy and Scale the Nginx Deployment

Deploy a Sample Nginx Application

  1. List the contents of the current directory.
    ls
  2. List the contents of the nginx.yaml file.
    cat nginx.yaml
  3. Deploy the nginx deployment.
    kubectl apply -f nginx.yaml
  4. Verify that the deployment was successful.
    kubectl get deployment/nginx-scaleout

Scale the Nginx Deployment

  1. Run the following command:
    kubectl scale --replicas=10 deployment/nginx-scaleout
  2. Check the autoscaler logs again.
    kubectl logs -f deployment/cluster-autoscaler -n kube-system
  3. Go back to the AWS Management Console.
  4. Navigate to the EC2 service.
  5. Click 3 Running Instances.
  6. Go back to your terminal application.
  7. Check the nodes.
    kubectl get nodes
  8. Delete the nginx and cluster autoscaler deployments.
    kubectl delete -f cluster_autoscaler.yaml
    kubectl delete -f nginx.yaml

Conclusion

Congratulations, you've successfully completed this hands-on lab!