Scaling Kubernetes on AWS: Real-World Approaches for Cloud-Native Success

Understanding Declarative Management in Kubernetes πŸ“œ

In Kubernetes, the declarative approach means describing the desired state of your infrastructure using configuration files (typically YAML), rather than issuing specific commands to modify resources. This is in contrast to the imperative approach, where you define explicit steps and commands.

In a declarative setup:

  • πŸ› οΈ You define what the final state should look like

  • πŸ” Kubernetes continuously reconciles the actual state to match the desired state

  • πŸ”§ If something changes unexpectedly (like a crashed pod), Kubernetes will automatically correct it

πŸ’‘ Benefits of the Declarative Approach

  • 🩹 Self-healing: Kubernetes automatically restores the desired state

  • 🧾 Version control: YAML files can be tracked and reviewed via Git

  • πŸ§ͺ Reproducibility: Consistent results across environments

  • πŸ•΅οΈβ€β™‚οΈ Auditability: System changes are documented in code

A simple example: instead of manually starting three containers, you declare:

replicas: 3

If one container crashes, Kubernetes automatically brings up another to maintain the count πŸ’ͺ

Kubernetes Controllers and the Control Loop Pattern πŸ”

Kubernetes uses controllers to maintain this declared state. Examples include:

βš™οΈ Deployment Controller

  • Ensures a specific number of replicas are running

  • Automatically replaces unhealthy pods

πŸ“¦ ReplicaSet Controller

  • Manages the number of identical pods based on deployment

πŸ–₯️ Node Controller

  • Monitors node availability and manages pod eviction on failure

🧠 StatefulSet Controller

  • Handles deployment and scaling of stateful applications

  • Ensures unique identity and persistent storage for each pod

All controllers follow a reconciliation loop:

  1. πŸ‘οΈ Observe the actual state

  2. βš–οΈ Compare it with the desired state

  3. πŸ”§ Act to reconcile differences

  4. πŸ” Repeat constantly

Declarative Deployment Example πŸ“„

Here's a sample deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

When you apply this using:

kubectl apply -f deployment.yaml

Kubernetes automatically manages the deployment lifecycle for you βš™οΈπŸ“¦

Getting Started with EKS: Declarative Cluster Creation πŸ› οΈ

βœ… Prerequisites

  • An AWS account with admin access πŸ‘€

  • Install the following:

    • 🧰 AWS CLI (v2)

    • πŸ§ͺ kubectl

    • πŸ—οΈ eksctl

πŸ“˜ Need help creating an EC2 instance? Follow this guide: Deploying EC2 Instances with Shared EFS Storage

πŸ” Step 1: Configure IAM

  1. Go to IAM > Users

  2. Attach the AdministratorAccess policy

  3. Create an access key for CLI use πŸ”‘

πŸ–₯️ Step 2: Install AWS CLI

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

Then configure it:

aws configure

πŸ”§ Step 3: Install kubectl

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

πŸ”¨ Step 4: Install eksctl

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/bin

Step 5: Provision an EKS Cluster β˜οΈπŸ”§

Let’s now create a cluster using a proper instance type like t3.medium. Using t2.micro or similar very small instance types often leads to issues like insufficient CPU/memory, unstable networking, or failed pod scheduling.

To avoid those limitations, we recommend using t3.medium, which offers more resources for workloads and better networking performance ⚑

eksctl create cluster \
  --name dev \
  --region eu-north-1 \
  --nodegroup-name standard-workers \
  --node-type t3.medium \
  --nodes 2 \
  --nodes-min 1 \
  --nodes-max 3 \
  --managed

⏳ This takes about 10–15 minutes. It sets up control plane, VPC, security groups, and auto-scaling worker nodes βš™οΈπŸŒ

🧭 Step 6: Update kubeconfig

aws eks --region eu-north-1 update-kubeconfig --name dev

πŸš€ Deploy a Sample Application

🧬 Clone a sample GitHub repository

sudo yum install -y git
git clone https://github.com/ACloudGuru-Resources/Course_EKS-Basics
cd Course_EKS-Basics

🧐 Review the manifests

cat nginx-deployment.yaml
cat nginx-svc.yaml

πŸ§‘β€πŸ’» Apply the service and deployment

kubectl apply -f nginx-svc.yaml
kubectl apply -f nginx-deployment.yaml

πŸ“Š View status

kubectl get svc
kubectl get deployment
kubectl get pod
kubectl get rs
kubectl get node

🌍 Access via Load Balancer

curl "<LOAD_BALANCER_DNS_HOSTNAME>"

Replace with the actual DNS from kubectl get svc 🌐

Paste the DNS in your browser to view the Nginx welcome page πŸŽ‰

πŸ”„ Test High Availability

Stop one worker node in the EC2 console. Kubernetes will:

  • ❌ Mark the node as NotReady

  • πŸ” Reschedule pods to another node

  • βš™οΈ Possibly launch a new node if within scaling range

Check node and pod status:

kubectl get node
kubectl get pod

Wait a few minutes for the new node and pods to stabilize πŸ”

🧹 Cleanup

When you're done:

eksctl delete cluster --name dev --region eu-north-1

🎯 Conclusion

By using a declarative approach with Kubernetes on EKS, you unlock the benefits of infrastructure as code, automated reconciliation, and easy scaling πŸš€. The declarative model ensures your desired state is always maintained, offering strong foundations for modern, cloud-native application development 🌐

Stay tuned for more hands-on Kubernetes content. Until next time! πŸ‘‹

0
Subscribe to my newsletter

Read articles from Di Nrei Alan Lodam directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Di Nrei Alan Lodam
Di Nrei Alan Lodam