CKA 배포 및 서비스 실습 #2
발행: (2026년 1월 9일 오전 08:38 GMT+9)
4 min read
원문: Dev.to
Source: Dev.to
전역 규칙
kubectl edit사용 금지- 요청이 없는 한 리소스를 재생성하지 않음
- 문제는
kubectl patch/set/scale/rollout로 해결 - 네임스페이스를 반드시 사용
- 실제 CKA 시험처럼 진행
기본 설정 (모든 머신에서 실행)
Step 0 – 클러스터 시작
minikube start --driver=docker
kubectl create namespace cka-lab
kubectl config set-context --current --namespace=cka-lab
애플리케이션 배포
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 4
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
EOF
애플리케이션 노출
kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: web-svc
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80
type: ClusterIP
EOF
트래픽 생성
kubectl run traffic --image=busybox -it --rm -- sh
Pod 내부:
while true; do
wget -qO- web-svc
echo "-----"
sleep 1
done
작업
배포 전략 수정
kubectl patch deployment web-app -p '
{
"spec": {
"strategy": {
"type": "RollingUpdate",
"rollingUpdate": {
"maxUnavailable": 4,
"maxSurge": 0
}
}
}
}'
- 이미지 업데이트 시 다운타임 없음
- 트래픽 루프가 절대 멈추지 않음
- 최소 하나의 Pod는 항상 가용 상태 유지
실패하는 이미지 시뮬레이션
kubectl set image deployment/web-app nginx=nginx:doesnotexist
배포를 정상 상태로 복구 (삭제 없이)
kubectl patch deployment web-app --type=json -p='[
{
"op": "remove",
"path": "/spec/template/spec/containers/0/readinessProbe"
}
]'
- 모든 Pod가 Running 상태이며
CrashLoopBackOff없음 - 트래픽 루프가 안정적으로 유지
트래픽이 준비된 Pod에만 전달되도록 보장 (클러스터 재시작 금지)
서비스 셀렉터를 잘못된 값으로 패치:
kubectl patch svc web-svc -p '
{
"spec": {
"selector": {
"app": "wrong"
}
}
}'
서비스 재생성 없이 올바른 셀렉터 복구
kubectl patch svc web-svc -p '
{
"spec": {
"selector": {
"app": "web"
}
}
}'
- 엔드포인트가 다시 채워지고 트래픽이 재개
카나리 버전 배포
kubectl create deployment web-app-canary --image=nginx:1.27 --replicas=1
kubectl label deployment web-app-canary track=canary
- 카나리 버전이 안정 버전과 함께 트래픽을 받음
- 서비스 재생성 없음
결함이 있는 카나리 즉시 제거
kubectl delete deployment web-app-canary
- 안정 버전이 중단 없이 트래픽 제공 지속
롤아웃 일시 중지, 이미지 업데이트, 롤아웃 완료
kubectl rollout pause deployment web-app
kubectl set image deployment/web-app nginx=nginx:1.26
- 롤아웃이 멈춘 이유 파악
- 배포 완료:
kubectl rollout resume deployment web-app
- 새 이미지가 완전히 배포되고 롤아웃이 더 이상 일시 중지되지 않음
서비스 NodePort로 노출 (재생성 없이)
kubectl patch svc web-svc -p '
{
"spec": {
"type": "NodePort"
}
}'
- 할당된 NodePort를 통해 브라우저에서 애플리케이션에 접근 가능
레플리카 수를 0으로 축소하고 서비스 복구
kubectl scale deployment web-app --replicas=0
원래 레플리카 수 복원 (Pod 재생성 금지):
kubectl scale deployment web-app --replicas=4
- Pod가 실행되고 트래픽이 복구됨
정리
kubectl delete namespace cka-lab
- 네임스페이스가 비어 있어야 함
kubectl get all
# → No resources found