Create an AWS Kubernetes Cluster

πŸ‘

Pro Tip

To create the cluster, we definitely recommend you use eksctl. It will undoubtedly make your life simpler.

eksctl is a tool provided by AWS to create, update, and delete Kubernetes clusters on Amazon Elastic Kubernetes Service (Amazon EKS).

We recommend it against using the AWS web console, as changes made there are hard to track and replicate.

Prerequisites:

For eksctl to work, it also needs the AWS CLI installed.

  1. Install the AWS CLI. Instructions on how to do that are available on the AWS documentation website.

πŸ“˜

You can configure the AWS CLI using the aws configure command.

  1. Install eksctl. Read more on how you can do this on the eksctl website.

Create an AWS Kubernetes cluster

This guide will walk you through the process of quickly setting up a Kubernetes cluster and configuring storage classes using eksctl and bash.

πŸ“˜

Generate your own eksctl template file

If you wish to generate the cluster manually please follow the instructions provided in the eksctl documentation.

Prerequisites

  • Clone the following Bunnyshell github repository.
  • AWS CLI and eksctl installed and configured with appropriate permissions.
  • AWS profile with necessary IAM roles and permissions.

πŸ“˜

Minimum Permissions Required

Please check this link for further information on the permissions required in addition to the ones specified below:

EFS (Elastic File System)

  • elasticfilesystem:CreateFileSystem: To create a new EFS filesystem.
  • elasticfilesystem:DescribeFileSystems: To verify the lifecycle state of the EFS.
  • elasticfilesystem:CreateMountTarget: To create mount targets in public subnets.
  • elasticfilesystem:DescribeMountTargets: To check the status of mount targets.

Create Cluster

Step 1: Export AWS and EKS Variables

Before proceeding, make sure to export the following AWS and EKS environment variables, replacing the values with your specific configurations:

export AWS_PROFILE=profile-name
export AWS_REGION=eu-west-1
export EKS_CLUSTER_NAME=test-cluster-2
export EKS_KUBE_VERSION=1.27

Step 2: Tweak eksctl_template.yaml

Review the eksctl_template.yaml file. You might want to edit the managed node groups or add extra addons as needed.

Step 3: Generate the eksctl Config File

Use the envsubst command to substitute the environment variables from the template file and generate the final eksctl configuration file:

envsubst < eksctl_template.yaml > eksctl_final.yaml

Step 4: Create the Kubernetes Cluster

Generate the Kubernetes cluster using the previously created config file. This process may take approximately 10 minutes, so please be patient:

eksctl create cluster -f eksctl_final.yaml

🚧

You might face the following error while creating the cluster:

Unable to connect to the server: getting credentials: exec plugin is configured to use API version client.authentication.k8s.io/v1alpha1, plugin returned version client.authentication.k8s.io/v1beta1.

In such cases, you can install the AWS EKS vended kubectl (linked here), then run the command cat ~/.kube/config and update the API version line respectively.

Step 5: Add the cluster to your kubectl configuration

Add the cluster to your kubectl configuration by downloading the config from AWS using the following command:

aws eks update-kubeconfig --region $AWS_REGION --name $EKS_CLUSTER_NAME

Post-Checks

Run the following command and make sure you are in the correct context. (This is in case you have other contexts pre-configured)

# Check contexts 
kubectl config get-contexts
# if you are not using a context that contains the name of the new cluster as outputed
# by the eksctl install command please adjust the context using: 
kubectl config use-context name-of-context-from-previous-command

Configuring Storage Classes

πŸ“˜

Manual Configuration

To better understand storage classes and If you wish to configure storage classes manually please follow the following documentation for further information.

EBS

Step 1: Create the Disk (EBS) Storage Class

Create the storage class for Kubernetes:

kubectl create -f k8s/sc_disk.yaml

Step 2: Test EBS

Test the storage class:

kubectl create -f k8s/test_ebs.yaml
kubectl get pvc

# Sample Output
NAME        STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS    AGE
ebs-claim   Bound    pv-xyz   4Gi        RWO            bns-disk-sc     1d

# Once confirmed don't forget to cleanup 
kubectl delete -f k8s/test_ebs.yaml

EFS

Step 1: Configure EFS Storage

This script will create an EFS file system with a security group and a mount target. Next, it will install nfs-subdir-external-provisioner via Helm and configure it to use the EFS.

# Please bare in mind this script has interactive sections
chmod +x configure_efs.sh
./configure_efs.sh

Step 2: Test EFS is Working

Run the following commands to test EFS functionality:

kubectl create -f k8s/test_efs.yaml
kubectl get pvc

# Sample Output 
NAME        STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS    AGE
efs-claim   Bound    pv-abc   5Gi        RWX            bns-network-sc  1d

# Once confirmed don't forget to cleanup 
kubectl delete -f k8s/test_efs.yaml

That's it! You have now set up a Kubernetes cluster using eksctl, configured storage classes, and tested EFS functionality.

Please note that this guide provides a quick setup for a basic Kubernetes cluster. For more advanced configurations, refer to the eksctl documentation and the Kubernetes documentation.


Connecting the cluster to Bunnyshell.

When connecting the cluster to Bunnyshell, you have to provide the following:

  • Cluster name
  • AWS Cluster name
  • Cluster URL
  • Certificate
  • Access Key ID
  • Secret Access Key

By default the configuration will be downloaded to ~/.kube/config-file-name. View this file and extract the relevant information provided below:

  • AWS Cluster name: Corresponds to the name of the cluster.
    Extract only the first part, eg bunnyshell-demo-cluster.
- cluster:
    certificate-authority-data: <very-long-encoded-text-here>
    ...
  name: bunnyshell-demo-cluster.eu-west-1.eksctl.io
  • Cluster URL: Corresponds to the cluster.server key in the below example.
- cluster:
    certificate-authority-data: <very-long-encoded-text-here>
    server: https://2E34896AD30433FAB54DB2F7A984F5C1.gr7.eu-west-1.eks.amazonaws.com
...
  • Certificate: Corresponds to the cluster.certificate-authority-data in the below example.
- cluster:
    certificate-authority-data: <very-long-encoded-text-here>
    server: https://2E34896AD30433FAB54DB2F7A984F5C1.gr7.eu-west-1.eks.amazonaws.com
...
  • Access Key ID and Secret Access Key are needed to programmatically obtain a token for cluster access.
    These can be found in the ~/.aws/credentials file after you have run the aws configure command provided above.

You are good to go!

We wish you happy & frequently successful Deployments!