0Pricing
Docker & Kubernetes for Developers · Lektion

Anwendungen skalieren und selbst heilen lassen

Implementieren Sie grundlegende Skalierungsstrategien für Ihre Deployments und verstehen Sie, wie Kubernetes die Verfügbarkeit und Resilienz von Anwendungen sicherstellt.

Anwendungen skalieren und selbst heilen lassen ist eine kostenlose Docker & Kubernetes for Developers-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Docker & Kubernetes for Developers-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Docker & Kubernetes for Developers-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Scaling & Self-Healing Intro

Welcome! In this lesson, we'll dive into making your applications robust and responsive using Kubernetes.

We'll explore how to scale your apps to handle varying loads and how Kubernetes enables self-healing to recover from failures automatically. These are crucial for reliable, high-availability services.

Why Scaling Matters

Scaling an application means adjusting its capacity to meet demand. Imagine a sudden surge in users for your online store—without scaling, your app might slow down or crash.

  • Handle Traffic: Distribute load across multiple instances.
  • Improve Performance: Maintain responsiveness under heavy use.
  • Boost Availability: If one instance fails, others can take over.

Scaling with Deployments

In Kubernetes, Deployments are key to scaling. They manage a set of identical pods, ensuring a desired number of replicas are always running.

You can manually scale a Deployment by changing its replicas field. For example, to scale an app named my-app to 3 pods:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: nginx:latest
        ports:
        - containerPort: 80

Introducing Horizontal Pod Autoscaler

While manual scaling works, it's not ideal for dynamic workloads. This is where the Horizontal Pod Autoscaler (HPA) comes in!

HPA automatically adjusts the number of pods in a Deployment (or StatefulSet) based on observed metrics like CPU utilization or custom metrics.

Configuring an HPA

An HPA resource defines the target for your application's scaling. It monitors metrics and increases or decreases pod replicas within defined minimum and maximum limits.

Here's a basic HPA manifest that targets 50% CPU utilization:

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: my-app-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-app-deployment
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50

What is Self-Healing?

Beyond scaling, Kubernetes also excels at self-healing. This means it can automatically detect and recover from application failures without human intervention.

If a pod crashes, becomes unresponsive, or gets terminated, Kubernetes' controllers (like the Deployment controller) will work to replace it and restore the desired state.

Liveness Probes: Are You Alive?

Liveness probes tell Kubernetes if your application inside a container is still running and healthy. If a liveness probe fails, Kubernetes will restart the container.

This is crucial for apps that might deadlock or become unresponsive but aren't technically 'crashed'.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: liveness-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: liveness-app
  template:
    metadata:
      labels:
        app: liveness-app
    spec:
      containers:
      - name: liveness-container
        image: busybox
        args:
        - /bin/sh
        - -c
        - touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 600
        livenessProbe:
          exec:
            command:
            - cat
            - /tmp/healthy
          initialDelaySeconds: 5
          periodSeconds: 5

Readiness Probes: Ready for Traffic?

Readiness probes tell Kubernetes if your application is ready to serve network traffic. If a readiness probe fails, Kubernetes stops sending traffic to that pod.

This prevents new requests from going to a pod that's still starting up, loading data, or temporarily unhealthy.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: readiness-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: readiness-app
  template:
    metadata:
      labels:
        app: readiness-app
    spec:
      containers:
      - name: readiness-container
        image: nginx:latest
        ports:
        - containerPort: 80
        readinessProbe:
          httpGet:
            path: /index.html
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5

Scaling & Healing Synergy

HPA, Liveness, and Readiness probes work together to make your applications highly available and resilient.

  • HPA handles varying load by adjusting replicas.
  • Liveness probes ensure containers are restarted if they become unresponsive.
  • Readiness probes ensure traffic only goes to fully operational pods.

This combined approach significantly improves application reliability in dynamic environments.

Quick Check

Which of the following statements about Kubernetes scaling and self-healing mechanisms are TRUE?

Recap & Next Steps

Great job! You've learned how Kubernetes helps your applications stay available and performant:

  • Scaling: Adjusting capacity with Deployments and HPA.
  • Self-Healing: Automatic recovery using Liveness and Readiness probes.

These powerful features are fundamental for building robust, cloud-native applications. Keep practicing to master them!

Häufig gestellte Fragen

Ist die Lektion „Anwendungen skalieren und selbst heilen lassen“ kostenlos?

Ja — der vollständige Text von „Anwendungen skalieren und selbst heilen lassen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Docker & Kubernetes for Developers-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Docker & Kubernetes for Developers-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Anwendungen skalieren und selbst heilen lassen“?

Implementieren Sie grundlegende Skalierungsstrategien für Ihre Deployments und verstehen Sie, wie Kubernetes die Verfügbarkeit und Resilienz von Anwendungen sicherstellt. Du übst Docker & Kubernetes for Developers mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Docker & Kubernetes for Developers zu starten?

Keine Vorkenntnisse erforderlich. Docker & Kubernetes for Developers auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.

Wie lange dauert die Lektion „Anwendungen skalieren und selbst heilen lassen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Docker & Kubernetes for Developers-Lektion Code schreiben und ausführen?

Ja. Jede Docker & Kubernetes for Developers-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Kubernetes-Deployments verstehen
  2. Anwendungen mit Services verfügbar machen
  3. Anwendungen skalieren und selbst heilen lassen
  4. Rolling Updates und Rollbacks
← Zurück zu Docker & Kubernetes for Developers