Kubernetes (K8s) Single-Node Setup on Ubuntu 22.04 for Beginners

Kubernetes (K8s) is a powerful open-source platform for automating deployment, scaling, and operations of application containers. A single-node...


0

Introduction

Kubernetes (K8s) is a powerful open-source platform for automating deployment, scaling, and operations of application containers. A single-node Kubernetes setup is an excellent way for beginners to get hands-on experience without the complexities of a multi-node cluster. This guide will walk you through setting up a Kubernetes single node on Ubuntu 22.04. By the end, you’ll have a functional Kubernetes environment on your local machine to deploy and manage containers.

Prerequisites

Before starting the Kubernetes single node setup, ensure you have the following:

  • A machine running Ubuntu 22.04
  • A user account with sudo privileges
  • At least 2 GB of RAM and 2 CPUs

Ensure you have a stable internet connection, as you’ll be downloading necessary packages.

Step 1: Update System Packages

First, update your Ubuntu system packages to the latest versions. This ensures you have the latest security patches and software updates. “`bash
sudo apt update && sudo apt upgrade -y

This command updates the package lists and upgrades installed packages.

## Step 2: Install Docker

Docker is required for Kubernetes to manage containers. Start by installing Docker. ```bash
sudo apt install docker.io -y

This installs Docker, a container runtime required for Kubernetes single node operation. To ensure Docker is set up correctly, enable and start the Docker service:

sudo systemctl enable docker
sudo systemctl start docker

These commands ensure Docker starts with the system and runs the container workloads.

Step 3: Add Kubernetes Repository

Next, add the Kubernetes repository to your system. This repository contains the components necessary for Kubernetes installation. “`bash
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl
sudo curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add –
echo “deb https://apt.kubernetes.io/ kubernetes-xenial main” | sudo tee /etc/apt/sources.list.d/kubernetes.list

This setup allows your system to retrieve packages and updates from the Kubernetes repository.

## Step 4: Install Kubernetes Components

Now, install the essential Kubernetes components: kubeadm, kubelet, and kubectl. ```bash
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

These tools are crucial for managing the Kubernetes single node environment. Kubeadm automates cluster setup, kubelet runs on each node to start pods, and kubectl is the command-line tool to interact with the cluster.

Step 5: Initialize Kubernetes Single Node

Initialize your Kubernetes single node using kubeadm. This step configures the node and starts the cluster. “`bash
sudo kubeadm init –pod-network-cidr=192.168.0.0/16

The `--pod-network-cidr` flag configures the pod network required by most network add-ons. After initialization, implement user-specific configurations:

```bash
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

These commands configure kubectl to communicate with the cluster as your current user.

Step 6: Deploy A Pod Network

A pod network is essential for communication between Kubernetes pods. Flannel is a popular choice for a pod network. “`bash
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

This command deploys Flannel, enabling network communication across your Kubernetes single node.

Step 7: Verify Installation



Verify that your Kubernetes single node setup is running smoothly. Use kubectl to check node status. ```bash
kubectl get nodes

This command lists all nodes in your cluster. Ensure your node status is Ready. Check the cluster components:

kubectl get pods --all-namespaces

This lists all pods running in your cluster. Confirm all essential services are up and running.

Step 8: Deploy A Sample Application

Now, test your Kubernetes single node setup by deploying a simple application. For instance, deploy an Nginx web server. “`bash
kubectl create deployment nginx –image=nginx
kubectl expose deployment nginx –port=80 –type=NodePort

These commands deploy an Nginx server and expose it on port 80, allowing access via your node's IP. To get the NodePort of your service, use:

```bash
kubectl get services

Access your application by entering http://<your-node-ip>:<NodePort> in a web browser.

Step 9: Clean Up Resources

After experimenting, clean up resources to avoid unnecessary consumption. “`bash
kubectl delete service nginx
kubectl delete deployment nginx

“`

These commands remove the Nginx deployment and service, freeing up resources on your Kubernetes single node.

Conclusion

Setting up a Kubernetes single node on Ubuntu 22.04 is an excellent way to begin learning about Kubernetes. With this setup, you can deploy, manage, and scale applications in a controlled, local environment. Practice with different Kubernetes features to deepen your understanding and prepare for managing more complex, multi-node clusters.


Like it? Share with your friends!

0

What's Your Reaction?

hate hate
0
hate
confused confused
0
confused
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
lol lol
0
lol
omg omg
0
omg
win win
0
win
Anoop Patel