annotate kube.py @ 303:9e15c07d5258

get telegraf running on pipe (non k8s)
author drewp@bigasterisk.com
date Wed, 07 Aug 2024 15:14:17 -0700
parents 3204157bb3e5
children 89b948759d64
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
303
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
1 import io
89
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
2 import os
303
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
3 import subprocess
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
4 from tempfile import NamedTemporaryFile
103
8b8ef9d8f0fd dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents: 99
diff changeset
5
8
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
6 from pyinfra import host
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
7 from pyinfra.facts.files import FindInFile
12
15c5ce7c74b5 refactor, cleanup, split large deploys
drewp@bigasterisk.com
parents: 8
diff changeset
8 from pyinfra.facts.server import Arch, LinuxDistribution
303
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
9 from pyinfra.operations import files, server, systemd, apt
8
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
10
40
193cd3b051c6 versions and ips
drewp@bigasterisk.com
parents: 29
diff changeset
11 # https://github.com/GoogleContainerTools/skaffold/releases
295
2543a0c2b59f upgr skaffold
drewp@bigasterisk.com
parents: 294
diff changeset
12 skaffold_version = 'v2.11.1'
40
193cd3b051c6 versions and ips
drewp@bigasterisk.com
parents: 29
diff changeset
13
8
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
14
204
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
15 def download_k3s(k3s_version):
27
7b22ff272001 refactor (may not be a correct commit)
drewp@bigasterisk.com
parents: 21
diff changeset
16 tail = 'k3s' if host.get_fact(Arch) == 'x86_64' else 'k3s-armhf'
282
e10ee3ddadcf pi changes
drewp@bigasterisk.com
parents: 280
diff changeset
17 if host.get_fact(Arch) == 'aarch64':
e10ee3ddadcf pi changes
drewp@bigasterisk.com
parents: 280
diff changeset
18 tail = 'k3s-arm64'
27
7b22ff272001 refactor (may not be a correct commit)
drewp@bigasterisk.com
parents: 21
diff changeset
19 files.download(
7b22ff272001 refactor (may not be a correct commit)
drewp@bigasterisk.com
parents: 21
diff changeset
20 src=f'https://github.com/rancher/k3s/releases/download/{k3s_version}/{tail}',
7b22ff272001 refactor (may not be a correct commit)
drewp@bigasterisk.com
parents: 21
diff changeset
21 dest='/usr/local/bin/k3s',
7b22ff272001 refactor (may not be a correct commit)
drewp@bigasterisk.com
parents: 21
diff changeset
22 user='root',
7b22ff272001 refactor (may not be a correct commit)
drewp@bigasterisk.com
parents: 21
diff changeset
23 group='root',
7b22ff272001 refactor (may not be a correct commit)
drewp@bigasterisk.com
parents: 21
diff changeset
24 mode='755',
7b22ff272001 refactor (may not be a correct commit)
drewp@bigasterisk.com
parents: 21
diff changeset
25 cache_time=43000,
263
47f5aca39a68 k3s update
drewp@bigasterisk.com
parents: 260
diff changeset
26 # force=True, # to get a new version
27
7b22ff272001 refactor (may not be a correct commit)
drewp@bigasterisk.com
parents: 21
diff changeset
27 )
8
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
28
99
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
29
302
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
30 def install_skaffold(reg):
99
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
31 files.download(src=f'https://storage.googleapis.com/skaffold/releases/{skaffold_version}/skaffold-linux-amd64',
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
32 dest='/usr/local/bin/skaffold',
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
33 user='root',
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
34 group='root',
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
35 mode='755',
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
36 cache_time=1000)
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
37 # one time; writes to $HOME
302
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
38 server.shell(commands=f"skaffold config set --global insecure-registries {reg}")
99
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
39
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
40
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
41 def host_prep():
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
42 server.sysctl(key='net.ipv4.ip_forward', value="1", persist=True)
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
43 server.sysctl(key='net.ipv6.conf.all.forwarding', value="1", persist=True)
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
44 server.sysctl(key='fs.inotify.max_user_instances', value='8192', persist=True)
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
45 server.sysctl(key='fs.inotify.max_user_watches', value='524288', persist=True)
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
46
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
47 # https://sysctl-explorer.net/net/ipv4/rp_filter/
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
48 none, strict, loose = 0, 1, 2
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
49 server.sysctl(key='net.ipv4.conf.default.rp_filter', value=loose, persist=True)
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
50
268
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
51
204
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
52 # don't try to get aufs-dkms on rpi-- https://github.com/docker/for-linux/issues/709
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
53 def podman_insecure_registry(reg):
302
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
54 # docs: https://rancher.com/docs/k3s/latest/en/installation/private-registry/
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
55 # user confusions: https://github.com/rancher/k3s/issues/1802
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
56 files.template(src='templates/kube/registries.yaml.j2', dest='/etc/rancher/k3s/registries.yaml', reg=reg)
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
57
222
9dfb0916e850 registry change
drewp@bigasterisk.com
parents: 220
diff changeset
58 files.template(src='templates/kube/podman_registries.conf.j2', dest='/etc/containers/registries.conf.d/reg.conf', reg=reg)
302
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
59 if host.data.get('k8s_admin'):
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
60 systemd.service(service='podman', user_mode=True)
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
61 systemd.service(service='podman.socket', user_mode=True)
296
drewp@bigasterisk.com
parents: 295
diff changeset
62 # and maybe edit /etc/containers/policy.json
240
b58f05be720a updates for new ubuntu 23.10 install
drewp@bigasterisk.com
parents: 232
diff changeset
63
89
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
64
204
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
65 def config_and_run_service(k3s_version, server_node, server_ip):
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
66 download_k3s(k3s_version)
89
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
67 service_name = 'k3s.service' if host.name == server_node else 'k3s-node.service'
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
68 role = 'server' if host.name == server_node else 'agent'
103
8b8ef9d8f0fd dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents: 99
diff changeset
69 which_conf = 'config-server.yaml.j2' if host.name == server_node else 'config-agent.yaml.j2'
8
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
70
294
7f0482453ead boost pod-per-node limit
drewp@bigasterisk.com
parents: 289
diff changeset
71 files.put(src="files/kube/kubelet.config", dest="/etc/rancher/k3s/kubelet.config")
7f0482453ead boost pod-per-node limit
drewp@bigasterisk.com
parents: 289
diff changeset
72
89
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
73 # /var/lib/rancher/k3s/server/node-token is the source of the string in secrets/k3s_token,
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
74 # so this presumes a previous run
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
75 if host.name == server_node:
99
6e159d3bdd40 rewrite k3s to match current config. many tests lying around in comments.
drewp@bigasterisk.com
parents: 89
diff changeset
76 token = "ununsed"
89
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
77 else:
267
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
78 # this assumes localhost is the k3s server.
89
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
79 if not os.path.exists('/var/lib/rancher/k3s/server/node-token'):
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
80 print("first pass is for server only- skipping other nodes")
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
81 return
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
82 token = open('/var/lib/rancher/k3s/server/node-token', 'rt').read().strip()
8
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
83 files.template(
28
d844cdf86164 more old changes, not sure
drewp@bigasterisk.com
parents: 27
diff changeset
84 src=f'templates/kube/{which_conf}',
21
948d9d72267d k3s update and some config refactoring
drewp@bigasterisk.com
parents: 19
diff changeset
85 dest='/etc/k3s_config.yaml',
112
drewp@bigasterisk.com
parents: 107
diff changeset
86 server_ip=server_ip,
28
d844cdf86164 more old changes, not sure
drewp@bigasterisk.com
parents: 27
diff changeset
87 token=token,
d844cdf86164 more old changes, not sure
drewp@bigasterisk.com
parents: 27
diff changeset
88 wg_ip=host.host_data['wireguard_address'],
8
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
89 )
84
eb38553a6806 trying to fix k3s networking but this doesn't work yet
drewp@bigasterisk.com
parents: 80
diff changeset
90 files.template(
28
d844cdf86164 more old changes, not sure
drewp@bigasterisk.com
parents: 27
diff changeset
91 src='templates/kube/k3s.service.j2',
d844cdf86164 more old changes, not sure
drewp@bigasterisk.com
parents: 27
diff changeset
92 dest=f'/etc/systemd/system/{service_name}',
89
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
93 role=role,
8
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
94 )
289
65e28d2e0cd8 move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents: 288
diff changeset
95 if not host.data.get('gpu'):
268
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
96 # no supported gpu
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
97 '''
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
98 kubectl label --overwrite node bang nvidia.com/gpu.deploy.gpu-feature-discovery=false
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
99 kubectl label --overwrite node bang nvidia.com/gpu.deploy.container-toolkit=false
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
100 kubectl label --overwrite node bang nvidia.com/gpu.deploy.dcgm-exporter=false
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
101 kubectl label --overwrite node bang nvidia.com/gpu.deploy.device-plugin=false
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
102 kubectl label --overwrite node bang nvidia.com/gpu.deploy.driver=false
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
103 kubectl label --overwrite node bang nvidia.com/gpu.deploy.mig-manager=false
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
104 kubectl label --overwrite node bang nvidia.com/gpu.deploy.operator-validator=false
34ab4aec7d4b notes and changes for getting nvidia gpu k3d support going, which was very hard
drewp@bigasterisk.com
parents: 267
diff changeset
105 '''
28
d844cdf86164 more old changes, not sure
drewp@bigasterisk.com
parents: 27
diff changeset
106 systemd.service(service=service_name, daemon_reload=True, enabled=True, restarted=True)
8
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
107
267
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
108
254
11b738d4c4ae work on k8s/nvidia setup
drewp@bigasterisk.com
parents: 240
diff changeset
109 def setupNvidiaToolkit():
265
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
110 # guides:
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
111 # https://github.com/NVIDIA/k8s-device-plugin#prerequisites
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
112 # https://docs.k3s.io/advanced#nvidia-container-runtime-support
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
113 # apply this once to kube-system: https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v0.14.3/nvidia-device-plugin.yml
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
114 # apply this once: https://raw.githubusercontent.com/NVIDIA/gpu-feature-discovery/v0.8.2/deployments/static/nfd.yaml
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
115 # and: kubectl apply -f https://raw.githubusercontent.com/NVIDIA/gpu-feature-discovery/v0.8.2/deployments/static/gpu-feature-discovery-daemonset.yaml
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
116
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
117 # k3s says they do this:
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
118 #server.shell('nvidia-ctk runtime configure --runtime=containerd --config /var/lib/rancher/k3s/agent/etc/containerd/config.toml')
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
119
254
11b738d4c4ae work on k8s/nvidia setup
drewp@bigasterisk.com
parents: 240
diff changeset
120 # then caller restarts k3s which includes containerd
89
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
121
265
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
122 # tried https://github.com/k3s-io/k3s/discussions/9231#discussioncomment-8114243
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
123 pass
9d0a3915cc00 WIP on k8s+gpu
drewp@bigasterisk.com
parents: 263
diff changeset
124
267
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
125
204
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
126 def make_cluster(
267
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
127 server_ip,
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
128 server_node,
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
129 nodes,
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
130 # https://github.com/k3s-io/k3s/releases
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
131 # 1.23.6 per https://github.com/cilium/cilium/issues/20331
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
132 k3s_version,
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
133 ):
89
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
134
204
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
135 if host.name in nodes + [server_node]:
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
136 host_prep()
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
137 files.directory(path='/etc/rancher/k3s')
89
2fddde57231b no connman to surprisingly rewrite net configs
drewp@bigasterisk.com
parents: 84
diff changeset
138
302
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
139 podman_insecure_registry(reg='reg:5000')
204
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
140 # also note that podman dropped the default `docker.io/` prefix on image names (see https://unix.stackexchange.com/a/701785/419418)
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
141 config_and_run_service(k3s_version, server_node, server_ip)
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
142
289
65e28d2e0cd8 move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents: 288
diff changeset
143 if host.data.get('k8s_admin'):
204
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
144 files.directory(path='/etc/rancher/k3s')
302
3204157bb3e5 attempt to fix http-registry problem on rpi
drewp@bigasterisk.com
parents: 296
diff changeset
145 install_skaffold("reg:5000")
204
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
146 files.link(path='/usr/local/bin/kubectl', target='/usr/local/bin/k3s')
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
147 files.directory(path='/home/drewp/.kube', user='drewp', group='drewp')
8
226f3c8419b2 kube setup
drewp@bigasterisk.com
parents:
diff changeset
148
204
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
149 # assumes our pyinfra process is running on server_node
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
150 files.put(
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
151 src='/etc/rancher/k3s/k3s.yaml',
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
152 dest='/etc/rancher/k3s/k3s.yaml', #
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
153 user='root',
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
154 group='drewp',
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
155 mode='640')
267
564b62e59484 redo k3s with ditto as the server
drewp@bigasterisk.com
parents: 265
diff changeset
156 server.shell(
288
drewp@bigasterisk.com
parents: 287
diff changeset
157 commands=f"kubectl config set-cluster default --server=https://{server_ip}:6443 --kubeconfig=/etc/rancher/k3s/k3s.yaml"
drewp@bigasterisk.com
parents: 287
diff changeset
158 )
204
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
159
ad6e997fd323 prepare for k8s server host and registry host to change
drewp@bigasterisk.com
parents: 203
diff changeset
160
303
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
161 def run_non_k8s_telegraf(node):
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
162 if host.name != node:
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
163 return
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
164 # this CM is written by /my/serv/telegraf/tasks.py
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
165 conf = io.BytesIO(subprocess.check_output(["kubectl", "get", "cm", "telegraf-config", "-o", "jsonpath={.data." + node + "}"]))
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
166 apt.packages(packages=['telegraf'])
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
167 files.put(src=conf, dest="/etc/telegraf/telegraf.conf", create_remote_dir=True, assume_exists=True)
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
168 systemd.service(
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
169 service='telegraf',
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
170 running=True,
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
171 enabled=True,
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
172 restarted=True,
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
173 )
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
174
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
175
288
drewp@bigasterisk.com
parents: 287
diff changeset
176 make_cluster(
drewp@bigasterisk.com
parents: 287
diff changeset
177 server_ip="10.5.0.7",
drewp@bigasterisk.com
parents: 287
diff changeset
178 server_node='ditto',
drewp@bigasterisk.com
parents: 287
diff changeset
179 nodes=[
drewp@bigasterisk.com
parents: 287
diff changeset
180 'bang',
drewp@bigasterisk.com
parents: 287
diff changeset
181 'slash',
drewp@bigasterisk.com
parents: 287
diff changeset
182 'dash',
drewp@bigasterisk.com
parents: 287
diff changeset
183 'ws-printer',
drewp@bigasterisk.com
parents: 287
diff changeset
184 # 'gn-music',
drewp@bigasterisk.com
parents: 287
diff changeset
185 'li-drums',
drewp@bigasterisk.com
parents: 287
diff changeset
186 ],
drewp@bigasterisk.com
parents: 287
diff changeset
187 k3s_version='v1.29.1+k3s1')
287
c094d23b7943 refmt, notes
drewp@bigasterisk.com
parents: 282
diff changeset
188
303
9e15c07d5258 get telegraf running on pipe (non k8s)
drewp@bigasterisk.com
parents: 302
diff changeset
189 run_non_k8s_telegraf('pipe')
287
c094d23b7943 refmt, notes
drewp@bigasterisk.com
parents: 282
diff changeset
190 # consider https://github.com/derailed/k9s/releases/download/v0.32.4/k9s_Linux_amd64.tar.gz
296
drewp@bigasterisk.com
parents: 295
diff changeset
191
drewp@bigasterisk.com
parents: 295
diff changeset
192 # k label node ws-printer unschedulable=octoprint-allowed