Gigakubegigakube.ch →Menu ↓

Command line (gk) and OpenTofu/Terraform

Managing a project from a terminal with gk, and as code with OpenTofu or Terraform: both work with an API key, on the same API as everything else.

What they are

Both use an API key: they can do what the key's role allows, in the key's project, and nothing else. With a key that requires approval every change becomes a change request that a person approves. Both run on macOS and Linux, on Intel/AMD (amd64) and ARM (arm64) machines.

Install

The binaries are not yet on a download page or in the public registries: until they are, ask us through support (Support in the panel) and we send you gk and the provider for your system. This page will say where to get them as soon as they are published.

Put gk somewhere in your PATH and check it:

gk version

gk: first steps

Create a key in the panel (API & agents → New API key), then:

gk login            # paste the key: it is not shown and not written in your shell history
gk status           # project, role, zones
gk catalog          # sizes, images, Kubernetes versions

gk login checks the key and tells you where it keeps it: on a Mac in the Keychain, on a Linux desktop in the system keyring, otherwise (servers, SSH sessions) in a file readable only by you. Alternatively set GK_API_KEY in the environment: it always wins over the stored key. gk logout forgets the key; to make it stop working, revoke it in the panel.

Servers and ports

gk servers create web-1 --size s-2-4 --image debian-13 --ssh-key ~/.ssh/id_ed25519.pub
gk servers list
gk firewall open web-1 443
gk firewall open web-1 22 --source 203.0.113.0/24
gk servers stop web-1
gk servers delete web-1

Servers can be named by name or id. Ports other than 80 and 443 need --source, as in the panel (Firewall).

Size, disks, snapshots, backups

gk servers resize web-1 --size s-4-8 --disk-gb 40   # restarts it if it runs; disks only grow
gk servers metrics web-1                            # CPU, memory, disk, network: 24h, or --range 30d
gk snapshots create web-1 before-upgrade
gk snapshots restore web-1 before-upgrade           # server stopped; the newest snapshot only
gk volumes create data --size-gb 100 --server web-1
gk volumes resize data --size-gb 200
gk backups set nightly --server web-1 --at 02:30 --keep 14
gk backups points --server web-1

See Virtual machines for what each one does and costs.

Physical servers

gk baremetal catalog                                # models, free servers, prices, your monthly limit
gk baremetal rent gpu1 --model g5090 --image ubuntu-26.04 --ssh-key ~/.ssh/id_ed25519.pub --wait
gk baremetal return gpu1                            # switched off, ALL disks erased

A rented server is charged by the hour until you return it, on or off, within the project's monthly limit for physical servers (Physical servers).

Object storage

gk buckets create photos
gk s3-keys create backup-job --bucket photos:read_write   # prints the secret once, with aws-cli and rclone settings
gk s3-keys grant backup-job photos read                    # none removes the access
gk buckets website photos on                               # public: anyone can read every object
gk buckets delete photos --force                           # with its objects

The secret of an S3 key is shown once and we do not keep it: copy it when gk prints it. A key that requires approval cannot create S3 keys; create them in the panel or with another key (Object storage).

Kubernetes

gk k8s create prod --pool workers:s-4-8:3
gk k8s kubeconfig prod --file prod.kubeconfig
gk k8s pools set prod workers --size s-4-8 --count 5

A pool is name:size:count, optionally :disk_gb and :public for a public address per node. The kubeconfig needs a key with Can manage that does not require approval, and is written with permissions only for you (Kubernetes).

DNS

gk dns zones
gk dns set example.ch www A 31.44.45.10 --ttl 300
gk dns set example.ch @ MX "10 mail.example.ch"
gk dns delete example.ch www A

Plans, confirmation, JSON

Shell completion

source <(gk completion bash)   # in ~/.bashrc
source <(gk completion zsh)    # in ~/.zshrc
gk completion fish | source    # in ~/.config/fish/config.fish

OpenTofu and Terraform

terraform {
  required_providers {
    gigakube = {
      source = "gigakube/gigakube"
    }
  }
}

provider "gigakube" {}   # the key comes from GK_API_KEY

resource "gigakube_server" "web" {
  name       = "web-1"
  size       = "s-2-4"
  image      = "debian-13"
  ssh_key    = file(pathexpand("~/.ssh/id_ed25519.pub"))
}

resource "gigakube_firewall_rule" "https" {
  server_id = gigakube_server.web.id
  port      = 443
}

resource "gigakube_dns_record" "www" {
  zone    = "example.ch"
  name    = "www"
  type    = "A"
  records = [gigakube_server.web.public_ipv4]
}
export GK_API_KEY=gk_…
tofu init && tofu plan && tofu apply

Until the provider is in the registries, we send it with installation instructions (a local provider folder).

Provider settings

Setting Environment variable Meaning
api_key GK_API_KEY The key. Use the environment variable: a key written in a .tf file ends up in version control.
location GK_LOCATION Default zone (gk01 Zurich, gk02 Varese). Without it, the project's home zone.
approval_timeout With a key that requires approval: how long apply waits for a person to approve each change, e.g. "30m". Without it, apply stops at once, says which change request was created, and changes nothing; run it again once the request is approved and done.
api_url GK_API_URL Only if we tell you to use another address.

Resources

Resource What it is
gigakube_server A virtual machine. size, a larger disk_gb, reverse_dns and running change in place (a size or disk change restarts a running server); the image, a smaller disk and the network settings replace it.
gigakube_firewall_rule One open port of a server (tcp or udp, with its source).
gigakube_network An L2 network (Networking).
gigakube_network_attachment A server attached to an L2 network.
gigakube_nat_gateway The way out to the Internet for servers and nodes without a public address.
gigakube_placement_group Servers kept on different hosts.
gigakube_kubernetes_cluster A Kubernetes cluster with its node_pools, which change in place.
gigakube_dns_record All the records with one name and type in a DNS zone of the project.
gigakube_ssh_key An SSH key saved in your account (needs a Can manage key that does not require approval).
gigakube_volume An additional disk; it grows in place.
gigakube_volume_attachment An additional disk attached to a server.
gigakube_server_snapshot A snapshot of a server's system disk (restoring is done with gk or the panel).
gigakube_backup_policy Scheduled backups of servers, kept in their zone.
gigakube_baremetal_server A rented physical server. Destroying it returns it and erases all its disks.
gigakube_bucket An S3 bucket; public_website changes in place. A bucket with objects is destroyed only with force_destroy = true.
gigakube_s3_access_key An S3 access key. Its secret_access_key is in the state from creation on (sensitive): encrypt the state. Imported keys have no secret. Needs an API key that does not require approval.
gigakube_s3_access_key_bucket What an S3 key can do on a bucket: read, write or read_write.

Data sources: gigakube_project, gigakube_catalog (sizes, images, Kubernetes versions), gigakube_public_ips, gigakube_volumes, gigakube_networks, gigakube_kubernetes_kubeconfig, gigakube_baremetal_catalog. The kubeconfig is stored in the state file: keep the state private and encrypted (OpenTofu can encrypt it).

Every resource can be imported: tofu import gigakube_server.web <id>, for another zone gk02:<id>; a firewall rule is <server id>/<rule id> (gk firewall list shows both), a snapshot <server id>/<snapshot id>, a DNS record <zone>/<full name>/<TYPE>, e.g. example.ch/www.example.ch/A, a backup policy its name.

Not available: reserving a public address on its own (addresses come with servers and the NAT gateway).

Good habits