Docker & Kubernetes for Developers · Ders

Uygulamaları ölçeklendirme ve kendi kendine iyileştirme

Dağıtımlarınız için temel ölçeklendirme stratejileri uygulayın ve Kubernetes'in uygulama kullanılabilirliği ile dayanıklılığını nasıl sağladığını öğrenin.

3. ders / 411 adım

Uygulamaları ölçeklendirme ve kendi kendine iyileştirme, CoddyKit'te ücretsiz bir Docker & Kubernetes for Developers dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Docker & Kubernetes for Developers öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Docker & Kubernetes for Developers kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

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!

Başlamak ücretsiz

Yapay zeka eğitmeniyle Docker & Kubernetes for Developers öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
12
Dersler
48

Sıkça Sorulan Sorular

“Uygulamaları ölçeklendirme ve kendi kendine iyileştirme” dersi ücretsiz mi?

Evet — “Uygulamaları ölçeklendirme ve kendi kendine iyileştirme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Docker & Kubernetes for Developers kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Docker & Kubernetes for Developers kursu toplamda 4 dersten oluşur.

“Uygulamaları ölçeklendirme ve kendi kendine iyileştirme” dersinde ne öğreneceğim?

Dağıtımlarınız için temel ölçeklendirme stratejileri uygulayın ve Kubernetes'in uygulama kullanılabilirliği ile dayanıklılığını nasıl sağladığını öğrenin. Docker & Kubernetes for Developers ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Docker & Kubernetes for Developers öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Docker & Kubernetes for Developers, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.

“Uygulamaları ölçeklendirme ve kendi kendine iyileştirme” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Docker & Kubernetes for Developers dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Docker & Kubernetes for Developers dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Kubernetes dağıtımlarını anlama
  2. Hizmetlerle uygulamaları dışa açma
  3. Uygulamaları ölçeklendirme ve kendi kendine iyileştirme
  4. Aşamalı Güncellemeler ve Geri Alımlar
← Docker & Kubernetes for Developers Sayfasına Dön