LinuxCommandLibrary

k3d

Run lightweight Kubernetes clusters in Docker

TLDR

Create a cluster

$ k3d cluster create [cluster_name]
copy

Delete a cluster
$ k3d cluster delete [cluster_name]
copy

Create a new containerized k3s node
$ k3d node create [node_name]
copy

Import an image from Docker into a k3d cluster
$ k3d image import [image_name] --cluster [cluster_name]
copy

Create a new registry
$ k3d registry create [registry_name]
copy

SYNOPSIS

k3d [OPTIONS] COMMAND [ARG...]

PARAMETERS

--help
    Show help message and exit.

--version
    Show version and exit.

--verbose
    Enable verbose output.

--kubeconfig-mode value
    Specify permissions mode to set for the kubeconfig file (default: '0644')

cluster create [NAME]
    Create a new k3s cluster.

cluster delete [NAME]
    Delete an existing cluster.

cluster list
    List existing clusters.

node create
    Create new k3s nodes.

node delete
    Delete nodes.

node list
    List nodes.

kubeconfig get [CLUSTER_NAME]
    Get the kubeconfig for a cluster.

DESCRIPTION

k3d is a lightweight wrapper to run k3s (Rancher's minimal Kubernetes distribution) in Docker. It simplifies the creation and management of single- and multi-node Kubernetes clusters for local development and testing. k3d utilizes Docker containers to emulate Kubernetes nodes, offering a fast and efficient alternative to traditional virtual machine-based solutions.

This approach allows developers to rapidly prototype and experiment with Kubernetes features without the overhead of managing full-fledged virtual machines. k3d supports various configurations, including single-node clusters for quick setups and multi-node clusters to simulate real-world distributed environments. It also handles network configuration and port mapping, making Kubernetes services easily accessible from the host machine. k3d is designed to be simple to use, requiring minimal setup and configuration to get a cluster up and running. It is a great tool for learning Kubernetes, developing cloud-native applications, and testing Kubernetes deployments locally before deploying to production environments. Its minimal footprint and fast startup times make it suitable for integration into CI/CD pipelines.

CAVEATS

k3d requires Docker to be installed and running on the host machine. Clusters created with k3d are only suitable for development and testing purposes and not for production environments.

NETWORKING

k3d automatically configures networking between the containers emulating Kubernetes nodes. Services are exposed via port mapping from the Docker container to the host machine, allowing easy access from the host.

Custom networks can be specified during cluster creation to isolate k3d clusters or integrate with existing Docker networks.

STORAGE

k3d supports persistent volumes for storing data across pod restarts. The hostPath provisioner is commonly used for local development, allowing volumes to be backed by directories on the host machine.

Other storage solutions, such as NFS or cloud-based storage providers, can also be integrated with k3d clusters.

HISTORY

k3d was developed by Rancher Labs to simplify the process of running Kubernetes clusters locally. It builds upon k3s, Rancher's lightweight Kubernetes distribution, by leveraging Docker containers for node emulation. The project was created to provide a fast and efficient way for developers to experiment with Kubernetes and build cloud-native applications without the complexity of traditional virtual machine-based setups. k3d has gained popularity due to its ease of use, minimal resource footprint, and suitability for CI/CD integration.

SEE ALSO

kubectl(1), docker(1)

Copied to clipboard