0Pricing
Docker & Kubernetes for Developers · Lekcja

Poznawanie wdrożeń Kubernetes

Dowiedz się, jak obiekty Deployment zarządzają pożądanym stanem aplikacji, umożliwiając aktualizacje kroczące i wycofywanie zmian.

Poznawanie wdrożeń Kubernetes to bezpłatna lekcja Docker & Kubernetes for Developers na CoddyKit. To lekcja 1 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Docker & Kubernetes for Developers, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Docker & Kubernetes for Developers zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

Meet Kubernetes Deployments

Welcome to the world of Kubernetes Deployments! After learning about Pods, you might wonder how to manage many identical Pods reliably.

Deployments are a powerful Kubernetes resource that helps you declare and manage the desired state of your applications.

Why Deployments are Essential

Imagine running a web server. You need multiple copies (replicas) for high availability and to handle traffic. If one crashes, you need another to take its place.

Deployments automate these tasks:

  • Self-Healing: Replaces failed Pods automatically.
  • Scaling: Easily adjust the number of Pod replicas.
  • Updates: Perform rolling updates without downtime.
  • Rollbacks: Revert to previous versions if something goes wrong.

Desired State in Action

The core concept behind a Deployment is its desired state. You tell Kubernetes what you want your application to look like, and it works to make it happen.

For example, if you say "I want 3 Nginx Pods running version 1.21," the Deployment will ensure exactly 3 Pods with Nginx 1.21 are running, even if some fail.

Deployments and ReplicaSets

Under the hood, Deployments use another Kubernetes resource called a ReplicaSet.

  • A ReplicaSet ensures a specified number of Pod replicas are running at all times.
  • When you create a Deployment, it automatically creates a ReplicaSet.
  • When you update a Deployment, it creates a new ReplicaSet and gracefully scales down the old one while scaling up the new one.

Building a Deployment Manifest

Like most Kubernetes resources, Deployments are defined using YAML. Key fields include:

  • apiVersion: apps/v1 (for Deployments)
  • kind: Deployment
  • metadata: Name, labels to identify the Deployment.
  • spec:
    • replicas: The desired number of Pods.
    • selector: How the Deployment finds its Pods (using labels).
    • template: The Pod definition (just like a standalone Pod YAML!).

Example: Nginx Deployment

Let's create a simple Deployment for Nginx. This YAML specifies 3 replicas of an Nginx web server.

You would typically save this as nginx-deployment.yaml and apply it using kubectl apply -f nginx-deployment.yaml.

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

Checking Deployment Status

Once you've applied your Deployment, you can check its status using kubectl commands:

  • kubectl get deployments: Shows a summary of your deployments.
  • kubectl get pods -l app=nginx: See the Pods managed by your Nginx deployment.
  • kubectl describe deployment nginx-deployment: Get detailed information, including events and associated ReplicaSets.

Seamless App Updates

One of the best features of Deployments is rolling updates. This allows you to update your application version without downtime.

When you change the image or configuration in your Deployment's YAML, Kubernetes:

  1. Creates new Pods with the updated version.
  2. Gradually terminates old Pods as new ones become ready.

This ensures your application remains available throughout the update process.

Performing a Rolling Update

Let's update our Nginx Deployment to a newer version. You would edit your nginx-deployment.yaml file and change the image to nginx:1.22.1.

Then, apply the changes: kubectl apply -f nginx-deployment.yaml. Kubernetes will perform a rolling update!

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.22.1 # Changed from 1.21.6
        ports:
        - containerPort: 80

Reverting Changes

Sometimes an update goes wrong. Deployments allow you to easily rollback to a previous stable version.

Kubernetes keeps a history of your Deployments' revisions. You can see this history and revert to an earlier state if needed, minimizing the impact of bad deployments.

  • kubectl rollout history deployment nginx-deployment: View past revisions.
  • kubectl rollout undo deployment nginx-deployment --to-revision=1: Revert to a specific revision.

Deployment Knowledge Check

You've learned about the power of Kubernetes Deployments!

Which of the following capabilities is NOT directly provided by a Kubernetes Deployment?

Deployment Power-Up!

Congratulations! You've successfully understood Kubernetes Deployments.

We covered:

  • What Deployments are and why they are crucial for managing applications.
  • The concept of desired state and how Deployments use ReplicaSets.
  • How to create, inspect, update, and rollback Deployments.

Next, we'll explore how to make your applications accessible using Kubernetes Services!

Często zadawane pytania

Czy lekcja „Poznawanie wdrożeń Kubernetes” jest bezpłatna?

Tak — pełny tekst „Poznawanie wdrożeń Kubernetes” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Docker & Kubernetes for Developers, przejdź na CoddyKit PRO. Kurs Docker & Kubernetes for Developers zawiera 4 lekcji w sumie.

Co nauczysz się w „Poznawanie wdrożeń Kubernetes”?

Dowiedz się, jak obiekty Deployment zarządzają pożądanym stanem aplikacji, umożliwiając aktualizacje kroczące i wycofywanie zmian. Ćwiczysz Docker & Kubernetes for Developers z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Docker & Kubernetes for Developers?

Nie wymagamy żadnego doświadczenia. Docker & Kubernetes for Developers w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 1 z 4.

Ile czasu zajmuje lekcja „Poznawanie wdrożeń Kubernetes”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Docker & Kubernetes for Developers?

Tak. Każda lekcja Docker & Kubernetes for Developers zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Poznawanie wdrożeń Kubernetes
  2. Udostępnianie aplikacji za pomocą usług
  3. Skalowanie i samonaprawianie aplikacji
  4. Aktualizacje kroczące i wycofywanie zmian
← Powrót do Docker & Kubernetes for Developers