During Civo compute instance creation there is a section where you can provide the installation script. This can prove to be very useful when you want to install certain tooling on the instance or run scripts for initial setup.

In this example we will setup containerd, kubeadm, kubectl and kubelet on an instance. The use case for this can be that you can create 4 instances and have them all execute the install script on creation. After that you would need to just run kubeadm init and kubeadm join commands to set up a Kubernetes (K8s) cluster.

Although the simpler way to run your Kubernetes workloads is to just run a Civo Kubernetes cluster this is intended to demonstrate how to use the installation script in a real-world scenario.

On the instance creation page, choose Ubuntu as your operating system and put the below code in the installation script section:

cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf 

sudo modprobe overlay 
sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf 
net.bridge.bridge-nf-call-iptables = 1 
net.ipv4.ip_forward = 1 
net.bridge.bridge-nf-call-ip6tables = 1 

sudo sysctl --system

sudo apt-get update && sudo apt-get install -y containerd
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo systemctl restart containerd

sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

sudo apt-get update && sudo apt-get install -y apt-transport-https curl

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
sudo apt-get update
sudo apt-get install -y kubelet=1.21.2-00 kubeadm=1.21.2-00 kubectl=1.21.2-00
sudo apt-mark hold kubelet kubeadm kubectl

Screenshot demonstrating the instance creation options alongside the installation script

Once the instance is created and you log in, you will be able to see the instance is ready with all the tooling that was given as part of the installation script.

In my case case I created 2 simultaneous instances and both of them will run the script on startup.

Two instances created at the same time

We can therefore run kubeadm on both instances:

Logging in to one of the instances and running Kubeadm to bootstrap a Kubernetes cluster

Logging in to the other instance and showing it too can run kubeadm

As you can see both of the instances have run the file successfully and you are all set to run kubeadm init on the control plane node and join the other instance as a worker using the join command.

This is just one way to make use of the installation script on Civo compute instance.