ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Kubernetes) Kubernetes Pod
    Cloud/Kubernetes 2022. 10. 13. 22:20
    학습 목표 : k8s의 pod 특징과 생명주기, 생성방법을 알아본다.

    Pod 란?

    • Pod는 kubernetes에서 하나의 독립적인 서비스를 제공할 수 있는 container 들을 모아서 관리하는 최소 배포단위다.
    • Pod 단위로 container의 작성, 시작, 정지, 삭제 등과 같은 조작을 수행한다.


    Pod 의 특징

    • 동일한 Pod의 container는 반드시 동일한 node상에서 동시에 deploy된다.
    • Pod 안에서 container의 Port는 중복될 수 없다.
    • Pod안의 여러 container에서 가상 NIC(Private IP)를 공유하는 구성을 취하기 때문에 container 끼리 localhost를 경유하여 통신할 수 있다.
    • Pod가 생성될 때 고유 IP가 할당되며 cluster 내에서만 접근할 수 있다.


    Pod 의 구성

    • 1개 이상의 container를 가지고있다.
    • Volume - Pod 내의 container간에 데이터를 공유한다.
    • 단일 container Pod - Pod당 하나의 container 모델로 가장 일반적인 형태
    • 다중 container Pod - Pod에 밀접한 연관성을 갖고있는 container를 배치하여 연관성있는 container간에 리소스를 공유하는 형태의 캡슐화되 모델이다.


    Pod 의 생성주기

    • Pod의 생성주기는 다음명령으로 확인할 수 있다.
    kubectl describe pods
    kubectl describe pod/<Pod 이름>
    • Pod Status

    설명
    Pending Pod 생성을 기다리는 상태, container image 다운로드 등 시간이 걸리는 경우 발생한다.
    Running Pod 정상 작동중인 상태
    Succeeded Pod 안의 container가 정상적으로 종료된 상태
    Failed Pod 안의 container 중 하나의 container가 실패하여 종료된 상태
    Unknown 어떤 이유로 Pod와 통신할 수 없는 상태
    • Pod Conditions
    Type 설명
    Initialized container가 성공적으로 시작한 상태
    Ready Pod가 요청을 실행하고, 모든 서비스의 Load Balancing pool에 추가될수 있는 상태
    ContainersReady Pod안의 모든 container가 준비된 상태
    PodScheduled Pod가 하나의 node로 schedule을 완료한 상태
    Unschedulabe schedule의 자원 부족이나 다른제약 등으로 Pod를 schedule 할 수 없는 상태


    Pod 명령어

    (1)  container Pod 생성하기 (run/apply)
        -  Docker에서 container 생성하는 방법과 같은 방식
    # 1. run - 단일 container Pod 생성 명령어
    kubectl run <pod 이름> --image=<container image이름:버전> --port=<port 번호>
    
    # 2. run - default namespace에 Pod 생성 예
    kubectl run webserver --image=nginx --port=80
    
    # 3. run - 사용자지정 namespace에 Pod 생성 예
    kubectl run webserver --image=nginx --port=80 --namespace myspace
    
    # 4. apply - 단일 container Pod 생성 명령어 예
    kubectl apply -f exam-nginx.yml
    
    # 5. apply - 다중 container 생성
    kubectl apply -f multi-container.yml

        -  exam-nginx.yml 파일

    apiVersion: v1
    kind: Pod
    metadata:
     name: webserver
     labels:
       app: myweb
    spec:
     containers:
     - name: nginx-container
       image: nginx:latest
       ports:
       - containerPort: 80

        -  multi-container.yml 파일

    apiVersion: v1
    kind: Pod
    metadata:
     name: kubetm
    spec:
     containers:
     - name: container1
       image: kubetm/p8000
       ports:
       - containerPort: 8000
     - name: container2
       image: kubetm/p8080
       ports:
       - containerPort: 8080


    (2)  Pod 목록 확인하기 (get/describe)

    # 1. get - default namespace Pod 목록 확인
    kubectl get pods -o wide
    
    # 2. get - 모든 namespace의 Pod 목록 확인
    kubectl get pods -o wide --all-namespaces 
    
    # 3. get - 사용자지정 namespace Pod 목록 확인 예
    kubectl get pods -o wide --namespace myspace
    
    # 4. describe - 사용자지정 namespace의 특정 Pod의 상세 정보 확인 예
    kubectl describe pod/webserver --namespace myspace


    (3)  Pod에 명령 수행하기 (exec)

    # 1. Pod에 명령 수행
    kubectl exec <pod 이름> -it -- <명령>
    
    # 2. Pod에 명령 수행 예
    kubectl exec webserver -it -- /bin/bash


    (4)  Pod 삭제하기  (delete)

    # 1. Pod만 삭제하기 예
    kubectl delete pod/webserver1 pod/webserver2
    
    # 2. Pod와 Namespace 삭제하기 예
    kubectl delete pod/webserver --namespace myspace



    댓글

Designed by Tistory.