K8s Cluster in NO-TIME using k3s and longhorn

If you want to bootstrap a Kubernetes cluster in no-time, then you may want to follow the below steps.

Here I describe how I set up a three node cluster using a Server and two Agents and a storage driver using longhorn.io.

by SweetOps

I assume you have at least three Servers up and running.

Servers:

  • 123.123.123.123 (Server 1)
  • 124.124.124.124 (Agent 1)
  • 125.125.125.125 (Agent 2)

Initialize the cluster

ssh root@123.123.123.123apt install curl -ycurl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--cluster-init --write-kubeconfig-mode 644 --node-label node-role.kubernetes.io/agent=true --node-label node-role.kubernetes.io/control-plane=true --node-label node-role.kubernetes.io/etcd=true --node-label node-role.kubernetes.io/master=true" sh -

Get the kubeconfig and starting watching the server rise.

export KUBECONFIG="/path/to/kubeconfig"
watch -d "kubectl get nodes && kubectl get po -o wide --all-namespaces"

Add your agents

ssh root@124.124.124.124apt update && apt install curl -ycurl -sfL https://get.k3s.io | K3S_URL=https://123.123.123.123:6443 K3S_TOKEN=mySuperToken INSTALL_K3S_EXEC="--node-label node-role.kubernetes.io/agent=true --node-label node-role.kubernetes.io/control-plane=true --node-label node-role.kubernetes.io/etcd=true --node-label node-role.kubernetes.io/master=true" sh -
ssh root@125.125.125.125apt install curl -ycurl -sfL https://get.k3s.io | K3S_URL=https://123.123.123.123:6443 K3S_TOKEN=mySuperToken INSTALL_K3S_EXEC="server --node-label node-role.kubernetes.io/agent=true --node-label node-role.kubernetes.io/control-plane=true --node-label node-role.kubernetes.io/etcd=true --node-label node-role.kubernetes.io/master=true" sh -

Install Storage using Longhorn.io

apt update &&apt install open-iscsi -ykubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml

Thats it!

You should be ready to go!

Now you can fire your containers into kubernetes with for example Kapitan.

Cheers!

Sources:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
D. Heinrich

Working as a IT-Operations engineer at NeXenio, a spin-off by Hasso-Plattner-Institute for products around a digitial workspace.