# Prepare EKS clusters - [Prerequisite](#prerequisite) - Provisioning EKS clusters - [Create Locust Cluster](#create-locust-cluster) - [Create Workload Cluster](#create-workload-cluster) (option) - [Result](#result) ## Prerequisite - [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) (check [version release](https://kubernetes.io/releases/)) - [eksctl](https://eksctl.io/introduction/#installation) (check [version release](https://github.com/weaveworks/eksctl/releases)) - [jq](https://stedolan.github.io/jq/download/) - [awscli v2](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-version.html) - [Setting AWS Profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) (with [minimum IAM policies](https://eksctl.io/usage/minimum-iam-policies/)) ```bash # Check your profile aws sts get-caller-identity ``` - Pull this repository ```bash git clone https://github.com/aws-samples/load-testing-eks-cluster-with-locust ``` ## Create Locust cluster ### 1. Settings ```bash # Set optional environment variables export AWS_PROFILE="YOUR_PROFILE" # If not, use 'default' profile export AWS_REGION="YOUR_REGION" # ex. ap-northeast-2 # Set common environment variables export TARGET_GROUP_NAME="locust" export TARGET_CLUSTER_NAME="awsblog-loadtest-${TARGET_GROUP_NAME}" export TARGET_REGION="${AWS_REGION}" # Set specific environment variables export TARGET_EKS_VERSION="1.21" # Check cat < _**Notice**_ > _If you use the variable (`TARGET_EKS_VERSION`) about the Kubernetes version,_ > _maybe you need to check the version of `kubectl` and `eksctl`._ > _We recommand to update the latest for matching those versions._ ### 2. Create EKS cluster Configuration file ```bash # Move to 'eks-clusters' directory from root of repository cd groundwork/eks-clusters # Create ClusterConfig file cat eks-cluster-template.yaml | envsubst > "${TARGET_CLUSTER_NAME}.yaml" ``` ### 3. Provision Locust cluster with eksctl ```bash # Create EKS cluster eksctl create cluster --with-oidc -f "${TARGET_CLUSTER_NAME}.yaml" ``` > _**Notice.**_ > _This step takes about 20 minutes._ > _Because it include that create all things (from VPC to EKS cluster)._ ### 4. Check the provision with connection ```bash # Create kubeconfig for your kubectl eksctl utils write-kubeconfig \ --cluster "${TARGET_CLUSTER_NAME}" \ --region "${TARGET_REGION}" \ --profile "${AWS_PROFILE:-(default)}" ``` ```bash # Check kubeconfig context kubectl config current-context # Like this.. # @..eksctl.io ``` ```bash # Check current nodes kubectl get nodes -L position --sort-by=.metadata.labels.position # Like this.. # NAME STATUS ROLES AGE VERSION POSITION # ip-xxx-xxx-xxx-xxx.TARGET_REGION.compute.internal Ready 46s MATCH_ON_EKS_VERSION addon # ip-xxx-xxx-xxx-xxx.TARGET_REGION.compute.internal Ready 48s MATCH_ON_EKS_VERSION locust # ip-xxx-xxx-xxx-xxx.TARGET_REGION.compute.internal Ready 52s MATCH_ON_EKS_VERSION locust # ip-xxx-xxx-xxx-xxx.TARGET_REGION.compute.internal Ready 44s MATCH_ON_EKS_VERSION locust ``` ### 5. Set IdP federation for OIDC provider associated with cluster ```bash eksctl utils associate-iam-oidc-provider --cluster=${TARGET_CLUSTER_NAME} --approve ``` - Refer. [How to find the federated OIDC Provider?](https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/enable-iam-roles-for-service-accounts.html) #### (option) Add identity to auth ConfigMap on other IAM user ```bash # Set target ARN export IAM_USER_ARN="USER_OR_ROLE_ARN" # e.g arn:aws:iam::111122223333:user/USER_NAME_A export MAP_USERNAME="admin-$(echo ${IAM_USER_ARN} | awk -F"/" '{print $2}')" # Check cat <