1. cluster 관련 (kubectl config)
1-1. cluster 목록 확인
- 현재 사용중인 클러스터에 * 표시됨
kubectl config get-contexts
1-2. 현재 cluster 확인
kubectl config current-context
1-3. 현재 사용중인 cluster 변경
kubectl config use-context <cluster_name>
2. namespace 관련
2-1. 전체 namespace 목록 확인
kubectl get namespaces
2-2. 특정 namespace의 자원 목록 확인
kubectl get all -n <namespace_name>
위 명령어를 수행하면 namespace에 해당하는 아래 정보를 한 번에 확인할 수 있다.
- Pods 정보
- Services 정보
- DaemonSets 정보
- Deployments 정보
- ReplicaSets 정보
- StatefulSets 정보
3. Pod 관련
3-1. pod 정보 확인
# 전체 pod 정보 확인
kubectl get pods -A
# 특정 namespace pod 정보 확인
kubectl get pods -n <namespace_name>
# pod 상세 정보 확인
kubectl get pods -A -o wide
* 정보 조회 시 -o wide 옵션을 사용하면 추가 정보들도 함께 출력됩니다.
- IP 주소: Pod의 IP 주소
- 노드 이름 : Pod가 실행 중인 노드의 이름
- 노드 IP : Pod가 실행 중인 노드의 IP 주소
- 포트 : Pod의 포트 정보
3-2. pod 상세 정보 확인
- pod 상태, 이벤트, 컨테이너 정보 등 확인 가능
kubectl describe pod -n <namespace-name> <pod-name>
3-3. pod 내 container 로그 확인
- 특정 Pod 또는 Pod 내 컨테이너의 로그를 확인할 수 있습니다.
-c 옵션을 사용하면 특정 컨테이너의 로그를 볼 수 있습니다.
-f 옵션을 추가하면 실시간으로 올라오는 로그를 확인할 수 있다.
kubectl logs -n <namespace-name> <pod-name> [-c <container-name>]
3-4. pod 포트포워딩 설정
- 로컬 호스트와 Pod 간의 포트 포워딩을 설정할 수 있습니다.
- 원격으로 pod에 access 해야 할 때 사용할 수 있습니다.
kubectl port-forward <pod-name> <local-port>:<pod-port>
3-5. pod 삭제
- pod 삭제
kubectl delete pod <pod-name> -n <namespace>
pod가 정상적으로 삭제되지 않고 Terminating 상태로 유지될 경우 필요에 따라 강제 삭제를 진행할 수 있음.
- pod 강제 삭제
- 특정 namespace 안에 있는 pod 한 번에 강제 삭제 하고 싶을 경우
* worker node에 떠 있는 pod를 삭제하기 전에 worker node vm 삭제를 먼저 진행함. 이후에 pod 삭제 시 삭제할 node를 찾을 수 없다는 오류로 terminating 상태에 빠져서 강제 삭제를 진행했음.
# pod 강제 삭제
kubectl delete pod <pod-name> --grace-period=0 --force --namespace=<namespace>
# 특정 namespace 안에 있는 pod 한 번에 강제 삭제 하고 싶을 경우
kubectl delete pod --all --grace-period=0 --force --namespace=<namespace>
4. kubectl apply 관련
4-1. 콘솔에서 바로 kubectl apply을 위한 yaml 파일을 바로 작성하고 반영하는 방법
(namespace 생성 예시!)
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
metadata:
name: ns-sample1
labels:
test: cka
---
apiVersion: v1
kind: Namespace
metadata:
name: ns-sample2
labels:
test: cka
EOF'Cloud > kubernetes' 카테고리의 다른 글
| Kubespray로 쿠버네티스 설치하기, 클러스터 구성하기 (0) | 2024.07.29 |
|---|---|
| kind란?🧐 1개의 host 안에서 k8s cluster를 쉽게 구성하기 위한 도구 (1) | 2024.06.14 |