-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathmanifests.ts
228 lines (212 loc) · 6.93 KB
/
manifests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
type NamespaceManifestOptions = {
namespace: string
}
export function NamespaceManifest({ namespace }: NamespaceManifestOptions) {
return `
apiVersion: v1
kind: Namespace
metadata:
name: ${namespace}
`
}
type VirtualMachineManifestArguments = {
vmName: string
namespace: string
claimName: string
userDataSecretName: string
}
export function VirtualMachineManifest({ vmName, namespace, claimName, userDataSecretName }: VirtualMachineManifestArguments) {
return `
apiVersion: kubevirt.io/v1
type: kubevirt.io.virtualmachine
kind: VirtualMachine
metadata:
namespace: ${namespace}
annotations:
harvesterhci.io/volumeClaimTemplates: '[{"metadata":{"name":"${claimName}","annotations":{"harvesterhci.io/imageId":"default/image-wh4cr"}},"spec":{"accessModes":["ReadWriteMany"],"resources":{"requests":{"storage":"200Gi"}},"volumeMode":"Block","storageClassName":"longhorn-image-wh4cr"}}]'
network.harvesterhci.io/ips: "[]"
labels:
harvesterhci.io/creator: harvester
harvesterhci.io/os: ubuntu
name: ${vmName}
spec:
running: true
template:
metadata:
annotations:
harvesterhci.io/sshNames: "[]"
labels:
harvesterhci.io/vmName: ${vmName}
spec:
readinessProbe:
tcpSocket:
port: 2200
initialDelaySeconds: 120
periodSeconds: 20
timeoutSeconds: 10
failureThreshold: 10
successThreshold: 10
domain:
hostname: ${vmName}
machine:
type: q35
cpu:
cores: 6
sockets: 1
threads: 1
devices:
interfaces:
- masquerade: {}
model: virtio
name: default
disks:
- name: system
bootOrder: 1
disk:
bus: scsi
- name: cloudinitdisk
disk:
bus: virtio
resources:
limits:
memory: 12Gi
cpu: 6
evictionStrategy: LiveMigrate
networks:
- pod: {}
name: default
volumes:
- name: system
persistentVolumeClaim:
claimName: ${claimName}
- name: cloudinitdisk
cloudInitNoCloud:
networkDataSecretRef:
name: ${userDataSecretName}
secretRef:
name: ${userDataSecretName}
`
}
type ServiceManifestOptions = {
vmName: string
namespace: string
}
export function ServiceManifest({ vmName, namespace }: ServiceManifestOptions) {
return `
apiVersion: v1
kind: Service
metadata:
name: proxy
namespace: ${namespace}
spec:
ports:
- name: ssh-gateway
protocol: TCP
port: 22
targetPort: 22
- name: vm-ssh
protocol: TCP
port: 2200
targetPort: 2200
- name: http
protocol: TCP
port: 80
targetPort: 80
- name: https
protocol: TCP
port: 443
targetPort: 443
- name: kube-api
protocol: TCP
port: 6443
targetPort: 6443
- name: prometheus
protocol: TCP
port: 9090
targetPort: 32001
- name: grafana
protocol: TCP
port: 3000
targetPort: 32000
selector:
harvesterhci.io/vmName: ${vmName}
type: ClusterIP
`
}
type UserDataSecretManifestOptions = {
vmName: string
namespace: string,
secretName: string
}
export function UserDataSecretManifest({vmName, namespace, secretName }: UserDataSecretManifestOptions) {
const userdata = Buffer.from(`#cloud-config
users:
- name: ubuntu
sudo: "ALL=(ALL) NOPASSWD: ALL"
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC/aB/HYsb56V0NBOEab6j33v3LIxRiGqG4fmidAryAXevLyTANJPF8m44KSzSQg7AI7PMy6egxQp/JqH2b+3z1cItWuHZSU+klsKNuf5HxK7AOrND3ahbejZfyYewtKFQ3X9rv5Sk8TAR5gw5oPbkTR61jiLa58Sw7UkhLm2EDguGASb6mBal8iboiF8Wpl8QIvPmJaGIOY2YwXLepwFA3S3kVqW88eh2WFmjTMre5ASLguYNkHXjyb/TuhVFzAvphzpl84RAaEyjKYnk45fh4xRXx+oKqlfKRJJ/Owxa7SmGO+/4rWb3chdnpodHeu7XjERmjYLY+r46sf6n6ySgEht1xAWjMb1uqZqkDx+fDDsjFSeaN3ncX6HSoDOrphFmXYSwaMpZ8v67A791fuUPrMLC+YMckhTuX2g4i3XUdumIWvhaMvKhy/JRRMsfUH0h+KAkBLI6tn5ozoXiQhgM4SAE5HsMr6CydSIzab0yY3sq0avmZgeoc78+8PKPkZG1zRMEspV/hKKBC8hq7nm0bu4IgzuEIYHowOD8svqA0ufhDWxTt6A4Jo0xDzhFyKme7KfmW7SIhpejf3T1Wlf+QINs1hURr8LSOZEyY2SzYmAoQ49N0SSPb5xyG44cptpKcj0WCAJjBJoZqz0F5x9TjJ8XToB5obyJfRHD1JjxoMQ== [email protected]
chpasswd:
list: |
ubuntu:ubuntu
expire: False
write_files:
- path: /etc/ssh/sshd_config.d/101-change-ssh-port.conf
permission: 0644
owner: root
content: 'Port 2200'
- path: /usr/local/bin/bootstrap-k3s.sh
permissions: 0744
owner: root
content: |
#!/bin/bash
set -eo pipefail
# inspired by https://github.com/gitpod-io/ops/blob/main/deploy/workspace/templates/bootstrap.sh
# Install k3s
export INSTALL_K3S_SKIP_DOWNLOAD=true
/usr/local/bin/install-k3s.sh \\
--token "1234" \\
--node-ip "$(hostname -I | cut -d ' ' -f1)" \\
--node-label "cloud.google.com/gke-nodepool=control-plane-pool" \\
--container-runtime-endpoint=/var/run/containerd/containerd.sock \\
--write-kubeconfig-mode 444 \\
--disable traefik \\
--disable metrics-server \\
--flannel-backend=none \\
--kubelet-arg config=/etc/kubernetes/kubelet-config.json \\
--kubelet-arg feature-gates=LocalStorageCapacityIsolation=true \\
--kubelet-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \\
--kube-apiserver-arg feature-gates=LocalStorageCapacityIsolation=true \\
--kube-apiserver-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \\
--cluster-init
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
# apply fix from https://github.com/k3s-io/klipper-lb/issues/6 so we can use the klipper servicelb
# this can be removed if https://github.com/gitpod-io/gitpod-packer-gcp-image/pull/20 gets merged
cat /var/lib/gitpod/manifests/calico.yaml | sed s/__KUBERNETES_NODE_NAME__\\"\\,/__KUBERNETES_NODE_NAME__\\",\\ \\"container_settings\\"\\:\\ \\{\\ \\"allow_ip_forwarding\\"\\:\\ true\\ \\}\\,/ > /var/lib/gitpod/manifests/calico2.yaml
kubectl apply -f /var/lib/gitpod/manifests/calico2.yaml
kubectl apply -f /var/lib/gitpod/manifests/cert-manager.yaml
kubectl apply -f /var/lib/gitpod/manifests/metrics-server.yaml
cat <<EOF >> /etc/bash.bashrc
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
EOF
runcmd:
- bash /usr/local/bin/bootstrap-k3s.sh`).toString("base64")
return `
apiVersion: v1
type: secret
kind: Secret
data:
networkdata: ""
userdata: ${userdata}
metadata:
name: ${secretName}
namespace: ${namespace}
`
}