This guide intends to teach you to Set up k3d on AlmaLinux 9.
k3d is a small program made for running a K3s cluster in Docker. K3s is a lightweight, CNCF-certified Kubernetes distribution and Sandbox project. Designed for low-resource environments, K3s is distributed as a single binary that uses under 512MB of RAM.
k3d uses a Docker image built from the K3s repository to spin up multiple K3s nodes in Docker containers on any machine with Docker installed. That way, a single physical (or virtual) machine (let’s call it Docker Host) can run multiple K3s clusters, with multiple server and agent nodes each, simultaneously.
Steps To Set up k3d on AlmaLinux 9
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with AlmaLinux 9.
K3d whole depends on docker. So you need to have Docker installed on your server. To do this, you can follow our guide on Install and Use Docker on AlmaLinux 9.
Install kubectl on AlmaLinux 9
At this point, you need to kubectl package to interact with the cluster we will be creating. To do this, run the commands below:
# curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" # sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
Then, verify your kubectl installation by checking its version:
kubectl version --output=yaml
Output clientVersion: buildDate: "2023-03-15T13:40:17Z" compiler: gc gitCommit: 9e644106593f3f4aa98f8a84b23db5fa378900bd gitTreeState: clean gitVersion: v1.26.3 goVersion: go1.19.7 major: "1" minor: "26" platform: linux/amd64 kustomizeVersion: v4.5.7
Enable ip_tables module on AlmaLinux 9
K3d comes with traefik and it will need iptables to enable some routing. Now you need to use the command below to enable the ip_tables module:
# sudo modprobe ip_tables # echo 'ip_tables' | sudo tee -a /etc/modules
Install k3d on AlmaLinux 9
At this point, you can use the following command to download and install k3d on your server:
wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
Output Preparing to install k3d into /usr/local/bin k3d installed into /usr/local/bin/k3d
How To Use k3d
At this point, we want to show you to create a single-node cluster with k3d. To do this, you can use the following command. You can choose your desired name.
k3d cluster create orcacluster
You’ll see the following output as it creates your cluster:
Output INFO Prep: Network INFO Created network 'k3d-orcacluster' INFO Created image volume k3d-orcacluster-images INFO Starting new tools node... INFO Creating node 'k3d-orcacluster-server-0' INFO Pulling image 'ghcr.io/k3d-io/k3d-tools:5.4.9' INFO Pulling image 'docker.io/rancher/k3s:v1.25.7-k3s1' INFO Starting Node 'k3d-orcacluster-tools' INFO Creating LoadBalancer 'k3d-orcacluster-serverlb' INFO Pulling image 'ghcr.io/k3d-io/k3d-proxy:5.4.9' INFO Using the k3d-tools node to gather environment information INFO HostIP: using network gateway 172.18.0.1 address INFO Starting cluster 'orcacluster' INFO Starting servers... INFO Starting Node 'k3d-orcacluster-server-0' INFO All agents already running. INFO Starting helpers... INFO Starting Node 'k3d-orcacluster-serverlb' INFO Injecting records for hostAliases (incl. host.k3d.internal) and for 2 network members into CoreDNS configmap... INFO Cluster 'orcacluster' created successfully! INFO You can now use it like this: kubectl cluster-info
It will automatically create a KubeConfig file at “~/.kube/config” and hence you can immediately begin interacting with your cluster via the “kubectl” command. So let us check our cluster information:
Output Kubernetes control plane is running at https://0.0.0.0:45135 CoreDNS is running at https://0.0.0.0:45135/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy Metrics-server is running at https://0.0.0.0:45135/api/v1/namespaces/kube-system/services/https:metrics-server:https/proxy
Also, you can view the pods by using the command below:
kubectl get pods -n kube-system
Output NAME READY STATUS RESTARTS AGE coredns-597584b69b-654kg 1/1 Running 0 4m33s local-path-provisioner-79f67d76f8-pzlp8 1/1 Running 0 4m33s helm-install-traefik-crd-bhqhh 0/1 Completed 0 4m33s metrics-server-5f9f776df5-vtszz 1/1 Running 0 4m33s helm-install-traefik-55rrs 0/1 Completed 2 4m33s svclb-traefik-188963af-jhzbm 2/2 Running 0 3m57s traefik-66c46d954f-k25gc 1/1 Running 0 3m57s
At this point, you are ready to deploy your applications to test them locally or do your various playful escapades with them.
At this point, you have learned to Set up k3d on AlmaLinux 9.
Hope you enjoy it. You may be interested in these articles: