파드: 컨테이너의 모음
쿠버네티스가 관리할 수 있는 가장 작은 워크로드는 파드
명령형 커맨드로 파드 생성
kubectl run myweb --image httpd
파드 목록 확인
kubectl get pods
특정 파드 확인
kubectl get pods myweb
파드 상세 정보
kubectl get pods -o wide
kubectl get pods -o yaml
kubectl get pods -o json
kubectl describe pods myweb
애플리케이션 로그
kubectl logs myweb
파드 삭제
kubectl delete pods myweb
myweb.yaml
apiVersion: v1
kind: Pod
metadata:
name: myweb
spec:
containers:
- name: myweb
image: httpd
ports:
- containerPort: 80
protocol: TCP
kubectl explain pods
파일을 이용한 pods 생성
kubectl create -f myweb.yaml
파일을 이용한 pods 확인
kubectl get -f myweb.yaml
kubectl describe -f myweb.yaml
파일을 이용한 pods 삭제
kubectl delete -f myweb.yaml
사이드카 패턴
https://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns/
- sidecar: 기능의 확장
- ambassador: 프록시/LB
- adpator: 출력의 표준
테스트 & 디버깅 목적
kubectl port-forward pods/myweb 8080:80
이름: 네임스페이스 유일
UID: 클러스터에서 유일
리소스를 분리
서비스: DNS 이름이 분리되는 용도
RBAC: 권한을 NS에 설정
https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/namespaces/
kubectl get namespaces
kubectl create ns developments
ns 삭제
kubectl delete ns developments
ns 확인
kubectl get pods -A | --all-namespaces
name 옵션을 통한 확인
kubectl get pods -n kube-system
ns-dev.yaml
apiVersion: v1
kind: Namespace
metadata:
name: dev
kubectl create -f ns-dev.yaml
myweb-dev.yaml
apiVersion: v1
kind: Pod
metadata:
name: myweb
namespace: dev
spec:
containers:
- name: myweb
image: httpd
ports:
- containerPort: 80
protocol: TCP
kubectl create -f myweb-dev.yaml
kubectl delete -f myweb-dev.yaml
https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/labels/
https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/common-labels/
레이블 확인
kubectl get pods --show-labels
kubectl get pods X -o yaml
kubectl describe pods X
레이블 관리
kubectl label pods myweb APP=apache
kubectl label pods myweb ENV=developments
kubectl label pods myweb ENV=staging
overwrite 옵션 사용 (덮어쓰기)
kubectl label pods myweb ENV=staging --overwirte
kubectl label pods myweb ENV-
=
==
!=
kubectl get pods -l APP=nginx
kubectl get pods -l APP==nginx
kubectl get pods -l 'APP!=nginx'
in
notin
exists
: 키만 매칭kubectl get pods -l 'APP'
doesnotexists
: 키 제외 매칭kubectl get pods -l '!APP'
레이블과 비슷
비 식별 메타데이타
애플리케이션이 해당 메타데이터를 참조할 수 있음 -> 애플리케이션 작동 변경
명령형 커맨드
kubectl annotate pods myweb created-by=Jang
kubectl annotate pods myweb created-by=Kim --overwrite
kubectl annotate pods myweb created-by-
YAML
apiVersion: v1
kind: Pod
metadata:
name: myweb-label-anno
labels:
APP: apache
ENV: staging
annotations:
Created-by: Jang
spec:
containers:
- name: myweb
image: httpd
ports:
- containerPort: 80
protocol: TCP