쿠버네티스의 최소 배포 단위
Pod을 생성하기 위해 아래 YAML 파일로 작성하여 실행
apiVersion: v1
kind: Pod
# 이름, 라벨, 어노테이션 등의 메타데이터
metadata:
name: example-pod
labels:
app: example
spec:
# Pod 컨테이너의 재시작 정책, Always 외 OnFailure, Never까지 있음
restartPolicy: Always
# 컨테이너 리스트, 컨테이너에 들어갈 이미지, 포트, 환경변수 등 기입
containers:
- name: web
image: nginx:1.23
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 10
periodSeconds: 10
- name: log-collector
image: fluent/fluent-bit:1.8
args:
- "-i"
- "tail"
- "-p"
- "path=/var/log/nginx/access.log"
- "-o"
- "stdout"
volumeMounts:
- name: web-logs
mountPath: /var/log/nginx
# Pod 내 컨테이너들이 공유하는 볼륨
volumes:
- name: web-logs
emptyDir: {}
# Pod 생성
kubectl apply -f example-pod.yaml
# Pod 확인
kubectl get pods --all-namespaces
kubectl describe pod my-nginx-pod
# Pod 컨테이너 내부 명령 실행
kubectl exec -it my-nginx-pod -c nginx -- bash
# Pod 삭제
kubectl delete pod my-nginx-pod