Kubernetes on AWS: Setting up a cluster on Amazon Web Services (with Amazon EKS)

Prerequisites
Before you begin, you will need the following:
- An AWS account with administrative access
- A basic understanding of Kubernetes concepts
- A local machine with the
aws
andkubectl
command-line tools installed
Step 1: Create an Amazon EKS Cluster
Amazon Elastic Kubernetes Service (EKS) is a managed Kubernetes service that makes it easy to run Kubernetes on AWS without the need to manage your own Kubernetes control plane. To create an EKS cluster, follow these steps:
- Open the AWS Management Console and navigate to the EKS console.
- Click on “Create cluster”.
- Choose a name for your cluster and select the region where you want to create it.
- Choose the Kubernetes version you want to use.
- Choose the type of control plane you want to use: either managed or self-managed.
- Select the number of nodes you want to create in your cluster.
- Choose the instance type and size for your nodes.
- Choose the networking options for your cluster.
- Review your settings and click on “Create”.
After you click “Create”, the EKS service will create your cluster and the necessary AWS resources, such as EC2 instances and security groups. This process may take several minutes.
Step 2: Configure kubectl
Once your cluster is created, you need to configure kubectl
to access it. Follow these steps:
- Install the
aws
CLI tool if you haven’t already done so. - Run the following command to update your
kubectl
configuration: aws eks update-kubeconfig --name my-cluster --region us-west-2
- Replace
my-cluster
with the name of your EKS cluster, andus-west-2
with the region where your cluster is located. - This command updates your
kubectl
configuration to use the AWS IAM user or role that you used to create your cluster. It also sets the current context to your EKS cluster.
Step 3: Verify Your Cluster
To verify that your cluster is working correctly, run the following command:
kubectl get nodes
This command should return a list of nodes in your cluster. If you see a list of nodes, your cluster is working correctly.
Step 4: Deploy Applications to Your Cluster
Now that you have a working EKS cluster, you can deploy applications to it. You can use Kubernetes manifests to deploy applications to your cluster.
Here’s an example manifest that deploys a simple nginx application:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- name: http
port: 80
targetPort: 80
type: LoadBalancer
Save this manifest to a file named nginx.yaml
, then run the following command to deploy it to your cluster:
kubectl apply -f nginx.yaml
This command will create a Deployment with three replicas of the nginx container and a Service to expose the nginx Deployment.
In this tutorial, we explored how to set up a Kubernetes cluster on Amazon Web Services using Amazon EKS. Check out my next posts to learn how to replicate this process on GCP and Azure.
If you’re interested in learning more about Kubernetes, check out my book: Learning Kubernetes — A Comprehensive Guide from Beginner to Intermediate by Lyron Foster ( https://a.co/d/aLXDvsZ )
Lyron Foster is a Hawai’i based African American Author, Musician, Actor, Blogger, Philanthropist and Multinational Serial Tech Entrepreneur.