AWS, DevOps, Kubernetes

2 Mins Read

Deploying MicroK8s on AWS: A Step-by-Step Guide

Voiced by Amazon Polly

Introduction

In today’s cloud-native world, Kubernetes has become the go-to platform for container orchestration. MicroK8s, a lightweight Kubernetes distribution by Canonical, simplifies Kubernetes deployment and management. This blog will guide you through deploying MicroK8s on AWS, ensuring you have a scalable and robust environment for your applications.

Freedom Month Sale — Upgrade Your Skills, Save Big!

  • Up to 80% OFF AWS Courses
  • Up to 30% OFF Microsoft Certs
Act Fast!

Prerequisites

  • An AWS account with proper permissions to create and manage EC2 instances.
  • Basic knowledge of AWS, EC2, and Linux commands.

Step 1: Launching an EC2 Instance on AWS

Instance Configuration

  1. Instance Type: We will use a medium instance, which provides a good balance of compute power and memory for running MicroK8s.
  2. Operating System: Ubuntu 22.04 LTS is our choice for its stability and compatibility with MicroK8s.
  3. Storage: Allocate 20 GB of disk space to accommodate the MicroK8s installation and workloads.
  4. Security Group Configuration: Configure the security group to allow necessary ports for Kubernetes communication.

 

Security Group Configuration

Create a security group with the following rules:

  • SSH (port 22): Allow SSH access for remote management.
  • HTTP (port 80) and HTTPS (port 443): Allow web traffic for accessing applications.
  • Custom TCP Rules: Open specific ports required by MicroK8s components:

 

PORT SERVICE ACCESS RESTRICTIONS
16443 API server SSL encrypted. Clients need to present a valid password.
10250 kubelet X509 client certificate required.
10255 kubelet Read-only port.
25000 cluster-agent Proper token required.
12379 etcd SSL encrypted. Client certificates are required.
10257 kube-controller HTTPS with authentication.
10259 kube-scheduler HTTPS with authentication.
19001 dqlite SSL encrypted. Client certificates are required.
4789/udp calico Calico networking with VXLAN enabled.
10248 kubelet Localhost healthz endpoint.
10249 kube-proxy Metrics server port.
10251 kube-scheduler HTTP insecurely.
10252 kube-controller HTTP insecurely.
10256 kube-proxy Health check server.
2380 etcd Peer connections.
1338 containerd Metrics port.
30000-32767 NodePort NodePort range.

 

Step 2: Set Hostname

After launching the instance, connect via SSH and set the hostname:

sudo hostnamectl set-hostname microk8s-node1

Step 3: Install MicroK8s

MicroK8s can be installed using Snap, a package manager for Ubuntu.
sudo snap install microk8s --classic --channel=1.28/stable

Step 4: Configure User Permissions

Add your current user to the microk8s group and set up the necessary directories:

sudo usermod -a -G microk8s $USER sudo mkdir -p ~/.kube sudo chown -f -R $USER ~/.kube

Reboot the instance to apply the changes:
sudo reboot

Step 5: Verify MicroK8s Installation

After rebooting, verify the MicroK8s installation:
microk8s status --wait-ready microk8s version microk8s inspect
Check the node details:
cat /var/snap/microk8s/current/var/kubernetes/backend/localnode.yaml

Step 6: Alias kubectl Command

To avoid conflicts with existing kubectl installations, create an alias for MicroK8s kubectl:


nano ~/.bashrc

Add the following line:

alias mkubectl='microk8s kubectl'

Apply the changes:
source ~/.bashrc
You can now use mkubectl for Kubernetes commands. For example:

mkubectl get nodes

Step 7: Deploy an Application

Deploy a demo Nginx application:

<code>microk8s kubectl create deployment nginx –image=nginx –replicas=3 microk8s kubectl get pods </code>

Expose the deployment:

<code>microk8s kubectl expose deployment nginx –type=NodePort –name=nginx-service –port=80</code>

Step 8: Manage MicroK8s

Start and stop MicroK8s services as needed:

<code> microk8s stop microk8s start</code>

Conclusion

By following these steps, you’ve successfully deployed MicroK8s on an AWS EC2 instance. This setup provides a scalable, lightweight Kubernetes environment for your applications. MicroK8s simplifies Kubernetes management, making it easier to deploy, monitor, and scale your workloads. Stay tuned for more on MicroK8s, including advanced configurations, multi-node clusters, and best practices for production deployments. Happy containerizing!

Feel free to reach out for any queries or feedback in the comments below.

 

Freedom Month Sale — Discounts That Set You Free!

  • Up to 80% OFF AWS Courses
  • Up to 30% OFF Microsoft Certs
Act Fast!

About CloudThat

CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.

WRITTEN BY Mehar Nafis

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!