Skip to main content

Command Palette

Search for a command to run...

Kubernetes Architecture, Components, and Installation Guide on AWS EC2

A Comprehensive Guide to Understanding and Setting Up Kubernetes on AWS EC2 with minikube tool

Updated
6 min read
Kubernetes Architecture, Components, and Installation Guide on AWS EC2

Kubernetes Overview

Kubernetes is an open-source platform that automates the deployment, scaling, and management of containerized applications. It orchestrates containers across a cluster of machines, ensuring high availability, scalability, and efficient resource utilization.

What is Kubernetes?

Kubernetes simplifies running software reliably across multiple environments by automating key tasks such as deployment, scaling, and management of containerized applications.

The benefits of using Kubernetes include:

Automated Scaling: Automatically adjusts the number of running containers based on demand.

Efficient Resource Management: Optimizes the use of hardware resources, ensuring efficient workload distribution.

High Availability: Provides built-in mechanisms for maintaining application uptime and recovering from failures.

Portability: Enables consistent application deployment across different environments, from on-premises to cloud.

Self-Healing: Automatically restarts failed containers, replaces unresponsive nodes, and reschedules disrupted workloads.

Simplified Deployment: Streamlines application updates and rollbacks, reducing the complexity of managing software releases.

Extensibility: Supports custom resource definitions and integrations with other tools and services, enhancing its functionality.

Kubernetes Architecture

Master Node (Control Plane)

The Control Plane (formerly known as the Master Node) is the brain 🧠 behind the K8s cluster, assigning tasks and managing the worker nodes with precision.

Components of Master Node:

  1. Control Manager:

    • The Control Manager checks that everything is working correctly.

    • It ensures that the actual state matches the desired state.

    • Example: If we need 4 pods but only 3 are running, the Control Manager will ensure all 4 are running.

  2. etcd: The Database of Kubernetes:

    • etcd is like a database for the K8s cluster. It is a distributed key-value store for the cluster's configuration data, representing the cluster's overall state. It acts as the backbone for all Kubernetes cluster data.
  3. Scheduler:

    • The scheduler is responsible for assigning newly created pods to nodes in the cluster based on resource availability and other constraints.
  4. API Server:

    • The API server in Kubernetes acts as the central hub for managing the entire cluster. It serves as the main interface for all administrative tasks, allowing users, command-line tools, and other components to communicate with the cluster. By exposing the Kubernetes API, the API server enables interaction with the cluster for operations like deploying applications, scaling workloads, and monitoring resources. In essence, it’s the gateway through which all requests and commands are processed within the Kubernetes environment.

Components of Worker Node:

  1. Kubelet:

    • This is the “manager” of each worker node, ensuring all containers on the node are healthy and running as they should be.
  2. Kube Proxy:

    • Think of this as the "traffic cop" for the network. It directs traffic between Pods or from outside clients to Pods, making sure everything gets where it needs to go.
  3. Pod:

    • The smallest units in Kubernetes, a pod is a group of one or more containers.
  4. Container Runtime:

    • It is used to run containers using Docker.

Kubernetes cluster setup with Minikube using AWS EC2

Pre-requisites:

  • Ubuntu OS – Amazon EC2 Instance.

  • sudo privileges

  • Internet access

  • Virtualization support enabled

AWS CLI configuration on Ubuntu Device:

  1. Download the installation file:

      curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
    

  2. Unzip the downloaded file:

      unzip awscliv2.zip
    

  3. Run the installer:

      sudo ./aws/install
    

  4. Verify the installation:

      aws --version
    

Step 1: Launch an EC2 instance with 2 CPU and 4 GB RAM:

  1. Login to the AWS console panel through your AWS account and password.

  2. Click on the Left side corner -> Services -> Compute -> EC2

  3. Click on the Launch Instance button.

  4. Provide the name of the Instance.

  5. Select the OS image where you want to configure Kubernetes. Currently, we have selected the Ubuntu OS.

  6. Select the instance type as below:

    • CPU: 2 vCPUs or more

    • RAM: 4 GB or more

    • Disk: 20 GB or more (for system and application binaries)

    • Network: Sufficient bandwidth for communication between nodes and with external services.

  7. Create Key-Pair.

  8. Set up the networking settings.

  9. Configure the storage settings.

  10. After completing all required settings, click on the “Launch instance”.

  11. Once the Instance status shows 2/2, it means our launched instance is ready to connect.

Connect EC2 instance through SSH:

  1. Click on the “Connect” option.

  2. Follow the steps as mentioned in SSH client.

    1. Change permissions for the key file:

        chmod 400 "Kubernetes-Key.pem"
      

    2. Connect to the instance:

        ssh -i "Key-Pair_Name" ubuntu@ec2-Public_IP-Region_Name.compute.amazonaws.com
      

Step 2: Update and install the required packages:

  1. Update your package lists:

      sudo apt update
    

  2. Install necessary packages:

      sudo apt install -y curl wget apt-transport-https
    

Step 3: Installing Docker, enabling it, and adding the current user to the Docker group:

  1. Install Docker:

      sudo apt install -y docker.io
    

  2. Enable the Docker service:

      sudo systemctl enable --now docker
    

  3. Add the current user to the Docker group:

      sudo usermod -aG docker $USER
    

  4. Check if the Docker service is enabled:

      sudo systemctl status docker
    

Kubernetes Installation

Step 3: Set-Up Minikube:

  1. Download the Minikube package:

      curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
    

  2. Make it executable and move it into /usr/local/bin:

      chmod +x minikube
      sudo mv minikube /usr/local/bin/
    

  3. Check the Minikube version:

      minikube version
    

Step 4: Set-up Kubectl:

  1. Download the Kubectl package:

      curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
    

  2. Make it executable and move it into /usr/local/bin:

      chmod +x kubectl
      sudo mv kubectl /usr/local/bin/
    

  3. Check the Kubectl version:

      kubectl version --short --client
    

Step 5: Start Minikube:

minikube start --driver=docker --vm=true

Step 6:

Check the Minikube service status:

minikube status

Check the Node status:

kubectl get nodes

Step 7: Stop Minikube

When you are done, you can stop the Minikube cluster with:

minikube stop


Step 8: Delete Minikube Cluster (Optional)

If you wish to delete the Minikube cluster entirely, you can do so with:

minikube delete

If you have any questions or need assistance, feel free to leave a comment! 📝 I'm here to help and would be happy to answer them.

If you found this post useful, please give it a thumbs up 👍 and consider following for more helpful content. 😊

Thank you for taking the time to read! 💚

Follow me on LinkedIn here

Kubernetes Architecture, Components, and Installation Guide on AWS EC2