Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/preview/infrastructure/scripts/bootstrap-k3s.sh
2498 views
1
#!/bin/bash
2
3
set -eo pipefail
4
5
# inspired by https://github.com/gitpod-io/ops/blob/main/deploy/workspace/templates/bootstrap.sh
6
7
# Install k3s
8
export INSTALL_K3S_SKIP_DOWNLOAD=true
9
SERVICE_DNS_IP="$(hostname -I | cut -d ' ' -f1)"
10
export SERVICE_DNS_IP
11
12
/usr/local/bin/install-k3s.sh \
13
--token "1234" \
14
--node-ip "$SERVICE_DNS_IP" \
15
--tls-san "${preview_name}.preview.gitpod-dev.com" \
16
--node-label "cloud.google.com/gke-nodepool=control-plane-pool" \
17
--container-runtime-endpoint=/var/run/containerd/containerd.sock \
18
--write-kubeconfig-mode 444 \
19
--disable traefik \
20
--disable metrics-server \
21
--disable-network-policy \
22
--disable-cloud-controller \
23
--flannel-backend=none \
24
--kubelet-arg config=/etc/kubernetes/kubelet-config.json \
25
--kubelet-arg cgroup-driver=systemd \
26
--kubelet-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \
27
--kube-apiserver-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \
28
--cluster-init
29
30
# Seems like this is a bit flaky now, with k3s not always being ready, and the labeling
31
# failing occasionally. Sleeping for a bit solves it.
32
sleep 10
33
34
# shellcheck disable=SC2154
35
# shellcheck disable=SC2086
36
kubectl label nodes ${vm_name} \
37
gitpod.io/workload_meta=true \
38
gitpod.io/workload_ide=true \
39
gitpod.io/workload_workspace_services=true \
40
gitpod.io/workload_services=true \
41
gitpod.io/workload_workspace_regular=true \
42
gitpod.io/workload_workspace_headless=true \
43
gitpod.io/workspace_0=true \
44
gitpod.io/workspace_1=true \
45
gitpod.io/workspace_2=true
46
47
# apply fix from https://github.com/k3s-io/klipper-lb/issues/6 so we can use the klipper servicelb
48
# this can be removed if https://github.com/gitpod-io/gitpod-packer-gcp-image/pull/20 gets merged
49
# shellcheck disable=SC2002
50
# shellcheck disable=SC1001
51
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
52
53
sed -i 's/docker.io/quay.io/g' /var/lib/gitpod/manifests/calico2.yaml
54
sed -i 's/interface=ens/interface=en/g' /var/lib/gitpod/manifests/calico2.yaml
55
# shellcheck disable=SC2016
56
sed -i 's/\$CLUSTER_IP_RANGE/10.20.0.0\/16/g' /var/lib/gitpod/manifests/calico2.yaml
57
58
kubectl apply -f /var/lib/gitpod/manifests/calico2.yaml
59
60
kubectl apply -f /var/lib/gitpod/manifests/cert-manager.yaml
61
kubectl apply -f /var/lib/gitpod/manifests/metrics-server.yaml
62
63
# install CSI snapshotter CRDs and snapshot controller
64
kubectl apply -f /var/lib/gitpod/manifests/csi-driver.yaml || true
65
kubectl apply -f /var/lib/gitpod/manifests/csi-config.yaml || true
66
67
cat <<EOF >>/etc/bash.bashrc
68
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
69
EOF
70
71