Skip to main content

Command Palette

Search for a command to run...

Day 3: Docker, Docker Compose, and MicroK8s Installation on Ubuntu 22.04

Updated
โ€ข3 min read
Day 3: Docker, Docker Compose, and MicroK8s Installation on Ubuntu 22.04

In this guide, we will walk through the installation of Docker, Docker Compose, and MicroK8s on Ubuntu 22.04. The commands are tested on the following machine specs:

  • RAM: 4GB

  • CPU: 2 cores

  • Storage: 25GB


๐Ÿš€ Docker & Docker Compose Installation on Ubuntu 22.04

๐Ÿ”„ Step 1: Update the Machine

sudo apt update -y

๐Ÿงน Step 2: Remove Conflicting Packages

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do 
  sudo apt-get remove $pkg; 
done

๐Ÿ“ฆ Step 3: Setup Dockerโ€™s APT Repository

Add Docker's Official GPG Key:

sudo apt-get update
sudo apt-get install ca-certificates curl -y
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

Add Docker Repository:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

๐Ÿ“ฅ Step 4: Install Docker & Docker Compose

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

โœ… Step 5: Verify Docker Installation

sudo docker run hello-world

๐Ÿ‘จโ€๐Ÿ’ป Step 6: Run Docker as a Non-Root User

sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
docker run hello-world

Now you can run Docker without sudo.


โ˜ธ๏ธ Install MicroK8s on Ubuntu 22.04

๐Ÿ”„ Step 1: Update the Machine

sudo apt update -y

๐Ÿ“ฅ Step 2: Install MicroK8s

sudo snap install microk8s --classic --channel=1.32

๐Ÿ‘ฅ Step 3: Add Your User to the MicroK8s Group

sudo usermod -a -G microk8s $USER
mkdir -p ~/.kube
chmod 0700 ~/.kube

๐Ÿ”„ Step 4: Apply Group Changes

Exit and log in again or run:

exit

โœ… Step 5: Check MicroK8s Status

microk8s status --wait-ready

๐Ÿ”— Step 6: Set Kubernetes Alias

alias kubectl='microk8s kubectl'

โ˜ธ๏ธ Step 7: Access Kubernetes Cluster

kubectl get nodes

๐Ÿ—๏ธ Adding a Worker Node to MicroK8s Cluster

๐Ÿ“ฅ Step 1: Install MicroK8s on Worker Node

sudo apt update -y
sudo snap install microk8s --classic --channel=1.32

๐Ÿ–ฅ๏ธ Step 2: Get Join Command from Master Node

microk8s add-node

This will provide a join command like:

sudo microk8s join <join-command>

โš ๏ธ Important: Both machines (master and worker) must be on the same network.

๐Ÿ”— Step 3: Run Join Command on Worker Node

sudo microk8s join <join-command>

โœ… Step 4: Verify Node is Joined (on Master Node)

microk8s kubectl get nodes

๐Ÿ”— Optional: Set Alias for kubectl

alias kubectl='microk8s kubectl'

โน๏ธ To Stop MicroK8s

microk8s stop

โœ… Conclusion

Youโ€™ve successfully installed Docker, Docker Compose, and MicroK8s on your Ubuntu 22.04 machine. Whether youโ€™re running containers or deploying Kubernetes clusters locally, this guide should help you get started with containerization and orchestration smoothly.

More from this blog

DevOps Journey with M Hassan

174 posts

I am writing these blogs because I recently completed a comprehensive DevOps course where I gained in-depth knowledge of the topics mentioned. As I progressed through the course, I realized the importance of having a concise and accessible resource to revise and reinforce my understanding of each topic. Therefore, I decided to create cheat sheets in the form of blog posts. These cheat sheets will not only serve as a handy reference for myself but also benefit others who are also interested in mastering DevOps concepts. By documenting each topic and providing concise explanations, I aim to create a valuable resource that simplifies complex concepts and facilitates hands-on practice. This way, I can solidify my own understanding while helping others on their DevOps journey.