@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
mdx 140 lines 4.17 KB
Raw
1 ---
2 title: "Part 4: Install a Helm Chart"
3 description: Install metrics-server from its Helm chart with Kubernetes.HelmChart, pass chart values, and check pod metrics with kubectl top.
4 sidebar:
5 order: 4
6 ---
7
8 import Terminal from "../../../../components/Terminal.astro";
9 import PackageManagers from "../../../../components/PackageManagers.astro";
10
11 In [Part 3](/kubernetes/tutorial/part-3) you ran your own Effect
12 programs as Jobs. Now you'll install third-party software from a
13 Helm chart, which is how most clusters get it.
14
15 The chart is [metrics-server](https://github.com/kubernetes-sigs/metrics-server),
16 which collects CPU and memory usage from each node and powers
17 `kubectl top`. Local kind clusters don't ship with it.
18
19 ## Install helm
20
21 `Kubernetes.HelmChart` renders charts with the `helm` CLI on your
22 machine. If you haven't installed it, follow the
23 [instructions](https://helm.sh/docs/intro/install/). For example:
24
25 ```sh
26 brew install helm
27 ```
28
29 ## Add the chart
30
31 ```diff lang="typescript"
32 +const metricsServer = yield* Kubernetes.HelmChart("MetricsServer", {
33 + cluster,
34 + chart: "metrics-server",
35 + repo: "https://kubernetes-sigs.github.io/metrics-server/",
36 + version: "3.14.0",
37 + namespace: "kube-system",
38 +});
39 ```
40
41 `chart` and `repo` name a chart in a classic Helm repository. `chart`
42 also accepts an `oci://` reference or a local chart directory.
43 `version` pins the chart so every deploy renders the same objects.
44 Cluster add-ons conventionally live in `kube-system`, which already
45 exists, so no Namespace resource is needed.
46
47 ## Name the release
48
49 ```diff lang="typescript"
50 version: "3.14.0",
51 +releaseName: "metrics-server",
52 namespace: "kube-system",
53 ```
54
55 Charts name their objects after the Helm release name. Without
56 `releaseName`, Alchemy generates one from the stack, stage, and
57 logical ID, and the chart's Deployment ends up with a long generated
58 name. Choose the release name before the first deploy. Changing it
59 later replaces the whole chart.
60
61 ## Pass chart values
62
63 kind's kubelets serve self-signed certificates, so metrics-server
64 must skip verifying them. Charts take their configuration as
65 **values**, in the same shape as a `values.yaml` file:
66
67 ```diff lang="typescript"
68 namespace: "kube-system",
69 + values: {
70 + args: ["--kubelet-insecure-tls"],
71 + },
72 });
73 ```
74
75 ## Deploy
76
77 <PackageManagers run="alchemy deploy" />
78
79 <Terminal content={`[u]Plan[/u]: [g]1 to create[/g]
80
81 [g]+[/g] [b]MetricsServer[/b] [d](Kubernetes.HelmChart)[/d]
82
83 Proceed?
84 ◉ Yes ○ No
85 [d]Rendering Helm chart metrics-server@3.14.0...[/d]
86 [d]Applying 9 objects from metrics-server...[/d]
87 [g]✓[/g] [b]MetricsServer[/b] [d](Kubernetes.HelmChart)[/d] [g]created[/g]`} />
88
89 Alchemy ran `helm template` locally and applied the nine rendered
90 objects through the same server-side apply path as a Manifest. They
91 include a Deployment, a Service, RBAC roles and bindings, and the
92 `APIService` that registers the metrics API. There is no
93 `helm install` and no release record in the cluster, so
94 `helm list -A` shows nothing. Alchemy owns the objects directly.
95
96 ## Verify it worked
97
98 Wait for metrics-server to roll out, give it a minute to collect its
99 first samples, then ask for pod usage:
100
101 ```sh
102 kubectl --context kind-alchemy -n kube-system rollout status deployment/metrics-server
103 kubectl --context kind-alchemy top pods -n my-app
104 ```
105
106 ```text
107 NAME CPU(cores) MEMORY(bytes)
108 web-c65f4dd44-h8d8d 1m 16Mi
109 web-c65f4dd44-rw7jm 1m 16Mi
110 ```
111
112 ## Change a value
113
114 Values are part of the chart's identity. If you change one, for
115 example to run two replicas, the next deploy re-renders the chart and
116 applies the difference:
117
118 ```diff lang="typescript"
119 values: {
120 args: ["--kubelet-insecure-tls"],
121 + replicas: 2,
122 },
123 ```
124
125 If a new render leaves out an object that the previous render
126 contained, Alchemy deletes it from the cluster.
127
128 ## Recap
129
130 You now have a complete stack on your local cluster:
131
132 - A podinfo Deployment in its own Namespace, configured from
133 TypeScript
134 - An Effect smoke test that re-runs when it changes, and the same
135 program on a schedule
136 - metrics-server installed from a pinned Helm chart, with Alchemy
137 owning every rendered object
138
139 In [Part 5](/kubernetes/tutorial/part-5), you'll point this stack at a
140 cluster of your own.