Zum Inhalt

App Labels

ohMyHelm kann automatisch ein app-Label zu Ihren Deployments und StatefulSets hinzufügen.

Übersicht

Das app-Label ist ein standardisiertes Kubernetes-Label, das häufig für:

  • Service-Selektoren
  • Pod-Affinität/Anti-Affinität
  • Monitoring und Alerting
  • Log-Aggregation

verwendet wird.

Aktivierung

chart:
  enabled: true
  applabel: true
  fullnameOverride: "my-application"

Resultierende Manifeste

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-application
  labels:
    app: my-application
spec:
  selector:
    matchLabels:
      app: my-application
  template:
    metadata:
      labels:
        app: my-application

StatefulSet

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: my-application
  labels:
    app: my-application
spec:
  selector:
    matchLabels:
      app: my-application
  template:
    metadata:
      labels:
        app: my-application

Anwendungsfälle

Service-Selektor

Der Service verwendet automatisch das app-Label:

apiVersion: v1
kind: Service
metadata:
  name: my-application
spec:
  selector:
    app: my-application  # Matched durch applabel
  ports:
    - port: 80

Pod-Anti-Affinität

Verteilen Sie Pods auf verschiedene Nodes:

chart:
  applabel: true
  fullnameOverride: "my-application"

  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 100
          podAffinityTerm:
            labelSelector:
              matchLabels:
                app: my-application
            topologyKey: kubernetes.io/hostname

Prometheus ServiceMonitor

Das app-Label für Monitoring-Selektoren:

chart:
  applabel: true

  monitoring:
    - name: my-application
      namespace: monitoring
      release: prometheus
      endpoints:
        - port: metrics
          interval: 30s

Best Practices

  1. Konsistente Benennung - Verwenden Sie fullnameOverride für vorhersehbare Label-Werte
  2. Aktivieren für Production - applabel: true verbessert die Kubernetes-Integration
  3. Kombinieren mit anderen Labels - Ergänzen Sie mit app.kubernetes.io/ Labels für bessere Standardisierung

Standard Kubernetes Labels

Zusätzlich zum app-Label setzt ohMyHelm auch die empfohlenen Kubernetes-Labels:

labels:
  app: my-application
  app.kubernetes.io/name: my-application
  app.kubernetes.io/instance: release-name
  app.kubernetes.io/version: "1.0.0"
  app.kubernetes.io/managed-by: Helm

Siehe auch