Integrating Kind with Travis

By Travis CI

Jul 1, 2022

Jul 1, 2022

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, and in this use case we will be using Kind with Travis. Let’s learn how.


Let’s get started with installing Kind, here’s a bash script I created that you can run in your .travis.yml file for one approach, but I’ll also be sharing the approach I did that didn’t require this bash script:


curl -Lo ./kind
chmod +x ./kind
mv ./kind /usr/bin/kind

apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nul
curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
apt-get update
apt-get install -y docker-ce docker-ce-cli kubectl

echo "Installing OpenStack client"
sleep 2
apt-get  install -y python3-pip
pip3 install python-openstackclient python-octaviaclient
mkdir -p /etc/openstack

wget -O /tmp/env.rc

curl -L -o clusterctl
chmod +x ./clusterctl
mv ./clusterctl /usr/local/bin/clusterctl

kind create cluster

echo "Create the cluster for Travis:"
echo "kubectl cluster-info --context kind-kind"
echo "kubectl get nodes"
echo "Initialize the cluster:"
echo "clusterctl init --infrastructure 'openstack:v0.4.0' --core 'cluster-api:v0.4.1' --control-plane 'kubeadm:v0.4.1' --bootstrap 'kubeadm:v0.4.1'"

This bash script will fetch a few things, in particular, Kind, OpenStack then it will create a cluster for you. The way I did it is it a bit different, because I want to give you options and flexibility, here’s how I set it up just purely using YAML.

Travis CI

So the .travis.yml file I created currently looks like this:

dist: jammy
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

If Kind is successfully built in your VM, you’ll see this in your Travis build log:

176944676 4481456a 16a9 488c 90b3 402c6f442a89 1

Please view my build for more information.

In Conclusion

You’ve just integrated Kind with Travis and started a Kind cluster! As per usual here’s my repo so you can follow it step by step and see for yourself how easy it is to integrate Kind with Travis.

As always, if you have any questions about integrating Kind and Travis, please email me at [email protected] and I will assist you with this tutorial.

Happy building!