Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59af834

Browse files
authored
docs: add offical kubernetes provider runtime_class_name (#5157)
* add: offical kubernetes provider runtime_class_name * fix: typos * add: coder data source & vars
1 parent fd54512 commit 59af834

File tree

1 file changed

+61
-24
lines changed

1 file changed

+61
-24
lines changed

docs/templates/docker-in-docker.md

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The [Sysbox](https://github.com/nestybox/sysbox) container runtime allows unpriv
66

77
> Sysbox can also be used to run systemd inside Coder workspaces. See [Systemd in Docker](#systemd-in-docker).
88
9-
### Use Sysbox in Docker-based templates:
9+
### Use Sysbox in Docker-based templates
1010

1111
After [installing Sysbox](https://github.com/nestybox/sysbox#installation) on the Coder host, modify your template to use the sysbox-runc runtime:
1212

@@ -35,13 +35,29 @@ resource "coder_agent" "main" {
3535
}
3636
```
3737

38-
### Use Sysbox in Kubernetes-based templates:
38+
### Use Sysbox in Kubernetes-based templates
3939

40-
After [installing Sysbox on Kubernetes](https://github.com/nestybox/sysbox/blob/master/docs/user-guide/install-k8s.md), modify your template to use the sysbox-runc RuntimeClass.
41-
42-
> Currently, the official [Kubernetes Terraform Provider](https://registry.terraform.io/providers/hashicorp/kubernetes/latest) does not support specifying a custom RuntimeClass. [mingfang/k8s](https://registry.terraform.io/providers/mingfang/k8s), a third-party provider, can be used instead.
40+
After [installing Sysbox on Kubernetes](https://github.com/nestybox/sysbox/blob/master/docs/user-guide/install-k8s.md), modify your template to use the sysbox-runc RuntimeClass. This requires the Kubernetes Terraform provider version 2.16.0 or greater.
4341

4442
```hcl
43+
terraform {
44+
required_providers {
45+
coder = {
46+
source = "coder/coder"
47+
}
48+
kubernetes = {
49+
source = "hashicorp/kubernetes"
50+
version = "2.16.0"
51+
}
52+
}
53+
}
54+
55+
variable "workspaces_namespace" {
56+
default = "coder-namespace"
57+
}
58+
59+
data "coder_workspace" "me" {}
60+
4561
resource "coder_agent" "main" {
4662
os = "linux"
4763
arch = "amd64"
@@ -56,7 +72,7 @@ resource "coder_agent" "main" {
5672
EOF
5773
}
5874
59-
resource "k8s_core_v1_pod" "dev" {
75+
resource "kubernetes_pod" "dev" {
6076
count = data.coder_workspace.me.start_count
6177
metadata {
6278
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}"
@@ -66,15 +82,14 @@ resource "k8s_core_v1_pod" "dev" {
6682
}
6783
}
6884
69-
7085
spec {
7186
runtime_class_name = "sysbox-runc"
7287
# Use the Sysbox container runtime (required)
7388
security_context {
74-
run_asuser = 1000
75-
fsgroup = 1000
89+
run_as_user = 1000
90+
fs_group = 1000
7691
}
77-
containers {
92+
container {
7893
name = "dev"
7994
env {
8095
name = "CODER_AGENT_TOKEN"
@@ -93,7 +108,7 @@ resource "k8s_core_v1_pod" "dev" {
93108

94109
While less secure, you can attach a [privileged container](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities) to your templates. This may come in handy if your nodes cannot run Sysbox.
95110

96-
### Use a privileged sidecar container in Docker-based templates:
111+
### Use a privileged sidecar container in Docker-based templates
97112

98113
```hcl
99114
resource "coder_agent" "main" {
@@ -130,9 +145,27 @@ resource "docker_container" "workspace" {
130145
}
131146
```
132147

133-
### Use a privileged sidecar container in Kubernetes-based templates:
148+
### Use a privileged sidecar container in Kubernetes-based templates
134149

135150
```hcl
151+
terraform {
152+
required_providers {
153+
coder = {
154+
source = "coder/coder"
155+
}
156+
kubernetes = {
157+
source = "hashicorp/kubernetes"
158+
version = "2.16.0"
159+
}
160+
}
161+
}
162+
163+
variable "workspaces_namespace" {
164+
default = "coder-namespace"
165+
}
166+
167+
data "coder_workspace" "me" {}
168+
136169
resource "coder_agent" "main" {
137170
os = "linux"
138171
arch = "amd64"
@@ -179,7 +212,7 @@ resource "kubernetes_pod" "main" {
179212

180213
Additionally, [Sysbox](https://github.com/nestybox/sysbox) can be used to give workspaces full `systemd` capabilities.
181214

182-
### Use systemd in Docker-based templates:
215+
### Use systemd in Docker-based templates
183216

184217
After [installing Sysbox](https://github.com/nestybox/sysbox#installation) on the Coder host, modify your template to use the sysbox-runc runtime and start systemd:
185218

@@ -219,32 +252,37 @@ resource "coder_agent" "main" {
219252
}
220253
```
221254

222-
### Use systemd in Kubernetes-based templates:
223-
224-
After [installing Sysbox on Kubernetes](https://github.com/nestybox/sysbox/blob/master/docs/user-guide/install-k8s.md), modify your template to use the sysbox-runc RuntimeClass.
255+
### Use systemd in Kubernetes-based templates
225256

226-
> Currently, the official [Kubernetes Terraform Provider](https://registry.terraform.io/providers/hashicorp/kubernetes/latest) does not support specifying a custom RuntimeClass. [mingfang/k8s](https://registry.terraform.io/providers/mingfang/k8s), a third-party provider, can be used instead.
257+
After [installing Sysbox on Kubernetes](https://github.com/nestybox/sysbox/blob/master/docs/user-guide/install-k8s.md),
258+
modify your template to use the sysbox-runc RuntimeClass. This requires the Kubernetes Terraform provider version 2.16.0 or greater.
227259

228260
```hcl
229261
terraform {
230262
required_providers {
231263
coder = {
232264
source = "coder/coder"
233265
}
234-
k8s = {
235-
source = "mingfang/k8s"
266+
kubernetes = {
267+
source = "hashicorp/kubernetes"
268+
version = "2.16.0"
236269
}
237270
}
238271
}
239272
273+
variable "workspaces_namespace" {
274+
default = "coder-namespace"
275+
}
276+
277+
data "coder_workspace" "me" {}
240278
241279
resource "coder_agent" "main" {
242280
os = "linux"
243281
arch = "amd64"
244282
dir = "/home/coder"
245283
}
246284
247-
resource "k8s_core_v1_pod" "dev" {
285+
resource "kubernetes_pod" "dev" {
248286
count = data.coder_workspace.me.start_count
249287
metadata {
250288
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}"
@@ -254,19 +292,18 @@ resource "k8s_core_v1_pod" "dev" {
254292
}
255293
}
256294
257-
258295
spec {
259296
260297
# Use Sysbox container runtime (required)
261298
runtime_class_name = "sysbox-runc"
262299
263300
# Run as root in order to start systemd (required)
264301
security_context {
265-
run_asuser = 0
266-
fsgroup = 0
302+
run_as_user = 0
303+
fs_group = 0
267304
}
268305
269-
containers {
306+
container {
270307
name = "dev"
271308
env {
272309
name = "CODER_AGENT_TOKEN"

0 commit comments

Comments
 (0)