[CKA] kubectl 작업 속도를 높이는 실습 흐름
명령형 생성, dry-run YAML, 검증 명령을 조합해 제한된 시간에 실수를 줄이는 작업 흐름입니다.
시험 실습에서는 처음부터 YAML 전체를 입력하기보다 명령형 명령으로 생성하거나 --dry-run=client -o yaml로 뼈대를 만든 뒤 필요한 필드만 편집하면 빠릅니다.
alias k=kubectl
export do='--dry-run=client -o yaml'
kubectl run nginx --image=nginx
kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml
kubectl create deployment web --image=nginx --replicas=3 \
--dry-run=client -o yaml > deployment.yaml
Service도 기존 Pod나 Deployment의 label을 이용해 생성할 수 있습니다.
kubectl expose pod redis --type=ClusterIP --port=6379 --name=redis-service
kubectl expose deployment web --type=NodePort --port=80 \
--name=web-service --dry-run=client -o yaml > service.yaml
NodePort 값을 직접 지정해야 한다면 생성한 YAML의 spec.ports[].nodePort를 편집한 뒤 적용합니다.
작업 전에는 context와 namespace를 확인하고, 적용 후에는 요청된 상태를 별도 명령으로 검증합니다.
kubectl config current-context
kubectl config use-context <context>
kubectl get pods -n <namespace> --show-labels
kubectl describe <resource> <name> -n <namespace>
자주 연습할 범위는 노드 장애 대응, cluster upgrade, etcd 백업·복구, PV/PVC, sidecar, nodeSelector, rolling update, Ingress, NetworkPolicy, RBAC, drain과 scale, JSONPath 출력입니다. 명령을 외우는 것보다 공식 문서에서 예제 위치를 빠르게 찾고 결과를 검증하는 흐름을 반복하는 편이 안정적입니다.