본문 바로가기
IT/Kubernetes

[Kubernetes] Workload - Pods

by 깅지수 2022. 5. 17.

* k8s에서 관리할 수 있는 가장 작은 workload = Pod ( : container의 모음)

 

 

 

파드 생성 및 관리

 

명령형 커맨드로 파드 생성

kubectl run <POD_NAME> --image <IMAGE>
kubectl run myweb --image httpd


파드 목록 확인

kubectl get pods
kubectl get pods <POD_NAME>


파드 상세 정보 (-o : --output)

kubectl get pods -o wide
kubectl get pods -o yaml
kubectl get pods -o json
kubectl describe pods <POD_NAME>
#Events : (만든 Application에 대한 log가 아닌) 리소스 자체에 대한 event log


애플리케이션 로그

kubectl logs <POD_NAME>


파드 삭제

kubectl delete pods myweb

 

 


 

YAML 파일로 Pod 정의

 

myweb.yaml

apiVersion: v1
kind: Pod 
metadata:
  name: myweb
spec:
  containers:
    - name: myweb
      image: httpd
      ports:
        - containerPort: 80
          protocol: TCP

 

 kubectl explain pods

kubectl create -f myweb.yaml
kubectl get -f myweb.yaml
kubectl describe -f myweb.yaml
kubectl delete -f myweb.yaml

 

 

kubectl 명령의 서브 명령어

  • create
  • get
  • describe
  • logs
  • delete
  • replace
  • patch
  • apply
  • diff

 

파드 디자인

pod에 container 2개 (main : web server, helper : file puller)

 

- 단일 컨테이너: 일반 적인 형태 (하나의 pod에 하나의 container)
멀티 컨테이너: 메인 애플리케이션이 존재 매인 애플리케이션 기능을 확장 하기 위한 컨테이너를 배치

                     (하나의 pod에 여러개의 containers 단, container끼리는 밀접한 관계여야함)

 

** 하나의 Pod에는 반드시 하나의 Main App(Container)이 존재해야 함. 이를 도와주는 (ex. web contents를 가져와서 main에 제공해주는) container만 공존 가능

 

*** Pod는 pod에 속한 container에 network와 volume을 공유 & 하나의 IP만 부여됨


- 사이드카(helper) 패턴
* 참고 : https://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns/

 

The Distributed System ToolKit: Patterns for Composite Containers

Having had the privilege of presenting some ideas from Kubernetes at DockerCon 2015, I thought I would make a blog post to share some of these ideas for those of you who couldn’t be there. Over the past two years containers have become an increasingly po

kubernetes.io

- sidecar: 기능의 확장
- ambassador: 프록시/LB
- adpator: 출력의 표준

 

 

포트 및 포트 포워딩

 

테스트 & 디버깅 목적

kubectl port-forward pods/myweb 8080:80




이름 & UID

이름 : 네임스페이스 유일
UID : 클러스터에서 유일