FedoraRHEL Based

How To Install Kubernetes on Fedora 41

Install Kubernetes on Fedora 41

Kubernetes has become the de facto standard for container orchestration in modern cloud-native environments. Whether you’re managing microservices or scaling applications, Kubernetes provides the necessary tools to automate deployment, scaling, and management of containerized applications. In this guide, we’ll walk you through the complete process of installing Kubernetes on Fedora 41, ensuring that you have a fully functional cluster by the end.

Prerequisites

Before diving into the installation process, there are a few prerequisites you need to meet:

  • System Requirements: Ensure your system has at least 2 CPUs, 2GB of RAM, and 20GB of disk space.
  • Fedora 41 Installed: You should have a fresh installation of Fedora 41 with root or sudo access.
  • Basic Knowledge: Familiarity with Linux commands and networking concepts will be helpful.
  • Container Runtime: You will need either Docker or CRI-O installed as the container runtime for Kubernetes.

Step 1: Update Your System

The first step in setting up Kubernetes on Fedora is to ensure your system is up-to-date. Keeping your system updated ensures that you have the latest security patches and software versions.

sudo dnf update -y
sudo reboot

If any kernel updates are applied during this process, you may need to reboot your system for the changes to take effect.

Step 2: Install Container Runtime (Docker or CRI-O)

Kubernetes requires a container runtime to manage containers. You can choose between Docker or CRI-O. Below are instructions for both options.

Option A: Install Docker

If you prefer Docker as your container runtime, follow these steps:

Remove Conflicting Packages: Fedora comes with Podman and Buildah by default, which may conflict with Docker. Remove them first:

sudo dnf remove podman buildah -y

Install Docker:

sudo dnf install docker-ce docker-ce-cli containerd.io -y

Start and Enable Docker Service:

sudo systemctl start docker
sudo systemctl enable docker

Option B: Install CRI-O

If you prefer using CRI-O as your container runtime (which is more lightweight and optimized for Kubernetes), follow these steps:

Install CRI-O and Networking Plugins:

sudo dnf install cri-o containernetworking-plugins -y

Start and Enable CRI-O Service:

sudo systemctl start crio
sudo systemctl enable crio

Step 3: Configure Kernel Modules and Network Settings

Kubernetes requires certain kernel modules and network settings to function properly. These settings will ensure that your system is ready for pod networking.

Load Kernel Modules:

sudo modprobe overlay
sudo modprobe br_netfilter

Create Sysctl Configuration File:

Create a new file called `/etc/sysctl.d/k8s.conf` with the following content:

net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1

Apply the Changes:

sudo sysctl --system

Step 4: Disable SELinux (Optional but Recommended)

Kubernetes recommends disabling SELinux for smoother operation. While not mandatory, it can help avoid potential issues related to security policies blocking certain actions.

Set SELinux to Permissive Mode Temporarily:

sudo setenforce 0

Permanently Disable SELinux:

Edit the SELinux configuration file located at `/etc/selinux/config` and change `SELINUX=enforcing` to `SELINUX=permissive`.

Reboot (if needed):

If you made changes to SELinux settings, reboot your system for them to take effect.

Step 5: Install Kubernetes Components (kubeadm, kubelet, kubectl)

The next step is installing the necessary Kubernetes components: `kubeadm`, `kubelet`, and `kubectl`. These tools are essential for managing your cluster.

Add Kubernetes Repository

Create a new repository file at `/etc/yum.repos.d/kubernetes.repo` with the following content:

[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl

Install Kubernetes Packages

sudo dnf install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

Enable kubelet Service

sudo systemctl enable --now kubelet

Step 6: Initialize the Kubernetes Cluster Using kubeadm

You are now ready to initialize your control plane node using `kubeadm`. This step will configure all necessary components for running a single-node cluster (or multi-node if desired).

Initialize Control Plane Node

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

This command sets up the control plane components such as etcd, API server, controller manager, and scheduler. The `--pod-network-cidr=10.244.0.0/16` flag is used because we will be using Flannel as our pod network add-on later.

Configure kubectl for Non-root User Access

If you want to run `kubectl` commands as a non-root user (recommended), follow these steps:

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

Verify Cluster Initialization

You can verify that your cluster has been initialized successfully by running the following commands:

kubectl cluster-info 
kubectl get nodes 

Step 7: Set Up Pod Network Add-on (Flannel)

Kubernetes requires a pod network add-on to allow communication between pods across different nodes in the cluster. We will use Flannel as our network add-on in this guide.

Install Flannel Network Add-on:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml 

Verify Pod Network Installation:

kubectl get pods --all-namespaces 

Step 8: Join Worker Nodes to the Cluster (Optional)

If you want to expand your cluster by adding worker nodes, follow these instructions on each worker node that you wish to join to the control plane node.

Retrieve Join Command from Control Plane Node

kubeadm token create --print-join-command 

Run Join Command on Worker Node(s)

sudo kubeadm join <control-plane-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>

Verify Worker Node Status

kubectl get nodes 

Step 9: Testing the Cluster with a Sample Application

Your cluster should now be fully operational! To test it further, let’s deploy a simple Nginx application using Kubernetes.

Create an Nginx Deployment

kubectl create deployment nginx --image=nginx 

Create a Service for Nginx Deployment

kubectl expose deployment nginx --port=80 --type=NodePort 

Verify Deployment Status

kubectl get pods 
kubectl get svc nginx 

Congratulations! You have successfully installed Kubernetes. Thanks for using this tutorial for installing the Kubernetes on your Fedora 41 system. For additional or useful information, we recommend you check the official Kubernetes website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button