Path: blob/main/dev/preview/infrastructure/scripts/bootstrap-k3s.sh
2498 views
#!/bin/bash12set -eo pipefail34# inspired by https://github.com/gitpod-io/ops/blob/main/deploy/workspace/templates/bootstrap.sh56# Install k3s7export INSTALL_K3S_SKIP_DOWNLOAD=true8SERVICE_DNS_IP="$(hostname -I | cut -d ' ' -f1)"9export SERVICE_DNS_IP1011/usr/local/bin/install-k3s.sh \12--token "1234" \13--node-ip "$SERVICE_DNS_IP" \14--tls-san "${preview_name}.preview.gitpod-dev.com" \15--node-label "cloud.google.com/gke-nodepool=control-plane-pool" \16--container-runtime-endpoint=/var/run/containerd/containerd.sock \17--write-kubeconfig-mode 444 \18--disable traefik \19--disable metrics-server \20--disable-network-policy \21--disable-cloud-controller \22--flannel-backend=none \23--kubelet-arg config=/etc/kubernetes/kubelet-config.json \24--kubelet-arg cgroup-driver=systemd \25--kubelet-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \26--kube-apiserver-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \27--cluster-init2829# Seems like this is a bit flaky now, with k3s not always being ready, and the labeling30# failing occasionally. Sleeping for a bit solves it.31sleep 103233# shellcheck disable=SC215434# shellcheck disable=SC208635kubectl label nodes ${vm_name} \36gitpod.io/workload_meta=true \37gitpod.io/workload_ide=true \38gitpod.io/workload_workspace_services=true \39gitpod.io/workload_services=true \40gitpod.io/workload_workspace_regular=true \41gitpod.io/workload_workspace_headless=true \42gitpod.io/workspace_0=true \43gitpod.io/workspace_1=true \44gitpod.io/workspace_2=true4546# apply fix from https://github.com/k3s-io/klipper-lb/issues/6 so we can use the klipper servicelb47# this can be removed if https://github.com/gitpod-io/gitpod-packer-gcp-image/pull/20 gets merged48# shellcheck disable=SC200249# shellcheck disable=SC100150cat /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.yaml5152sed -i 's/docker.io/quay.io/g' /var/lib/gitpod/manifests/calico2.yaml53sed -i 's/interface=ens/interface=en/g' /var/lib/gitpod/manifests/calico2.yaml54# shellcheck disable=SC201655sed -i 's/\$CLUSTER_IP_RANGE/10.20.0.0\/16/g' /var/lib/gitpod/manifests/calico2.yaml5657kubectl apply -f /var/lib/gitpod/manifests/calico2.yaml5859kubectl apply -f /var/lib/gitpod/manifests/cert-manager.yaml60kubectl apply -f /var/lib/gitpod/manifests/metrics-server.yaml6162# install CSI snapshotter CRDs and snapshot controller63kubectl apply -f /var/lib/gitpod/manifests/csi-driver.yaml || true64kubectl apply -f /var/lib/gitpod/manifests/csi-config.yaml || true6566cat <<EOF >>/etc/bash.bashrc67export KUBECONFIG=/etc/rancher/k3s/k3s.yaml68EOF697071