The Little Tool To Run K8S In Docker Easily

Guillaume Vincent
Guillaume Vincent
Photo by Simone Viani / Unsplash
Photo by Simone Viani / Unsplash
Table of Contents
Table of Contents

Want to deploy Kubernetes clusters on the fly? Yes, it is possible to run Kubernetes directly under Docker!

To deploy Kubernetes locally, the solutions until now were to install Docker Desktop or minikube. We will see here how to deploy Kubernetes in Docker using a great tool called kind. We'll see how to install it on your laptop and push a little bit on the CI side using Travis CI.

For the CI, let's take the following scenario: you have a YAML manifest of an application that you want to test on different versions of Kubernetes. It's going to be complicated to have a real cluster for each version with breaking changes.

Why not Minikube?

Minikube was the initial way to deploy a Kubernetes cluster locally for testing purposes. It is possible to configure a master and multiple nodes using virtual machines. Each VM embeds a runtime container:

Minikube Architecture Diagram
Minikube Architecture Diagram

A VM takes longer to start. This is all the more important in a CI context where several jobs have to run in a chain. The shorter the execution time of the job the better! Finally, what if we replace the virtualization layer with a containerization layer?

Kubernetes In Docker (Kind)

β€œkind is a tool for running local Kubernetes clusters using Docker container nodes. kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.” from

Kind is a CLI that interacts with a docker daemon. Β It creates a "node" container creating the necessary components for Kubernetes like etcd, kubelet, addons:

Kind design diagram from
Kind design diagram from

In this part, we’re going to see how to install kind in local and then create a cluster. Then we’ll export the recipe to Travis CI configuration.


First of all install golang :

$ brew install golang
$ go version                                                                                                                                                                                                                     
go version go1.16 darwin/amd64

Then kind is super easy to install:

$ GO111MODULE="on" go get[email protected]

Creating a cluster with Kind

$ kind create cluster
Creating cluster "kind" ...
 βœ“ Ensuring node image (kindest/node:v1.20.2) πŸ–Ό
 βœ“ Preparing nodes πŸ“¦
 βœ“ Writing configuration πŸ“œ
 βœ“ Starting control-plane πŸ•ΉοΈ
 βœ“ Installing CNI πŸ”Œ
 βœ“ Installing StorageClass πŸ’Ύ
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
Thanks for using kind! 😊
$ kubectl cluster-info --context kind-kind                                                                                                                                                                                     
Kubernetes control plane is running at
KubeDNS is running at
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
$ kubectl run busybox --context kind-kind --image=busybox
pod/busybox created
$ kubectl get pods
busybox   0/1     Completed   0          7s

Use Kubernetes In a CI Pipeline (Travis CI)

The configuration reuses what we have seen before:

language: go

  - '1.15.x'

  - docker

    - stage: 'Kind example'
        - curl -LO$(curl -s && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
        - GO111MODULE="on" go get[email protected]
        - kind create cluster
        - kubectl config use-context kind-kind
        - kubectl create sa default
        - kubectl run busybox --image=busybox
        - kubectl get pods

All is working like a charm:

The Travis CI output of the previous configuration file
The Travis CI output of the previous configuration file


Kind offers a significantly faster startup speed compared to Minikube. It is very straightforward to install and create Kubernetes clusters. For all these points, it is a good fit for CI practices. You can also use it to replace the Kubernetes feature of Docker for Desktop if you are looking for a minimal solution.



Great! Next, complete checkout for full access to Getbetterdevops
Welcome back! You've successfully signed in
You've successfully subscribed to Getbetterdevops
Success! Your account is fully activated, you now have access to all content
Success! Your billing info has been updated
Your billing was not updated