Skip to content

Instantly share code, notes, and snippets.

@jarededwards
Last active April 23, 2023 13:23
Show Gist options
  • Save jarededwards/e252547860215c977b2ecf9dc7378f58 to your computer and use it in GitHub Desktop.
Save jarededwards/e252547860215c977b2ecf9dc7378f58 to your computer and use it in GitHub Desktop.
# civo isntance setup
# run terraform to create the new civo vm
# 1. export CIVO_TOKEN=$your-civo-token (allows access to the civo terraform provider)
# 2. terraform init
# 3. terraform plan
# NOTE: the following command assumes you were satisfied with the plan in the previous step
# 4. terraform apply -auto-approve
# run the `kubefirst` cli
# 1. update line 30 below with your ssh public key
# 2. ssh on the vm and run `mkcert -install` before running kubefirst
# 3. on the new vm set your GITHUB_TOKEN env `export GITHUB_TOKEN=$your-github-token`
# 4. on the new vm set your CIVO_TOKEN env `export CIVO_TOKEN=$your-civo-token`
# 5. `kubefirst civo create --alerts-email your@email.com --github-org your-org --domain-name your-domain.com`
terraform {
required_providers {
civo = {
source = "civo/civo"
}
}
}
data "civo_size" "xlarge" {
filter {
key = "name"
values = ["g3.xlarge"]
match_by = "re"
}
filter {
key = "type"
values = ["instance"]
}
}
data "civo_disk_image" "ubuntu" {
filter {
key = "name"
values = ["ubuntu-jammy"]
}
}
resource "civo_ssh_key" "ubuntu_kubefirst" {
name = "ubuntu-kubefirst"
public_key = "ssh-rsa AAAABBBB....."
}
resource "civo_instance" "ubuntu_kubefirst" {
hostname = "ubuntu-kubefirst"
size = element(data.civo_size.xlarge.sizes, 0).name
disk_image = element(data.civo_disk_image.ubuntu.diskimages, 0).id
initial_user = "root"
public_ip_required = "create"
reverse_dns = "ubuntu-kubefirst"
script = local.startup_script
sshkey_id = civo_ssh_key.ubuntu_kubefirst.id
}
locals {
startup_script = <<EOF
#!/bin/bash
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
wget \
libnss3-tools \
--yes
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin --yes
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
mv kubectl /usr/local/bin/
chmod +x /usr/local/bin/kubectl
apt-get install wget libnss3-tools
wget https://github.com/FiloSottile/mkcert/releases/download/v1.4.4/mkcert-v1.4.4-linux-amd64
mv mkcert-v1.4.4-linux-amd64 /usr/bin/mkcert
chmod +x /usr/bin/mkcert
mkcert -install
kubectl version
export KUBEFIRST_VERSION=`curl https://github.com/kubefirst/kubefirst/releases/latest -Ls -o /dev/null -w %%{url_effective} | grep -oE "[^/]+$"`
curl -s -LO "https://github.com/kubefirst/kubefirst/releases/download/$${KUBEFIRST_VERSION}/kubefirst_$${KUBEFIRST_VERSION:1}_linux_amd64.tar.gz"
tar -xvf kubefirst_$${KUBEFIRST_VERSION:1}_linux_amd64.tar.gz -C /usr/local/bin/
chmod +x /usr/local/bin/kubefirst
ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
ssh-keyscan github.com >> ~/.ssh/known_hosts
kubefirst version
EOF
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment