How to use k3d on Ubuntu?
You can install k3d on Ubuntu, which is a lightweight wrapper to run k3s (a lightweight Kubernetes distribution) in Docker. Follow these steps to install k3d on Ubuntu:
1. Prerequisites
- Docker: k3d uses Docker to run k3s clusters, so make sure Docker is installed and running. You can install Docker if it's not already set up.
Install Docker:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce -y
Verify Docker installation:
sudo systemctl status docker
Add your user to the docker
group to run Docker without sudo
:
sudo usermod -aG docker $USER
Log out and log back in to apply the group changes.
2. Install k3d
You can install k3d using a simple script, Homebrew, or manually by downloading the binary. Here's how to do it using the official installation script:
Method 1: Install Using the Official Script
Verify the installation:
k3d --version
You should see the k3d version output.
Run the following command to install k3d:
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
Method 2: Install Using Homebrew (optional)
If you have Homebrew installed on Ubuntu, you can also install k3d via Homebrew:
Install k3d via Homebrew:
brew install k3d
Make sure Homebrew is installed. If not, install it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3. Create a k3s Cluster Using k3d
Once k3d is installed, you can create a k3s cluster with just one command.
Check that your cluster is running:
kubectl get nodes
If you don't have kubectl
installed, you can install it with:
sudo snap install kubectl --classic
Then, re-run the command to check the cluster status.
Create a k3s cluster with one server node (you can add more nodes as needed):
k3d cluster create mycluster
This will spin up a single-node Kubernetes cluster named mycluster
.
4. Access the k3s Cluster
By default, k3d sets up your kubeconfig
to point to the new cluster. You can inspect your cluster and manage workloads just like a regular Kubernetes cluster.
To access the cluster:
kubectl get all -A
This command shows all running services, pods, and deployments in your k3s cluster.
5. Delete the Cluster
When you're done, you can delete the cluster by running:
k3d cluster delete mycluster
Conclusion
You've successfully installed k3d on your Ubuntu system, which runs a k3s Kubernetes cluster inside Docker. Now you can deploy and test Kubernetes workloads in a lightweight, local environment.