Gitpod Installation - k3s

Document Last Modified: 2022-06-02 20:40:21

Setting Up PostgreSQL

  1. Create a PostgreSQL user for k3s:
    CREATE USER k3s WITH ENCRYPTED PASSWORD '$PASSWORD';
  2. Create a database for k3s to use:
    CREATE DATABASE k3s;
  3. Grant privileges to the k3s user:
    GRANT ALL PRIVILEGES ON DATABASE k3s TO k3s;

Master Node

  1. Once Ubuntu 20.04.x has been installed, login via SSH and run apt update and then apt upgrade.
  2. Next edit the /etc/fstab file and comment out the swap line. Reboot the system.
  3. Confirm that swap has been disabled - free -mh.
  4. Set the timezone using - sudo dpkg-reconfigure tzdata - set it to America/Chicago (or whatever your local timezone is).
  5. Install k3s in master mode (run this as the root user):
    $ curl -sfL https://get.k3s.io | sh -s - --datastore-endpoint 'postgres://k3s:$POSTGRES_PASSWORD@$HOSTNAME:5432/k3s?sslmode=disable' --write-kubeconfig-mode 644 --disable traefik --disable servicelb

Worker Node

  1. Once Ubuntu 20.04.x has been installed, login via SSH and run apt update and then apt upgrade.
  2. Next edit the /etc/fstab file and comment out the swap line. Reboot the system.
  3. Confirm that swap has been disabled - free -mh.
  4. Set the timezone using - sudo dpkg-reconfigure tzdata - set it to America/Chicago (or whatever your local timezone is).
  5. Install k3s in agent mode (run this as the root user):
    $ export K3S_URL=https://$MASTER_NODE_HOSTNAME:6443
    $ export K3S_TOKEN=$TOKEN
    $ curl -fsL https://get.k3s.io | K3S_URL=$K3S_URL K3S_TOKEN=$K3S_TOKEN sh -s agent --disable traefik --disable servicelb

Setting Up MySQL

  1. Run these queries in MySQL server to get the user and databases setup properly:
    
    CREATE USER IF NOT EXISTS "gitpod"@"%" IDENTIFIED BY 'PASSWORD_HERE';
    GRANT ALL ON gitpod%.* TO "gitpod"@"%";

CREATE DATABASE IF NOT EXISTS gitpod-sessions CHARSET utf8mb4; USE gitpod-sessions;

CREATE TABLE IF NOT EXISTS sessions ( session_id varchar(128) COLLATE utf8mb4_bin NOT NULL, expires int(11) unsigned NOT NULL, data text COLLATE utf8mb4_bin, _lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (session_id) );


## Assigning Workloads to Nodes (optional)

Run these command to assign workloads to our nodes. Ideally we just have one "meta" node and the rest are workspace nodes.

```shell-session
$ kubectl label worker-node-1 gitpod.io/workload_meta=true
$ kubectl label worker-node-2 gitpod.io/workload_workspace=true
$ kubectl label worker-node-3 gitpod.io/workload_workspace=true

Updating Kubernetes Configurations

  1. Set your master node to not allow scheduling:
    $ kubectl taint node master-node-name k3s-controlplane=true:NoSchedule

Installing Gitpod

Alright, we're finally ready to install Gitpod!

  1. Clone the Gitpod self-hosted repository:
    $ git clone https://octocat.ninja/gitpod-app/self-hosted.git
  2. Go into the self-hosted directory. From here everything should already be configured for our Gitpod instance.
  3. From Rancher create a Project named 'Gitpod' and a namespace within there called 'gitpod'.
  4. Run these helm command to install Gitpod:
    $ helm repo add charts.gitpod.io https://charts.gitpod.io
    $ helm dep update
    $ helm upgrade --install $(for i in $(cat configuration.txt); do echo -e "-f $i"; done) gitpod . --namespace gitpod --timeout 60m --version 0.5.0