|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Fully Automated K3S etcd High Availability Install" |
| 4 | +date: 2022-03-26 10:00:00 -0500 |
| 5 | +categories: kubernetes k3s |
| 6 | +tags: k3s rancher etcd ansible cloud-image metallb kube-vip |
| 7 | +--- |
| 8 | + |
| 9 | +[](https://www.youtube.com/watch?v=CbkEWcUZ7zM "Fully Automated K3S etcd High Availability Install") |
| 10 | + |
| 11 | +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 automated the entire process giving you an easy, repeatable way to create a k3s cluster that you can run in a few minutes. |
| 12 | + |
| 13 | +A HUGE THANKS to our sponsor, Micro Center! |
| 14 | + |
| 15 | +New Customers Exclusive – Get a Free 240gb SSD at Micro Center: https://micro.center/1043bc |
| 16 | + |
| 17 | +📺 [Watch Video](https://www.youtube.com/watch?v=CbkEWcUZ7zM) |
| 18 | + |
| 19 | +## Prep |
| 20 | + |
| 21 | +First, you'll need Ansible installed. Here's an easy way to [install Ansible](https://docs.technotim.live/posts/ansible-automation/) and a video if you need. |
| 22 | + |
| 23 | +Next, you'll need to fork and clone [the repo](https://github.com/techno-tim/k3s-ansible). While you're at it, give it a ⭐ too :). |
| 24 | + |
| 25 | +## Installing k3s |
| 26 | + |
| 27 | +Next, you'll want to copy the `sample` directory within the `inventory` directory. |
| 28 | + |
| 29 | +```bash |
| 30 | +cp -R inventory/sample inventory/my-cluster |
| 31 | +``` |
| 32 | + |
| 33 | +Next, edit the `inventory/hosts.ini` to match your systems. DNS works here too. |
| 34 | + |
| 35 | +```ini |
| 36 | +[master] |
| 37 | +192.168.30.38 |
| 38 | +192.168.30.39 |
| 39 | +192.168.30.40 |
| 40 | + |
| 41 | +[node] |
| 42 | +192.168.30.41 |
| 43 | +192.168.30.42 |
| 44 | + |
| 45 | +[k3s_cluster:children] |
| 46 | +master |
| 47 | +node |
| 48 | +``` |
| 49 | + |
| 50 | +Edit `inventory/group_vars/all.yml` to your liking. See comments inline. |
| 51 | + |
| 52 | +Start provisioning of the cluster using the following command: |
| 53 | + |
| 54 | +```bash |
| 55 | +ansible-playbook site.yml -i inventory/hosts.ini |
| 56 | +``` |
| 57 | + |
| 58 | +After deployment control plane will be accessible via virtual ip address which is defined in `inventory/group_vars/all.yml` as `apiserver_endpoint` |
| 59 | + |
| 60 | +## Removing |
| 61 | + |
| 62 | +To remove k3s from the nodes |
| 63 | + |
| 64 | +```bash |
| 65 | +ansible-playbook reset.yml -i inventory/hosts.ini |
| 66 | +``` |
| 67 | + |
| 68 | +## kube config |
| 69 | +To get access to your Kubernetes cluster and copy your kube config locally run: |
| 70 | + |
| 71 | +``` |
| 72 | +scp debian@master_ip:~/.kube/config ~/.kube/config |
| 73 | +``` |
| 74 | + |
| 75 | +## Testing your cluster |
| 76 | + |
| 77 | +Be sure you can ping your VIP defined in `inventory/group_vars/all.yml` as `apiserver_endpoint` |
| 78 | + |
| 79 | +```bash |
| 80 | +ping 192.168.30.222 |
| 81 | +``` |
| 82 | + |
| 83 | +Getting nodes |
| 84 | + |
| 85 | +```bash |
| 86 | +kubectl get nodes |
| 87 | +``` |
| 88 | + |
| 89 | +Deploying a sample `nginx` workload |
| 90 | + |
| 91 | +```bash |
| 92 | +kubectl apply -f example/deployment.yml |
| 93 | +``` |
| 94 | + |
| 95 | +Check to be sure it was deployed |
| 96 | + |
| 97 | +```bash |
| 98 | +kubectl describe deployment nginx |
| 99 | +``` |
| 100 | + |
| 101 | + |
| 102 | +Deploying a sample `nginx` service with a `LoadBalancer` |
| 103 | + |
| 104 | +```bash |
| 105 | +kubectl apply -f example/service.yml |
| 106 | +``` |
| 107 | + |
| 108 | + |
| 109 | +Check service and be sure it has an IP from metal lb as defined in `inventory/group_vars/all.yml` |
| 110 | + |
| 111 | +```bash |
| 112 | +kubectl describe service nginx |
| 113 | +``` |
| 114 | + |
| 115 | +Visit that url or curl |
| 116 | + |
| 117 | +```bash |
| 118 | +curl http://192.168.30.80 |
| 119 | +``` |
| 120 | + |
| 121 | +You should see the `nginx` welcome page. |
| 122 | + |
| 123 | + |
| 124 | +You can clean this up by running |
| 125 | + |
| 126 | +```bash |
| 127 | +kubectl delete -f example/deployment.yml |
| 128 | +kubectl delete -f example/service.yml |
| 129 | +``` |
| 130 | + |
| 131 | + |
| 132 | +## Links |
| 133 | + |
| 134 | +⚙️ See all the hardware I recommend at <https://l.technotim.live/gear> |
| 135 | + |
| 136 | +🚀 Don't forget to check out the [🚀Launchpad repo](https://l.technotim.live/quick-start) with all of the quick start source files |
0 commit comments