Kubernetes Deploymentを理解する
Deploymentがアプリケーションの望ましい状態を管理し、ローリングアップデートやロールバックを可能にする仕組みを学びます。
「Kubernetes Deploymentを理解する」はCoddyKit上の無料Docker & Kubernetes for Developersレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDocker & Kubernetes for Developers学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Docker & Kubernetes for Developersコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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!
AI チューターと学ぶ Docker & Kubernetes for Developers — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「Kubernetes Deploymentを理解する」レッスンは無料ですか?
はい。「Kubernetes Deploymentを理解する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Docker & Kubernetes for Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Docker & Kubernetes for Developersコースには全4レッスンが含まれています。
「Kubernetes Deploymentを理解する」で何を学びますか?
Deploymentがアプリケーションの望ましい状態を管理し、ローリングアップデートやロールバックを可能にする仕組みを学びます。 ブラウザで直接実行するハンズオンコードでDocker & Kubernetes for Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Docker & Kubernetes for Developersを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのDocker & Kubernetes for Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「Kubernetes Deploymentを理解する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このDocker & Kubernetes for Developersレッスンでコードを書いて実行できますか?
はい。すべてのDocker & Kubernetes for Developersレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Kubernetes Deploymentを理解する
- Serviceによるアプリケーションの公開
- アプリケーションのスケーリングと自己修復
- ローリングアップデートとロールバック