이 문제를 실습하는 과정은 Deployment 생성, Rolling Update, Rollback을 포함하는 쿠버네티스의 기본적인 작업 흐름입니다. 단계별로 과정을 안내할게요.
문제 1: 다음 조건으로 Deployment를 사용하는 dep-lab.yaml 파일을 생성하고, kubectl apply 명령어로 동작시킵니다.
dep-mainuihttpd:2.2name=apache, app=main, rel=stablekubernetes.io/change-cause=version 2.2YAML 파일 (dep-lab.yaml) 작성:
apiVersion: apps/v1
kind: Deployment
metadata:
name: dep-mainui
annotations:
kubernetes.io/change-cause: "version 2.2"
spec:
replicas: 2
selector:
matchLabels:
app: main
template:
metadata:
labels:
name: apache
app: main
rel: stable
spec:
containers:
- name: httpd
image: httpd:2.2
ports:
- containerPort: 80
이 YAML 파일은 dep-mainui라는 이름의 Deployment를 만들고, 2개의 Pod를 실행하며 httpd:2.2 이미지를 사용합니다.
명령어:
kubectl apply -f dep-lab.yaml
문제 2: 동작 중인 dep-lab.yaml의 이미지를 httpd:2.4 버전으로 Rolling Update 합니다.
이미지를 httpd:2.4로 업데이트하여 Rolling Update를 적용합니다.
명령어:
kubectl set image deployment/dep-mainui httpd=httpd:2.4
이 명령어는 현재 실행 중인 Deployment의 httpd 컨테이너 이미지를 httpd:2.4로 변경합니다. Rolling Update가 자동으로 실행됩니다.
문제 3: 현재의 dep-mainui 히스토리를 확인하고 rollback 시킵니다.
Deployment 히스토리 확인:
kubectl rollout history deployment/dep-mainui
Rollback:
이전 버전으로 되돌리려면, kubectl rollout undo 명령어를 사용합니다.
kubectl rollout undo deployment/dep-mainui
이 명령어는 dep-mainui Deployment를 이전 버전으로 되돌립니다.
문제 4: 현재 동작 중인 Pod의 httpd 이미지 버전을 확인합니다.
명령어:
kubectl get pods -l app=main -o=jsonpath='{.items[*].spec.containers[*].image}'
이 명령어는 app=main이라는 라벨을 가진 Pod들의 컨테이너 이미지를 확인하여, 현재 Pod에서 사용 중인 httpd 이미지 버전이 무엇인지 보여줍니다.
dep-lab.yaml 파일을 작성한 후, kubectl apply로 적용.kubectl set image 명령어로 httpd 이미지를 2.4 버전으로 업데이트.kubectl rollout history로 히스토리 확인, kubectl rollout undo로 롤백.kubectl get pods 명령어로 현재 실행 중인 Pod의 이미지 버전 확인.이 과정을 통해 Deployment의 버전 관리 및 Rollback, Rolling Update 기능을 연습할 수 있습니다.