CKA/CKAD 같은 Kubernetes 자격증 시험에서 YAML 작성 시간을 줄이는 팁
시험에서는 Pod, Deployment, Service 등을 빠르게 생성해야 하는데, YAML을 일일이 작성하고 복붙하는 게 시간이 오래 걸립니다. 그래서 kubectl 명령어를 이용해 바로 리소스를 만들거나, YAML 템플릿만 빠르게 생성해서 수정 후 적용하는 방법
kubectl run vs kubectl create deploymentkubectl run
원래는 Pod를 만들 때 주로 사용. 간단하게 컨테이너 실행할 때 유용.
bash
복사편집
kubectl run nginx --image=nginx
→ 이름이 nginx이고 nginx 이미지를 사용하는 Pod가 생성됨.
kubectl create deployment
Pod를 직접 만들지 않고 Deployment 리소스를 생성.
bash
복사편집
kubectl create deployment nginx --image=nginx
→ Deployment가 자동으로 ReplicaSet → Pod를 관리.
-dry-run=client + o yaml-dry-run=client : 실제로 리소스를 생성하지 않고, "생성될 YAML"만 출력.o yaml : 출력 형식을 YAML로 지정.예)
bash
복사편집
kubectl run nginx --image=nginx --dry-run=client -o yaml
→ nginx Pod를 만들기 위한 YAML을 터미널에 출력 (리소스는 안 만듦).
bash
복사편집
kubectl create deployment nginx --image=nginx --dry-run=client -o yaml > nginx-deployment.yaml
> 로 파일 저장
파일을 열어서 replicas 값을 수정
적용:
bash
복사편집
kubectl create -f nginx-deployment.yaml