728x90
1. 생성 - create | apply
1-1) kubectl create
# pod.yaml 파일이 있을 경우
kubectl create -f ./pod.yaml
# 내용과 함께 바로 작성
kubectl create -f - <<END
apiVersion: v1
kind: Pod
metadata:
name: pod1
spec:
containers:
- name: container
image: kubetm/init
END
1-2) kubectl apply
kubectl apply -f ./pod.yaml
※ Apply vs Create
두 명령어 모두 자원 생성 시 사용할 수 있는 명령어.
create는 기존에 같은 이름의 Pod가 존재하면 생성 불가.
apply는 기존에 같은 이름의 Pod가 존재하면 업데이트.
2. 자원에 대한 정보 조회 - get
// 기본 Pod 리스트 조회 (namespace 포함)
kubectl get pods -n default
// 좀 더 많은 내용 출력
kubectl get pods -o wide -n default
// Pod의 이름을 지정
kubectl get pod pod1
// JSON 형태로 출력
kubectl get pod pod1 -o json
3. 상세내용 조회 - describe
kubectl describe pod pod1
※ get VS describe
get
- 리소스를 요약해서 보여줌
- 리소스의 상태를 확인하기 위함(목록 조회의 성격이 강함)
get 특징
- 출력이 간단함
- 다양한 포맷으로 출력이 가능 (kubectl get pod $이름 -o yaml ... )
describe
- 특정 리소스의 상세 상태와 이벤트를 보여줌
- 핵심은 운영/장애분석용 명령어 (왜 올라오지 않지?, 왜 죽었지?, 왜 스케쥴링이 안 되지?, 왜 restart 하는거지? 등등..)
describe출력에서 중요한 것들
1) Node 정보
2) Container 상태
3) Resource 정보
4) Events : Failed Scheduling , BackOff, Unhealthy ...
3. 삭제 - delete
# 파일이 있을 경우, 생성한 방법 그대로 삭제
kubectl delete -f pod.yaml
# 내용과 함께 바로 작성한 경우 생성한 방법 그대로 삭제
kubectl delete -f - <<END
apiVersion: v1
kind: Pod
metadata:
name: pod1
spec:
containers:
- name: container
image: kubetm/init
END
# Pod 이름을 지정하는 방법으로 삭제
kubectl delete pod pod1
4. 컨테이너로 접근하기 - exec
# Pod 이름이 pod1인 Container로 들어가기 (나올 땐 exit)
kubectl exec pod1 -it /bin/bash
# 생성한 Pod에 Container가 두 개 이상일 때, Container 이름이 con1인 Container로 들어가기
kubectl exec pod1 -c con1 -it /bin/bash
// 과거엔 exec 사용 시, kubectl exec pod1 -it /bin/bash 로 했지만,
// 이젠 kubectl exec pod1 -it -- /bin/bash 이렇게 작성
'k8s' 카테고리의 다른 글
| 8. Volume - emptyDir | hostPath | PV/PVC (0) | 2026.05.12 |
|---|---|
| 7. Services - ClusterIP | NodePort | LoadBalancer (0) | 2026.05.11 |
| 5. Node Schedule (0) | 2026.05.07 |
| 4. Service (0) | 2026.05.07 |
| 3. labels (0) | 2026.05.07 |