Memahami Deployment Kubernetes
Pelajari cara Deployment mengelola keadaan yang diinginkan aplikasi Anda sehingga memungkinkan pembaruan bergulir dan pengembalian versi.
Memahami Deployment Kubernetes adalah pelajaran Docker & Kubernetes for Developers gratis di CoddyKit. Ini adalah pelajaran 1 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Docker & Kubernetes for Developers, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Docker & Kubernetes for Developers mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
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:Deploymentmetadata: 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: 80Checking 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:
- Creates new Pods with the updated version.
- 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: 80Reverting 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!
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Memahami Deployment Kubernetes” gratis?
Ya — teks lengkap “Memahami Deployment Kubernetes” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Docker & Kubernetes for Developers, upgrade ke CoddyKit PRO. Kursus Docker & Kubernetes for Developers mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Memahami Deployment Kubernetes”?
Pelajari cara Deployment mengelola keadaan yang diinginkan aplikasi Anda sehingga memungkinkan pembaruan bergulir dan pengembalian versi. Kamu berlatih Docker & Kubernetes for Developers dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Docker & Kubernetes for Developers?
Tidak diperlukan pengalaman sebelumnya. Docker & Kubernetes for Developers di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 1 dari 4.
Berapa lama pelajaran “Memahami Deployment Kubernetes” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Docker & Kubernetes for Developers ini?
Ya. Setiap pelajaran Docker & Kubernetes for Developers menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Memahami Deployment Kubernetes
- Mengekspos Aplikasi dengan Layanan
- Penskalaan dan Pemulihan Mandiri Aplikasi
- Pembaruan Bergulir dan Pengembalian Versi