Skip to content

Commit af375b9

Browse files
meysholdtroboquat
authored andcommitted
Launch k3s in the VM on Harvester and configure it similar to prod.
1 parent 2479e48 commit af375b9

File tree

2 files changed

+95
-20
lines changed

2 files changed

+95
-20
lines changed

.werft/vm/manifests.ts

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ metadata:
1414
type VirtualMachineManifestArguments = {
1515
vmName: string
1616
namespace: string
17-
claimName: string,
17+
claimName: string
18+
userDataSecretName: string
1819
}
1920

20-
export function VirtualMachineManifest({ vmName, namespace, claimName }: VirtualMachineManifestArguments) {
21+
export function VirtualMachineManifest({ vmName, namespace, claimName, userDataSecretName }: VirtualMachineManifestArguments) {
2122
return `
2223
apiVersion: kubevirt.io/v1
2324
type: kubevirt.io.virtualmachine
@@ -75,23 +76,11 @@ spec:
7576
claimName: ${claimName}
7677
- name: cloudinitdisk
7778
cloudInitNoCloud:
78-
userData: |-
79-
#cloud-config
80-
users:
81-
- name: ubuntu
82-
sudo: "ALL=(ALL) NOPASSWD: ALL"
83-
ssh_authorized_keys:
84-
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC/aB/HYsb56V0NBOEab6j33v3LIxRiGqG4fmidAryAXevLyTANJPF8m44KSzSQg7AI7PMy6egxQp/JqH2b+3z1cItWuHZSU+klsKNuf5HxK7AOrND3ahbejZfyYewtKFQ3X9rv5Sk8TAR5gw5oPbkTR61jiLa58Sw7UkhLm2EDguGASb6mBal8iboiF8Wpl8QIvPmJaGIOY2YwXLepwFA3S3kVqW88eh2WFmjTMre5ASLguYNkHXjyb/TuhVFzAvphzpl84RAaEyjKYnk45fh4xRXx+oKqlfKRJJ/Owxa7SmGO+/4rWb3chdnpodHeu7XjERmjYLY+r46sf6n6ySgEht1xAWjMb1uqZqkDx+fDDsjFSeaN3ncX6HSoDOrphFmXYSwaMpZ8v67A791fuUPrMLC+YMckhTuX2g4i3XUdumIWvhaMvKhy/JRRMsfUH0h+KAkBLI6tn5ozoXiQhgM4SAE5HsMr6CydSIzab0yY3sq0avmZgeoc78+8PKPkZG1zRMEspV/hKKBC8hq7nm0bu4IgzuEIYHowOD8svqA0ufhDWxTt6A4Jo0xDzhFyKme7KfmW7SIhpejf3T1Wlf+QINs1hURr8LSOZEyY2SzYmAoQ49N0SSPb5xyG44cptpKcj0WCAJjBJoZqz0F5x9TjJ8XToB5obyJfRHD1JjxoMQ== [email protected]
85-
chpasswd:
86-
list: |
87-
ubuntu:ubuntu
88-
expire: False
89-
runcmd:
90-
- curl -sfL https://get.k3s.io | sh -
91-
- sleep 10
92-
- kubectl label nodes ${vmName} gitpod.io/workload_meta=true gitpod.io/workload_ide=true gitpod.io/workload_workspace_services=true gitpod.io/workload_workspace_regular=true gitpod.io/workload_workspace_headless=true gitpod.io/workspace_0=true gitpod.io/workspace_1=true gitpod.io/workspace_2=true
93-
- kubectl create ns certs
94-
- kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.6.1/cert-manager.yaml
79+
networkDataSecretRef:
80+
name: ${userDataSecretName}
81+
secretRef:
82+
name: ${userDataSecretName}
83+
9584
`
9685
}
9786

@@ -132,6 +121,82 @@ spec:
132121
}
133122

134123
type UserDataSecretManifestOptions = {
124+
vmName: string
135125
namespace: string,
136126
secretName: string
137127
}
128+
129+
export function UserDataSecretManifest({vmName, namespace, secretName }: UserDataSecretManifestOptions) {
130+
const userdata = Buffer.from(`#cloud-config
131+
users:
132+
- name: ubuntu
133+
sudo: "ALL=(ALL) NOPASSWD: ALL"
134+
ssh_authorized_keys:
135+
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC/aB/HYsb56V0NBOEab6j33v3LIxRiGqG4fmidAryAXevLyTANJPF8m44KSzSQg7AI7PMy6egxQp/JqH2b+3z1cItWuHZSU+klsKNuf5HxK7AOrND3ahbejZfyYewtKFQ3X9rv5Sk8TAR5gw5oPbkTR61jiLa58Sw7UkhLm2EDguGASb6mBal8iboiF8Wpl8QIvPmJaGIOY2YwXLepwFA3S3kVqW88eh2WFmjTMre5ASLguYNkHXjyb/TuhVFzAvphzpl84RAaEyjKYnk45fh4xRXx+oKqlfKRJJ/Owxa7SmGO+/4rWb3chdnpodHeu7XjERmjYLY+r46sf6n6ySgEht1xAWjMb1uqZqkDx+fDDsjFSeaN3ncX6HSoDOrphFmXYSwaMpZ8v67A791fuUPrMLC+YMckhTuX2g4i3XUdumIWvhaMvKhy/JRRMsfUH0h+KAkBLI6tn5ozoXiQhgM4SAE5HsMr6CydSIzab0yY3sq0avmZgeoc78+8PKPkZG1zRMEspV/hKKBC8hq7nm0bu4IgzuEIYHowOD8svqA0ufhDWxTt6A4Jo0xDzhFyKme7KfmW7SIhpejf3T1Wlf+QINs1hURr8LSOZEyY2SzYmAoQ49N0SSPb5xyG44cptpKcj0WCAJjBJoZqz0F5x9TjJ8XToB5obyJfRHD1JjxoMQ== [email protected]
136+
chpasswd:
137+
list: |
138+
ubuntu:ubuntu
139+
expire: False
140+
write_files:
141+
- path: /usr/local/bin/bootstrap-k3s.sh
142+
permissions: 0744
143+
owner: root
144+
content: |
145+
#!/bin/bash
146+
147+
set -eo pipefail
148+
149+
# inspired by https://github.com/gitpod-io/ops/blob/main/deploy/workspace/templates/bootstrap.sh
150+
151+
# Install k3s
152+
export INSTALL_K3S_SKIP_DOWNLOAD=true
153+
154+
/usr/local/bin/install-k3s.sh \
155+
--token "1234" \
156+
--node-ip "$(hostname -I | cut -d ' ' -f1)" \
157+
--node-label "cloud.google.com/gke-nodepool=control-plane-pool" \
158+
--container-runtime-endpoint=/var/run/containerd/containerd.sock \
159+
--write-kubeconfig-mode 444 \
160+
--disable servicelb \
161+
--disable traefik \
162+
--disable local-storage \
163+
--disable metrics-server \
164+
--flannel-backend=none \
165+
--kubelet-arg config=/etc/kubernetes/kubelet-config.json \
166+
--kubelet-arg feature-gates=LocalStorageCapacityIsolation=true \
167+
--kubelet-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \
168+
--kube-apiserver-arg feature-gates=LocalStorageCapacityIsolation=true \
169+
--kube-apiserver-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \
170+
--cluster-init
171+
172+
kubectl label nodes ${vmName} \
173+
gitpod.io/workload_meta=true \
174+
gitpod.io/workload_ide=true \
175+
gitpod.io/workload_workspace_services=true \
176+
gitpod.io/workload_workspace_regular=true \
177+
gitpod.io/workload_workspace_headless=true \
178+
gitpod.io/workspace_0=true \
179+
gitpod.io/workspace_1=true \
180+
gitpod.io/workspace_2=true
181+
182+
kubectl apply -f /var/lib/gitpod/manifests/calico.yaml
183+
kubectl apply -f /var/lib/gitpod/manifests/cert-manager.yaml
184+
kubectl apply -f /var/lib/gitpod/manifests/metrics-server.yaml
185+
186+
cat <<EOF >> /root/.bashrc
187+
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
188+
EOF
189+
runcmd:
190+
- bash /usr/local/bin/bootstrap-k3s.sh`).toString("base64")
191+
return `
192+
apiVersion: v1
193+
type: secret
194+
kind: Secret
195+
data:
196+
networkdata: ""
197+
userdata: ${userdata}
198+
metadata:
199+
name: ${secretName}
200+
namespace: ${namespace}
201+
`
202+
}

.werft/vm/vm.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,28 @@ EOF
2222
*/
2323
export function startVM(options: { name: string }) {
2424
const namespace = `preview-${options.name}`
25+
const userDataSecretName = `userdata-${options.name}`
2526

2627
kubectlApplyManifest(
2728
Manifests.NamespaceManifest({
2829
namespace
2930
})
3031
)
3132

33+
kubectlApplyManifest(
34+
Manifests.UserDataSecretManifest({
35+
vmName: options.name,
36+
namespace,
37+
secretName: userDataSecretName,
38+
})
39+
)
40+
3241
kubectlApplyManifest(
3342
Manifests.VirtualMachineManifest({
3443
namespace,
3544
vmName: options.name,
36-
claimName: `${options.name}-${Date.now()}`
45+
claimName: `${options.name}-${Date.now()}`,
46+
userDataSecretName
3747
}),
3848
{ validate: false }
3949
)

0 commit comments

Comments
 (0)