|
| 1 | +#cloud-config |
| 2 | +users: |
| 3 | +- name: ubuntu |
| 4 | + sudo: "ALL=(ALL) NOPASSWD: ALL" |
| 5 | + ssh_authorized_keys: |
| 6 | + - ${ssh_authorized_keys} |
| 7 | +chpasswd: |
| 8 | + list: | |
| 9 | + ubuntu:ubuntu |
| 10 | + expire: False |
| 11 | +write_files: |
| 12 | + - path: /etc/disable-services.sh |
| 13 | + permissions: '0755' |
| 14 | + content: | |
| 15 | + #!/bin/bash |
| 16 | + systemctl disable google-guest-agent & |
| 17 | + systemctl disable google-startup-scripts & |
| 18 | + systemctl disable google-osconfig-agent & |
| 19 | + systemctl disable google-oslogin-cache.timer & |
| 20 | + systemctl disable google-shutdown-scripts & |
| 21 | + systemctl stop google-guest-agent & |
| 22 | + systemctl stop google-startup-scripts & |
| 23 | + systemctl stop google-osconfig-agent & |
| 24 | + systemctl stop google-oslogin-cache.timer & |
| 25 | + systemctl stop google-shutdown-scripts & |
| 26 | + - path: /etc/ssh/sshd_config.d/101-change-ssh-port.conf |
| 27 | + permissions: '0644' |
| 28 | + owner: root |
| 29 | + content: 'Port 2200' |
| 30 | + |
| 31 | + - path: /usr/local/bin/bootstrap-k3s.sh |
| 32 | + permissions: '0744' |
| 33 | + owner: root |
| 34 | + content: | |
| 35 | + #!/bin/bash |
| 36 | +
|
| 37 | + set -eo pipefail |
| 38 | +
|
| 39 | + cat <<EOF >> /etc/containerd/config.toml |
| 40 | + [plugins."io.containerd.grpc.v1.cri".registry.configs."registry-1.docker.io".auth] |
| 41 | + username = "${dockerhub_user}" |
| 42 | + password = "${dockerhub_passwd}" |
| 43 | + EOF |
| 44 | + sudo systemctl restart containerd.service |
| 45 | +
|
| 46 | + # inspired by https://github.com/gitpod-io/ops/blob/main/deploy/workspace/templates/bootstrap.sh |
| 47 | +
|
| 48 | + # Install k3s |
| 49 | + export INSTALL_K3S_SKIP_DOWNLOAD=true |
| 50 | +
|
| 51 | + /usr/local/bin/install-k3s.sh \ |
| 52 | + --token "1234" \ |
| 53 | + --node-ip "$(hostname -I | cut -d ' ' -f1)" \ |
| 54 | + --node-label "cloud.google.com/gke-nodepool=control-plane-pool" \ |
| 55 | + --container-runtime-endpoint=/var/run/containerd/containerd.sock \ |
| 56 | + --write-kubeconfig-mode 444 \ |
| 57 | + --disable traefik \ |
| 58 | + --disable metrics-server \ |
| 59 | + --flannel-backend=none \ |
| 60 | + --kubelet-arg config=/etc/kubernetes/kubelet-config.json \ |
| 61 | + --kubelet-arg cgroup-driver=systemd \ |
| 62 | + --kubelet-arg feature-gates=LocalStorageCapacityIsolation=true \ |
| 63 | + --kubelet-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \ |
| 64 | + --kube-apiserver-arg feature-gates=LocalStorageCapacityIsolation=true \ |
| 65 | + --kube-apiserver-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \ |
| 66 | + --cluster-init |
| 67 | +
|
| 68 | + # Seems like this is a bit flaky now, with k3s not always being ready, and the labeling |
| 69 | + # failing occasionally. Sleeping for a bit solves it. |
| 70 | + sleep 10 |
| 71 | +
|
| 72 | + kubectl label nodes ${vm_name} \ |
| 73 | + gitpod.io/workload_meta=true \ |
| 74 | + gitpod.io/workload_ide=true \ |
| 75 | + gitpod.io/workload_workspace_services=true \ |
| 76 | + gitpod.io/workload_workspace_regular=true \ |
| 77 | + gitpod.io/workload_workspace_headless=true \ |
| 78 | + gitpod.io/workspace_0=true \ |
| 79 | + gitpod.io/workspace_1=true \ |
| 80 | + gitpod.io/workspace_2=true |
| 81 | +
|
| 82 | + # apply fix from https://github.com/k3s-io/klipper-lb/issues/6 so we can use the klipper servicelb |
| 83 | + # this can be removed if https://github.com/gitpod-io/gitpod-packer-gcp-image/pull/20 gets merged |
| 84 | + 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 |
| 85 | +
|
| 86 | + sed -i 's/docker.io/quay.io/g' /var/lib/gitpod/manifests/calico2.yaml |
| 87 | + sed -i 's/interface=ens/interface=en/g' /var/lib/gitpod/manifests/calico2.yaml |
| 88 | + sed -i 's/\$CLUSTER_IP_RANGE/10.20.0.0\/16/g' /var/lib/gitpod/manifests/calico2.yaml |
| 89 | +
|
| 90 | + kubectl apply -f /var/lib/gitpod/manifests/calico2.yaml |
| 91 | +
|
| 92 | + kubectl apply -f /var/lib/gitpod/manifests/cert-manager.yaml |
| 93 | + kubectl apply -f /var/lib/gitpod/manifests/metrics-server.yaml |
| 94 | +
|
| 95 | + # install CSI snapshotter CRDs and snapshot controller |
| 96 | + kubectl apply -f /var/lib/gitpod/manifests/csi-driver.yaml || true |
| 97 | + kubectl apply -f /var/lib/gitpod/manifests/csi-config.yaml || true |
| 98 | +
|
| 99 | + cat <<EOF >> /etc/bash.bashrc |
| 100 | + export KUBECONFIG=/etc/rancher/k3s/k3s.yaml |
| 101 | + EOF |
| 102 | +runcmd: |
| 103 | + - bash /etc/disable-services.sh |
| 104 | + - bash /usr/local/bin/bootstrap-k3s.sh |
0 commit comments