Rex-Rancher

 view release on metacpan or  search on metacpan

eg/hetzner-gpu.Rexfile  view on Meta::CPAN

# Hetzner bare-metal GPU server → single-node RKE2 cluster
#
# Usage:
#   rex -f eg/hetzner-gpu-rke2.Rexfile -H <IP> deploy
#   rex -f eg/hetzner-gpu-rke2.Rexfile -H <IP> status
#   rex -f eg/hetzner-gpu-rke2.Rexfile -H <IP> untaint
#   rex -f eg/hetzner-gpu-rke2.Rexfile -H <IP> get_token
#
# Prerequisites:
#   - Fresh Debian/Ubuntu/openSUSE on Hetzner dedicated server with NVIDIA GPU
#   - SSH root access (key-based), Rex::LibSSH for SFTP-less hosts
#   - cpanm Rex::GPU Rex::Rancher (or -Ilib paths for dev)
#
# For development (both repos checked out):
#   rex -f eg/hetzner-gpu-rke2.Rexfile \
#       -I ../rex-gpu/lib -I lib \
#       -H <IP> deploy

use Rex -feature => ['1.4'];
use Rex::LibSSH;
use Rex::GPU;
use Rex::Rancher;

# --- Configuration ---

my $HOSTNAME   = $ENV{RKE2_HOSTNAME}   || 'rexdemo';
my $DOMAIN     = $ENV{RKE2_DOMAIN}     || 'internal';
my $TIMEZONE   = $ENV{RKE2_TIMEZONE}   || 'Europe/Berlin';
my $TOKEN      = $ENV{RKE2_TOKEN}      || 'rexdemo-cluster-secret';
my $KUBECONFIG = $ENV{KUBECONFIG}      || "$ENV{HOME}/.kube/rexdemo.yaml";

# --- Connection ---

set connection  => 'LibSSH';
set user        => ($ENV{REX_USER} || 'root');
set private_key => ($ENV{REX_KEY}  || "$ENV{HOME}/.ssh/id_ed25519");
set public_key  => ($ENV{REX_KEY}  ? "$ENV{REX_KEY}.pub" : "$ENV{HOME}/.ssh/id_ed25519.pub");
set auth        => 'key';

# ============================================================
#  Main deployment
# ============================================================

desc "Full deployment: prepare → GPU (reboot) → RKE2 → Cilium → device plugin";
task "deploy", sub {
  my $host = connection->server;
  my $tls  = $ENV{RKE2_TLS_SAN} || $host;

  rancher_deploy_server(
    distribution    => 'rke2',
    gpu             => 1,
    reboot          => 1,
    hostname        => $HOSTNAME,
    domain          => $DOMAIN,
    timezone        => $TIMEZONE,
    token           => $TOKEN,
    tls_san         => $tls,
    kubeconfig_file => $KUBECONFIG,
  );

  untaint_node(kubeconfig => $KUBECONFIG);

  say "";
  say "Done!";
  say "  export KUBECONFIG=$KUBECONFIG";
};

# ============================================================
#  Individual steps (for debugging / re-running)
# ============================================================

desc "Step 1: Prepare node only";
task "prepare", sub {
  prepare_node(
    hostname => $HOSTNAME,
    domain   => $DOMAIN,
    timezone => $TIMEZONE,
  );
};

desc "Step 2: GPU detect + install (with reboot)";
task "gpu", sub {
  gpu_setup(containerd_config => 'rke2', reboot => 1);
};

desc "Step 3: RKE2 + Cilium + device plugin (node must be prepared)";
task "rke2", sub {
  my $host = connection->server;
  my $tls  = $ENV{RKE2_TLS_SAN} || $host;

  install_server(
    distribution    => 'rke2',
    token           => $TOKEN,
    tls_san         => $tls,
    kubeconfig_file => $KUBECONFIG,
  );



( run in 0.800 second using v1.01-cache-2.11-cpan-39bf76dae61 )