The kind logo is licensed under CC BY 4.0
In a previous post, I showed how to build your own Kubernetes clusters using K3s. Since then, I’ve found an even easier cluster deployment tool that runs entirely within Docker. That’s right – if you have a computer with Docker installed, you can run a full multi-node Kubernetes cluster with no additional setup. This post shows you how to do it, and provides an all-in-one script for spinning up a full cluster with a demo website in one command.
Kubernetes in Docker?
The cluster management tool I’m using is Kubernetes in Docker (“kind” for short). In a nutshell, kind works by using Docker containers to host Kubernetes “nodes”. It handles all of the setup and networking behind the scenes, and even exposes the Kubernetes API so that you can manage the cluster using kubectl. You can do almost anything with this cluster that you can do with a real cluster, but without having to manually provision your own nodes.
As a note, I recommend using kind only for testing and not as a production cluster. It doesn’t have true redundancy, high availability, or scalability, but it’s great for testing a deployment or learning Kubernetes.
Getting started is easy: All you need is Docker, kubectl, and the kind CLI. Create a
config.yaml file with your desired cluster configuration (or let kind use its default settings), then use the following command to create the cluster:
kind create cluster --name KIND_CLUSTER_NAME --config config.yaml
Once kind creates your cluster, it will auto-generate a configuration file for kubectl. You can verify that your cluster was created by running
kubectl cluster-info or
kubectl get nodes.
Deploy a complete demo environment
I frequently use Kubernetes to practice Chaos Engineering, so to make my life easier, I wrote a script to create a kind cluster, deploy my chaos engineering tool, and deploy a demo application called Online Boutique that I run my experiments on. You can download the script from GitHub, or by running:
git clone https://github.com/8bitbuddhist/kind-gremlin-demo.git
By default, this script creates a three-node kind cluster, deploys the Chaos Engineering tool (Gremlin), then deploys the demo application to port 80 on the host. If you have a Gremlin account, you can provide the path to your authentication certificates and team ID in the
.env file and it will be deployed alongside the Gremlin daemon.
Alternatively, you can choose whether to deploy Gremlin or the demo app. To deploy the cluster and demo app without Gremlin, use
run.sh --no-gremlin cluster-name. If you just want an empty cluster, use
run.sh --no-gremlin --no-app cluster-name. Wait for the script to finish running, and that’s it!
Note that this script will expose the Kubernetes API on port 6443 of the host it’s running on. You can change this if you don’t want to make the cluster accessible outside of the host. I really don’t recommend running any secure or production workloads on this.
Let me know how this works for you! Leave a comment or PR!