Zum Inhalt

Namespaces

Der Namespaces-Helper erstellt Kubernetes Namespaces als Teil Ihres Helm-Releases.

Übersicht

Mit dem Namespaces-Helper können Sie Namespaces erstellen, bevor andere Ressourcen deployed werden. Dies ist besonders nützlich für:

  • Multi-Namespace-Deployments
  • Infrastruktur-Setup
  • Tenant-Isolation

Basis-Konfiguration

namespaces:
  setPreInstallHook: true
  spaces:
    - name: production

Pre-Install Hook

Empfohlen

Setzen Sie setPreInstallHook: true um sicherzustellen, dass der Namespace vor allen anderen Ressourcen erstellt wird.

namespaces:
  setPreInstallHook: true  # Namespace wird vor allen anderen Ressourcen erstellt
  spaces:
    - name: my-namespace

Mehrere Namespaces

namespaces:
  setPreInstallHook: true
  spaces:
    - name: production
    - name: staging
    - name: development
    - name: monitoring
    - name: logging

Mit Labels und Annotations

namespaces:
  setPreInstallHook: true
  spaces:
    - name: production
      labels:
        environment: production
        team: platform
      annotations:
        description: "Production workloads"

    - name: staging
      labels:
        environment: staging
        team: platform

Vollständiges Beispiel

Multi-Environment Setup

# Chart.yaml
apiVersion: v2
name: infrastructure
version: 1.0.0

dependencies:
  - name: ohmyhelm
    alias: infra
    repository: https://gitlab.com/ayedocloudsolutions/ohmyhelm
    version: 1.13.0
# values.yaml
infra:
  namespaces:
    setPreInstallHook: true
    spaces:
      - name: prod-apps
        labels:
          environment: production
          istio-injection: enabled

      - name: prod-data
        labels:
          environment: production
          backup: enabled

      - name: staging-apps
        labels:
          environment: staging

      - name: monitoring
        labels:
          purpose: observability

      - name: cert-manager
        labels:
          purpose: infrastructure

Wichtige Hinweise

Namespace-Löschung

Namespaces, die mit einem Helm Hook erstellt wurden, werden nicht automatisch gelöscht wenn Sie helm uninstall ausführen. Dies ist ein Sicherheitsmechanismus um versehentlichen Datenverlust zu vermeiden.

Manuelles Löschen

# Nach helm uninstall
kubectl delete namespace production staging development

Automatisches Löschen (nicht empfohlen)

Wenn Sie automatisches Löschen wünschen, erstellen Sie den Namespace stattdessen ohne Hook:

namespaces:
  setPreInstallHook: false  # Wird mit Release gelöscht
  spaces:
    - name: temporary-namespace

Kombination mit anderen Helpern

infra:
  # Zuerst Namespaces erstellen
  namespaces:
    setPreInstallHook: true
    spaces:
      - name: production

  # Dann Secrets im Namespace
  secrets:
    - name: db-credentials
      namespace: production
      values:
        password: ""

  # Und ConfigMaps
  configs:
    - name: app-config
      namespace: production
      values:
        config.yaml: |
          environment: production

Best Practices

  1. Immer setPreInstallHook: true verwenden für zuverlässige Reihenfolge
  2. Labels für Organisation - Verwenden Sie konsistente Labels für Filtering
  3. Resource Quotas - Definieren Sie Quotas pro Namespace für Multi-Tenancy
  4. Network Policies - Isolieren Sie Namespaces mit Network Policies
  5. Dokumentation - Beschreiben Sie den Zweck jedes Namespaces in Annotations

Siehe auch