애플리케이션 확장 및 자동 복구
배포를 위한 기본 확장 전략을 구현하고 Kubernetes가 애플리케이션의 가용성과 복원력을 보장하는 방식을 이해합니다.
애플리케이션 확장 및 자동 복구은(는) CoddyKit의 무료 Docker & Kubernetes for Developers 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Docker & Kubernetes for Developers 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
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: 80Introducing 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: 50What 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: 5Readiness 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: 5Scaling & 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!
자주 묻는 질문
“애플리케이션 확장 및 자동 복구” 강의는 무료인가요?
네 — “애플리케이션 확장 및 자동 복구” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Docker & Kubernetes for Developers 강의 전체를 잠금 해제할 수 있습니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.
“애플리케이션 확장 및 자동 복구”에서 뭘 배우나요?
배포를 위한 기본 확장 전략을 구현하고 Kubernetes가 애플리케이션의 가용성과 복원력을 보장하는 방식을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Docker & Kubernetes for Developers을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Docker & Kubernetes for Developers을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Docker & Kubernetes for Developers은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“애플리케이션 확장 및 자동 복구” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Docker & Kubernetes for Developers 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Docker & Kubernetes for Developers 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Kubernetes Deployment 이해
- Service를 활용한 애플리케이션 노출
- 애플리케이션 확장 및 자동 복구
- 롤링 업데이트 및 롤백