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.

Customized Cloud Solutions to Drive your Business Success

  • Cloud Migration
  • Devops
  • AIML & IoT
Know More

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.

 

Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.

  • Cloud Training
  • Customized Training
  • Experiential Learning
Read More

About CloudThat

CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAWS GenAI Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery Partner AWS Microsoft Workload PartnersAmazon EC2 Service Delivery PartnerAmazon ECS Service Delivery PartnerAWS Glue Service Delivery PartnerAmazon Redshift Service Delivery PartnerAWS Control Tower Service Delivery PartnerAWS WAF Service Delivery PartnerAmazon CloudFront Service Delivery PartnerAmazon OpenSearch Service Delivery PartnerAWS DMS Service Delivery PartnerAWS Systems Manager Service Delivery PartnerAmazon RDS Service Delivery PartnerAWS CloudFormation Service Delivery PartnerAWS ConfigAmazon EMR and many more.

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!