Kubernetes: How to Deploy an Nginx Image Using AWS EKS

Hasan Cheema
Nerd For Tech
Published in
6 min readApr 9, 2023

Overview:

AWS Elastic Kubernetes Service (EKS) is a managed service that enables you to run Kubernetes on AWS without needing to install, operate, and maintain your own Kubernetes control plane.

In this article, I will show you how to deploy a Nginx web server with Kubernetes (CLI). We will create an EKS cluster and utilize kubectl to handle the deployment and scaling of Nginx. The aim of this article is to have a fundamental understanding of how to deploy and manage containerized applications in the cloud with EKS and kubectl.

What is Kubernetes?

Kubernetes automates operational tasks of container management and includes built-in commands for deploying applications, rolling out changes to your applications, scaling your applications up and down to fit changing needs, monitoring your applications, and more, making it easier to manage applications.

What is Nginx Image?

Ngnix is open-source software and a tool that has the feature set to be many things, a web server, reverse proxying, caching, load balancing, media streaming, logging, and many more.

Objectives:

1. Create a deployment that runs the nginx image.
2. Display the details of this deployment
3. Check the event logs from the deployment
4. Delete the deployment
5. Do all of the above in EKS Cluster

Preconditions:

1. Free tier AWS Account
2. AWS Cloud9 Environment
3. Kubernetes Installed
4. Basic Knowledge of Linux

Step 1: Launch an EC2 Instance

Log in to the AWS Management Console, navigate to EC2 Dashboard, and click on Launch Instance. Next, we will do the following configurations to create our Instance.

1. Give your Instance a name
2. Select your AMI for purpose of this project we will select (Amazon Linux)
3. For instance type select t2.micro
4. Select a key pair (I will be creating a new one for this project)
5. Select create security group under Network settings
6. Click on Launch instance

Now that we have our instance up and running, we will configure the command line tools. To build a Kubernetes cluster, you must use CLI tools and your AWS account. From the EC2 dashboard, select the check box and select an instance as shown below. Click Connect to initialize the connection to your instance.

Normally I would SSH into the instance, but for the purpose of this project, we will be using the ECE Instance Connect and click the Connect button to connect to the instance we selected earlier. Your browser will be redirected to a new window and show a temporary SSH session with your EC2 instance, shown below.

Step 2: Install and update CLI tools

First, we need to make sure that our AWS CLI version is up to date. Use the following command to check your AWS version.

aws --version 

Next, we will run the following commands to update our AWS CLI version.

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install --bin-dir /usr/bin --install-dir /usr/bin/aws-cli --update

After running the above commands, our CLI should be updated.

Step 3: Configure the CLI

Run the aws configure command to configure your instance. You will need to enter your access key and secret access key and pick a region along with the format you want. I will be choosing the us-west-1 region, but you can select a region you are closer to.

Step 4: Install Kubectl and eskctl

Use the following commands to install kubectl first.

curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.16.8/2020-04-16/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
kubectl version --short --client

Next, we will use the following commands to install eskctl.

curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl version

As you can see, we have successfully updated the kubectl and eksctl.

Step 5: Create the EKS Cluster

Use the following command to create an EKS cluster. The command will create an EKS cluster named week19-eks running in the us-west-1 region. I wanted to create 4 worker nodes with at least 1 minimum to 4 maximum that are managed.

 eksctl create cluster --name <cluster_name> --region us-west-1 --nodegroup-name <worker_node_name> --node-type t3.medium --nodes 3 --nodes-min 1 –-nodes-max 4 --managed

Step 6: Verify if our EKS cluster is created

Go back to the AWS console and head over to the Cloudformation dashboard click on Stacks, select your cluster and navigate your way to the Events tab to see everything being created.

Step 7: Verify if the cluster is active

From the AWS console, navigate your way to the Elastic Kubernetes Service (EKS) to see if the cluster is activated.

Navigate to the EC2 Instance, and you should see 4 instances running 1 should be the control plane and three worker nodes.

Step 1: Create a deployment that runs the nginx image

Head over to the CLI console and run the following commands.

eksctl get cluster
aws eks update-kubeconfig --name week19-eks --region us-west-1
kubectl get nodes

Next, run the following command to create our deployment.

kubectl create deployment <deployment_name> --image nginx

2. Display the details of this deployment

Use the following command to show all the information about the Pods.

kubectl get deployments
kubectl get pods
kubectl describe deployment <deployment name>

3. Check the event logs from the deployment

Use the following command to check the event logs for the deployment.

kubectl logs deployment/<deployment name>

4. Delete the Cluster

Use the following command to delete your cluster.

eksctl delete cluster <cluster name>

Just like that, we have deleted our cluster and EC2 instances.

Conclusion:

In conclusion, deploying an Nginx image using AWS EKS is a straightforward process that can be achieved using the command line interface. By creating a deployment, running the Nginx image, and displaying deployment details and event logs, it is possible to monitor and manage the application effectively. With AWS EKS, you can easily place all of these actions within a cluster, making it easier to manage multiple deployments and applications efficiently. By following these steps, you can deploy Nginx images on AWS EKS with ease and ensure the smooth operation of your application.

Thank you for reading my post! Be sure to clean up your environment after.

--

--