Skip to main content

Scaling a Cluster with Python

Hands-On Lab

 

Photo of John Marx

John Marx

Training Architect

Length

01:00:00

Difficulty

Beginner

This lab guides the student through the final component of the proof-of-concept. This lab uses kops to scale a cluster after a Python program edits the cluster configuration YAML file. This is all done from a Bastion Host.

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.

Scaling a Cluster with Python

Introduction

This lab guides the student through the final component of the proof-of-concept. This lab uses kops to scale a cluster after a Python program edits the cluster configuration YAML file. This is all done from a Bastion Host.

Solution

Start by logging in to the Bastion Host using the credentials provided on the hands-on lab page:

ssh cloud_user@PUBLIC_IP_ADDRESS_OF_BASTION_HOST

Create a cluster with kops

  1. To create a Kubernetes Cluster from the Bastion Host, input the following command:

    $ . ./k8s-create.sh
  2. You may view the default YAML templates created by kops with any of the following commands:

    kops edit cluster

    Or to look at the instance group for the nodes:

    kops edit ig nodes
  3. After looking at the base installation, you may create the cluster by entering:

    kops update cluster --yes

Validate the cluster that was created

  1. To validate the newly created cluster:

    kops validate cluster

    And eventually, after the EC2 servers are up:

    kubectl get nodes

Use Python to increase the nodes in the instance group

You may view the files below from the GitHub site, or by simply using cat.

  1. The link for the GitHub repo is:

    https://github.com/linuxacademy/content-aiops-essentials
  2. To look at the Python source code in scale_cluster.py:

    cat scale_cluster.py
  3. Also look at the template YAML for the instance group:

    cat instance.yaml
  4. Also, look at the edit_cluster.sh script that edits the instance.yaml file:

    cat edit_cluster.sh
  5. Now execute the command to scale the cluster:

    python scale_cluster.py

Validate that the cluster was scaled

  1. You may simply validate the number of worker nodes running by entering:

    kubectl get node

Conclusion

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