9

Fully Automated K3S etcd High Availability Install

 3 years ago
source link: https://techno-tim.github.io/posts/k3s-etcd-ansible/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Fully Automated K3S etcd High Availability Install

Posted a month ago 2 min read

Setting up k3s is hard. That’s why we made it easy. Today we’ll set up a High Availability K3s cluster using etcd, MetalLB, kube-vip, and Ansible. We’ll automate the entire process giving you an easy, repeatable way to create a k3s cluster that you can run in a few minutes.

A HUGE THANKS to our sponsor, Micro Center!

New Customers Exclusive – Get a Free 240gb SSD at Micro Center: https://micro.center/1043bc

📺 Watch Video

First, you’ll need Ansible installed. Here’s an easy way to install Ansible and a video if you need.

Next, you’ll need to fork and clone the repo. While you’re at it, give it a ⭐ too :).

Installing k3s

Next, you’ll want to copy the sample directory within the inventory directory.

cp -R inventory/sample inventory/my-cluster

Next, edit the inventory/my-cluster/hosts.ini to match your systems. DNS works here too.

[master]
192.168.30.38
192.168.30.39
192.168.30.40

[node]
192.168.30.41
192.168.30.42

[k3s_cluster:children]
master
node

Edit inventory/my-cluster/group_vars/all.yml to your liking. See comments inline.

The variables I used in the video are below but…

Note: These are for an advanced use case. There isn’t a one size fits all setting for everyone and their needs, I would try using k3s without these before changing. This could have undesired effects like nodes going offline, pods jumping or being removed, etc… This might come at the cost of stability

extra_server_args: "--no-deploy servicelb --no-deploy traefik --write-kubeconfig-mode 644 --kube-apiserver-arg default-not-ready-toleration-seconds=30 --kube-apiserver-arg default-unreachable-toleration-seconds=30 --kube-controller-arg node-monitor-period=20s --kube-controller-arg node-monitor-grace-period=20s --kubelet-arg node-status-update-frequency=5s"
extra_agent_args: "--kubelet-arg node-status-update-frequency=5s"

It’s best to start using these args, and optionally include traefik if you want it installed with k3s

extra_server_args: "--no-deploy servicelb --no-deploy traefik"
extra_agent_args: ""

Start provisioning of the cluster using the following command:

ansible-playbook site.yml -i inventory/my-cluster/hosts.ini

note: add –ask-pass –ask-become-pass if you are using password SSH login

After deployment control plane will be accessible via virtual ip address which is defined in inventory/my-cluster/group_vars/all.yml as apiserver_endpoint

Removing

To remove k3s from the nodes. These nodes should be rebooted afterwards due to VIP still being present

ansible-playbook reset.yml -i inventory/my-cluster/hosts.ini

kube config

To get access to your Kubernetes cluster and copy your kube config locally run:

scp debian@master_ip:~/.kube/config ~/.kube/config

Testing your cluster

Be sure you can ping your VIP defined in inventory/my-cluster/group_vars/all.yml as apiserver_endpoint

ping 192.168.30.222

Getting nodes

kubectl get nodes

Deploying a sample nginx workload

kubectl apply -f example/deployment.yml

Check to be sure it was deployed

kubectl describe deployment nginx

Deploying a sample nginx service with a LoadBalancer

kubectl apply -f example/service.yml

Check service and be sure it has an IP from metal lb as defined in inventory/my-cluster/group_vars/all.yml

kubectl describe service nginx

Visit that url or curl

curl http://192.168.30.80

You should see the nginx welcome page.

You can clean this up by running

kubectl delete -f example/deployment.yml
kubectl delete -f example/service.yml

Troubleshooting

Be sure to see this post on how to troubleshoot common problems

Links

⚙️ See all the hardware I recommend at https://l.technotim.live/gear

🚀 Don’t forget to check out the 🚀Launchpad repo with all of the quick start source files


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK