Skip to content

Commit 7728b06

Browse files
author
Gunther Klessinger
committed
docs
1 parent 9811311 commit 7728b06

File tree

2 files changed

+143
-3
lines changed

2 files changed

+143
-3
lines changed

README.md

+46-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[Hetzner-k3s][hk3s] is nicely engineered general k3s installation tool on Hetzner, with a large degree of declarative possibilities for customization. As terraform, it is a single static binary and idempotent, with a single source of truth. In contrast to terraform it is straightforward to use, with far less abstractions but a lot of built in best practices, incl CNI and autoscaling, plus faster.
1010

11-
This repo here provides a set of **bash functions**, incl. possibly useful support tools to organize them, in order to further automate _around_ the pure k3s installation, which hetzner-k3s provides.
11+
This repo here provides a set of **python functions**, incl. possibly useful support tools to organize them, in order to further automate _around_ the pure k3s installation, which hetzner-k3s provides.
1212

1313

1414
## Features
@@ -36,8 +36,8 @@ That bastion server is the only one with a public IP, and is equipped with a l4
3636
We provide the functions necessary to
3737

3838
- create the private network
39-
- bastion node itself, with ssh key
40-
- tools (hetzner-k3s, kubectl, helm) and [optional load balancer service](./docs/l4lb.md) on it
39+
- bastion node itself, incl. ssh key and make it know to hetzner.
40+
- tools (hetzner-k3s, kubectl, helm) and [load balancer service](./docs/l4lb.md) on it
4141
- cloud init config for hetzner-k3s, so that the priv ip nodes can reach the internet
4242

4343
Then hetzner-k3s can be run from there, to create the cluster.
@@ -101,6 +101,49 @@ See [here](./docs/customization.md)
101101

102102
---
103103

104+
#### Local kubectl/helm support
105+
106+
You want to copy the kubeconfig file, which the installer script created on the bastion node to your local machine, so that you can manage the cluster from there.
107+
108+
I change the server line within the copied local kubeconfig to this:
109+
110+
```yaml
111+
server: https://127.0.0.1:16443
112+
```
113+
114+
and configure ssh like this:
115+
116+
```config
117+
# ---- cluster citest
118+
Host citest-proxy
119+
HostName 37.27.... # pub ip of the bastion node
120+
User root
121+
Port 22
122+
LocalForward 16443 10.1.0.3:6443 # first master
123+
Host citest-m1
124+
HostName 10.1.0.3
125+
User root
126+
Port 22
127+
ProxyCommand ssh -W %h:%p citest-proxy
128+
Host citest-m2
129+
HostName 10.1.0.4
130+
User root
131+
Port 22
132+
ProxyCommand ssh -W %h:%p citest-proxy
133+
Host citest-m3
134+
HostName 10.1.0.5
135+
User root
136+
Port 22
137+
ProxyCommand ssh -W %h:%p citest-proxy
138+
# ---- cluster citest
139+
```
140+
141+
#### Load Balancer on Bastion Node
142+
143+
You can install a layer 4 load balancer on bastion, turning it into a full proxy into your cluster, eradicating the need for a hetzner load balancer.
144+
145+
[This repo](https://github.com/axgkl/hk3sf) explains how to do that.
146+
104147
## Refs
105148

106149
- [notes](./docs/knowledge.md)

docs/privip.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
# Private IP Only Cluster
3+
4+
Below details about a private IP only cluster, set up with [hetzner-k3s][hk], are provided.
5+
6+
We describe a setup, where the cluster is 'behind' a proxy node, with a pub ip, reachable via ssh. Alternatively, you could add a vpn on top.
7+
8+
```mermaid
9+
flowchart LR
10+
A[World] --> B[Bastion Proxy<br/>IP pub<br/>Opt.LoadBalancer]
11+
B --priv net--> M1[Master 1<br/>...<br/>Master 3]
12+
B --priv net--> w1[Worker 1<br/>...<br/>Worker n]
13+
B --priv net--> a1[Autoscaled 1<br/>...<br/>Autoscaled n]
14+
```
15+
Why:
16+
17+
1. want a cost effective cluster, but
18+
1. don't want to ever have to recover a broken k8s. So: 3 masters.
19+
1. => Workloads on (cheap) masters - but with **autoscaled** add/delete workers if required.
20+
21+
IPs: Priv IPs are for free -> Only 1 pub IP (on a bastion outside the k8s cluster, which runs trivially restorable services w/o k8s). Also more secure, only this to shield.
22+
23+
💡 [This repo](https://github.com/axgkl/pyhk3) provides a set of python functions, to automate that setup.
24+
25+
💡 The node may be super slim, resource/cost wise. Distribution: We tested with ubuntu/amd64, but any other _should_ work as well.
26+
27+
## Features
28+
29+
- Creates a private network, using the hetzner ui, say on 10.1.0.0/16, named `ten-1`.
30+
- Creates a bastion node, with a pub ip and membership within that network. Usually that first node gets `.2` assigned, i.e. `10.1.0.2` in our example.
31+
- Secures the node but keeps allowing outgoing traffic to the internet and ssh access from your local machine, possibly from a jump host.
32+
- Kicks off the installation of the cluster, using [hetzner-k3s][hk], with a config, which creates a private IP only cluster.
33+
- Installs tools
34+
35+
36+
### Tools Installed
37+
38+
- [hetzner-k3s][hk]
39+
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
40+
- [helm](https://helm.sh/docs/intro/install/)
41+
42+
💡 The setup function in this repo use [binenv][binenv] to install kubectl and helm, since fast, distri independent and w/o the need for a big package mgmt. framework.
43+
44+
45+
46+
#### Notes on the Post Create Config
47+
48+
We add this post create commands hetzner-k3s:
49+
50+
```yaml
51+
post_create_commands:
52+
- echo "Started" > /.status # just to debug
53+
- timedatectl set-timezone Europe/Berlin
54+
- echo 'ecdsa-sha2-nistp256 AAAAE2V....= root@citest-proxy' >> /root/.ssh/authorized_keys
55+
- echo 'ecdsa-sha2-nistp256 AAAAE2V....= gk@axgk' >> /root/.ssh/authorized_keys
56+
- echo "root:$(head -c 50 /dev/urandom | base64)" | chpasswd
57+
- mkdir -p /etc/network/interfaces.d
58+
- iface="$(ip -o -4 addr list | grep " 10.1." | cut -d " " -f 2)"
59+
- |
60+
cat > /etc/network/interfaces.d/$iface <<EOF
61+
auto $iface
62+
iface $iface inet dhcp
63+
post-up ip route add default via 10.1.0.1
64+
post-up ip route add 169.254.169.254 via 172.31.1.1
65+
EOF
66+
- rm -f /etc/resolv.conf
67+
- |
68+
cat > /etc/resolv.conf <<EOF
69+
nameserver 185.12.64.1
70+
nameserver 185.12.64.2
71+
edns edns0 trust-ad
72+
search .
73+
EOF
74+
- ip route add 169.254.0.0/16 via 172.31.1.1
75+
- ip route add default via 10.1.0.1
76+
- echo "Done" > /.status # just to debug
77+
```
78+
79+
80+
These commands are basically run as cloud init, after a node is created.
81+
82+
Since we use the 'classic' way of configuring the network, using /etc/network/interfaces.d, on ubuntu we needed to add the `ifupdown` package.
83+
84+
- Added ssh pub keys, which should be allowed to log in to the k3s nodes.
85+
- Run `chpasswd`, in order to avoid any mails from hetzner, reminding you to change the password, after autoscaled nodes are created.
86+
- Find the interface name of the one interface, which is in the private network (distri dependent)
87+
- Create the interface config file, with the default route to the gateway of the private network, which is our bastion node. This has to be the `.1` address, not the priv ip of the bastion node!
88+
- Also add a route to hetzner's api server on 169.254.169.254, which seems to be always via 172.31.1.1
89+
- Lastly we configure hetzner's DNS servers and configure the above routes via cli commands, avoiding the need for a reboot.
90+
91+
With such a config, the hetzner-k3s setup should run through, creating a private IP only cluster.
92+
93+
[hk]: https://github.com/vitobotta/hetzner-k3s
94+
[binenv]: https://github.com/devops-works/binenv
95+
96+
97+

0 commit comments

Comments
 (0)