K8s Cluster in NO-TIME using k3s and longhorn

D. Heinrich
2 min readNov 26, 2021

--

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

NOTE:

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

Server 1 — 123.123.123.123

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

Agent 1 - 124.124.124.124

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 -

Agent 2 -125.125.125.125

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:

--

--