Skip to main content
In this lesson, you’ll learn how to interact with Kubernetes clusters on AWS EKS using the kubectl CLI. We have two clusters set up—one for production and another for staging. Follow along as we inspect the kubeconfig file, switch between clusters, deploy a Flask application, perform load testing with k6, and update the application image.

Accessing the EKS Clusters

Open the AWS EKS console to view your clusters. In our setup, the console shows two active clusters named “prod” and “staging,” both running Kubernetes version 1.27 with extended support until July 24, 2025.
The image shows the Amazon Elastic Kubernetes Service (EKS) console with two active clusters named "prod" and "staging," both running Kubernetes version 1.27 with extended support until July 24, 2025.
To interact with these clusters, you need the kubectl CLI utility. Follow the installation instructions provided in the Kubernetes documentation tailored for your operating system.
The image shows a webpage from the Kubernetes documentation, specifically the "Install Tools" section, detailing how to set up Kubernetes tools like kubectl, kind, and minikube on different operating systems.

Inspecting the kubeconfig File

Your kubeconfig file, usually located at ~/.kube/config, contains configurations for your clusters, users, and contexts. To inspect the file, run:
Open config.yaml in your preferred IDE.
Do not commit this file to Git or any public repository as it contains sensitive cluster credentials.
A section from the file for the staging cluster might look like this:
Similarly, the file includes configurations for the production cluster. Notice that the current-context is set to the production cluster by default:

Switching Between Clusters

To operate on different clusters, switch contexts. First, check the nodes on your current production cluster:
The output might resemble:
To switch to the staging cluster, execute:
After switching, verify the change:
The displayed node names will differ, confirming that you are now connected to the staging cluster.

Deploying the Flask Application

Our Kubernetes configurations are stored in the k8s/ directory, which includes the deployment.yaml and service.yaml files.

Deployment Configuration

The deployment.yaml file sets up a deployment for a Flask application with three replicas:

Service Configuration

The service.yaml file defines a LoadBalancer service to expose the Flask application externally:
This configuration assigns an external IP and possibly a DNS name that routes incoming traffic to the correct pods.

Deploying Resources to the Cluster

Before deploying, confirm that your current context is correct:
Deploy all resources (both deployment and service) with:
You should see output similar to:
Next, verify that the deployment and pods are running:
Example output:
And check the pods:
Example output:
Finally, retrieve the service details to access your application:
Example output:
Copy the EXTERNAL-IP or hostname and access your application on port 5000.

Load Testing with k6

Use k6 to simulate user traffic and measure your application’s performance. k6 lets you define virtual users (VUs), duration, and thresholds for request response times. Create a file named acceptance-test.js with the following content:
The target URL is provided via an environment variable. Retrieve the external hostname and port of your service with a command similar to:
Then run the k6 test by setting the SERVICE environment variable:
During the test, k6 will simulate 10 virtual users over 10 seconds, ensuring that 90% of the requests complete in under 600 milliseconds. After the test, you’ll see statistical data including average, median, and maximum response times.

Updating the Application Version

Our current deployment uses version 3 of the image:
To update the application to a new version (for example, v5), follow these steps:
  1. Build the New Image
  2. Push the Image to Docker Hub
  3. Update the Deployment in Kubernetes Use the kubectl set image command to update the image version:
    You should see a confirmation:
Finally, verify the rollout status of your deployment and refresh your application to ensure it is now using version 5.
This lesson covered managing multiple Kubernetes clusters, deploying a Flask application, conducting load tests with k6, and updating the application version seamlessly—all crucial skills for maintaining an efficient CI/CD pipeline.

Watch Video