Learn to interact with Kubernetes clusters on AWS EKS using kubectl, deploy a Flask application, perform load testing, and update application images.
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.
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.
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.
To operate on different clusters, switch contexts. First, check the nodes on your current production cluster:
Copy
Ask AI
kubectl get node
The output might resemble:
Copy
Ask AI
NAME STATUS ROLES AGE VERSIONip-192-168-60-39.ec2.internal Ready <none> 5h33m v1.27.15-eks-1552ad0ip-192-168-8-155.ec2.internal Ready <none> 5h33m v1.27.15-eks-1552ad0
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:
Copy
Ask AI
import http from "k6/http";import { sleep } from "k6";export const options = { vus: 10, duration: "10s", thresholds: { http_req_duration: ["p(90)<600"], // 90% of requests must complete in under 600ms },};export default function () { http.get(`http://${__ENV.SERVICE}`); sleep(1);}
The target URL is provided via an environment variable. Retrieve the external hostname and port of your service with a command similar to:
Copy
Ask AI
kubectl get svc flask-app-service -o jsonpath='{.status.loadBalancer.ingress[0].hostname}:{.spec.ports[0].port}'
Then run the k6 test by setting the SERVICE environment variable:
Copy
Ask AI
k6 run -e SERVICE=<external-hostname>:5000 acceptance-test.js
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.
Update the Deployment in KubernetesUse the kubectl set image command to update the image version:
Copy
Ask AI
kubectl set image deployment/flask-app flask-app=sanjeevkt720/jenkins-flask-app:v5
You should see a confirmation:
Copy
Ask AI
deployment.apps/flask-app image updated
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.