Skip to content

GitHub Actions

Automatisiere Cluster-Bereitstellung und Konfigurations-Sync mit GitHub Actions.

Voraussetzungen

  • Ein Repository, das deine cluster.lok8s.yaml enthält
  • lok8s CLI in CI verfügbar (installiert via b env add)
  • Konfigurierte GitHub-Repository-Secrets

Erforderliche Secrets

Füge diese in den Repository-Einstellungen unter Settings > Secrets and variables > Actions hinzu:

SecretBeschreibung
HCLOUD_TOKENHetzner-Cloud-API-Token
SSH_PRIVATE_KEYPrivater SSH-Schlüssel für den Node-Zugriff
KUBECONFIGBase64-kodierte kubeconfig (für Sync-Workflows)

Provision-Workflow

Erstelle .github/workflows/provision.yml:

yaml
name: Provision Cluster
on:
  workflow_dispatch:
    inputs:
      action:
        description: 'Action to perform'
        required: true
        default: 'provision'
        type: choice
        options:
          - provision
          - destroy

jobs:
  provision:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install lok8s
        run: b env add github.com/kernpilot/lok8s

      - name: Setup SSH key
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519

      - name: Provision
        env:
          HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
        run: lo provision

Sync-Workflow

Erstelle .github/workflows/sync.yml, um Konfigurationsänderungen bei einem Push anzuwenden:

yaml
name: Sync Cluster
on:
  push:
    branches: [main]
    paths:
      - 'cluster.lok8s.yaml'
      - 'deploy/**'

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install lok8s
        run: b env add github.com/kernpilot/lok8s

      - name: Setup kubeconfig
        run: |
          mkdir -p ~/.kube
          echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config

      - name: Reconcile infrastructure
        env:
          HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
        run: lo provision

      - name: Deploy platform
        run: lo deploy

lo provision ist idempotent — erneutes Ausführen gleicht den Cluster an deine Spezifikation an. lo deploy rollt die Plattform-/Workload-Manifeste unter deploy/ aus.

Nächste Schritte


Doku-Status

AspektDetail
Zustandaktiv
Zuletzt geprüft2026-04-04