Zum Inhalt springen

Cluster

Das hier gezeigte Beispiel deployt einen Kubernetes-Cluster, dieselbe Logik gilt jedoch auch für einen SLURM-Cluster.
Der SSH-Schlüssel muss dem SSH-Agenten hinzugefügt werden, bevor die terraform-CLI verwendet wird.
~/projet-cloud $ eval "$(ssh-agent)"
~/projet-cloud $ ssh-add

Abhängigkeiten

env:
  OS_CLOUD: 'resinfo-discotech@stratuslab.production.virtualdata'
  TF_VAR_VM_PREFIX: 'k3s'
  TF_VAR_IMAGE_NAME: 'jammy-server-cloudimg-amd64.img'
  TF_VAR_SSH_USER: 'ubuntu'
  TF_VAR_FLAVOR_NAME: 'vd.4'
  TF_VAR_PUBLIC_NETWORK: 'public-2'
  TF_VAR_KEYPAIR: 'mykey'
dependencies:
  jq: ^1.7
  yq: ^4.25.2
  terraform.io: ^1.5
  task: ^3.30.1
  openssh.com: ^9.5
  1. Name des Eintrags in der OpenStack-Client-Konfiguration.
  2. Präfix für alle VM-Namen.
  3. Disk-Image für das VM-Deployment.
  4. SSH-Benutzername für die VM-Verbindung.
  5. Name des VM-Flavors (CPU/RAM/DISK).
  6. Name des Netzwerks mit öffentlichen IPs.
  7. Name des SSH-Schlüsselpaars.

Aufgaben

version: '3'

tasks:

  default:
    silent: true
    cmds:
    - task --list

  deploy:
    desc: deploy
    cmds:
    - |
      bash <<-'EOS'
      source <(pkgx --shellcode)
      terraform apply --auto-approve
      EOS

Aktivierung

~ $ cd projet-cloud
 ✓  ~/.pkgx/github.com/kkos/oniguruma/v6.9.8
 ✓  ~/.pkgx/stedolan.github.io/jq/v1.7.0
env +stedolan.github.io/jq^1.7 +github.com/mikefarah/yq^4.35.2 +terraform.io^1.5 +taskfile.dev^3.30.1 +gnu.org/coreutils^9.4
~/projet-cloud/ $

Terraform

Variablen

variable VM_PREFIX {
  type = string
}

variable IMAGE_NAME {
  type = string
}

variable SSH_USER {
  type = string
}

variable COMPUTE_COUNT {
  type = number
  default = 3
}

variable FLAVOR_NAME {
  type = string
}

variable PUBLIC_NETWORK {
  type = string
}

variable KEYPAIR {
  type = string
}

Ressourcen

resource openstack_compute_instance_v2 bootstrap {
  name = "manager-1"
  image_name = var.IMAGE_NAME
  flavor_name = var.FLAVOR_NAME
  key_pair = var.KEYPAIR
  network {
    name = var.PUBLIC_NETWORK
  }
}

resource openstack_compute_instance_v2 compute {
  count = var.COMPUTE_COUNT
  name = "compute-${count.index+1}"
  image_name = var.IMAGE_NAME
  flavor_name = var.FLAVOR_NAME
  key_pair = var.KEYPAIR
  network {
    name = var.PUBLIC_NETWORK
  }
}

Ausgaben

output bootstrap_user {
  value = var.SSH_USER
}

output bootstrap_ip {
  value = openstack_compute_instance_v2.bootstrap.access_ip_v4
}

output compute_ip {
  value = openstack_compute_instance_v2.compute.*.access_ip_v4
}

Ausführung

~/projet-cloud/ $ task list
~/projet-cloud/ $ task deploy