1 분 소요

Pod

pod란?

컨테이너를 표현하는 K8S API의 최소 단위

Pod에는 하나 또는 여러 개의 컨테이너가 포함될 수 있다.

Pod 생성과정

pod_creating

  1. Scheduler는 API서버를 감시하면서 할당되지 않은unassigned Pod이 있는지 체크
  2. Scheduler는 할당되지 않은 Pod을 감지하고 적절한 노드node에 할당 (minikube는 단일 노드)
  3. 노드에 설치된 kubelet은 자신의 노드에 할당된 Pod이 있는지 체크
  4. kubeletScheduler에 의해 자신에게 할당된 Pod의 정보를 확인하고 컨테이너 생성
  5. kubelet은 자신에게 할당된 Pod의 상태를 API 서버에 전달

Pod 생성하기

  • run 명령어를 이용해 생성
    • $ kubectl run {pod명} --image={이미지명}
$ kubectl run webserver --image=nginx:1.14
  • pod yaml을 이용해 생성
$ kubectl create -f pod-nginx.yaml
# pod-nginx.yaml

apiVersion: apps/v1
kind: Pod
metadata:
  name: webserver
spec:
  containers:
  - name: nginx-container
    image: nginx:1.14
    imagePullPolicy: Always
    ports:
    - containerPort: 80
      protocol: TCP

동작중인 Pod 확인

$ kubectl get pods
$ kubectl get pods -o wide
$ kubectl get pods -o yaml
$ kubectl get pods -o json
$ kubectl get pods webserver -o json | grep -i podip

# 접속해서 결과보기
$ curl {pod's IP address}

multi-container pod 생성하기

  • pod yaml을 이용해 생성
$ kubectl create -f pod-multi.yaml
# pod-multi.yaml

apiVersion: apps/v1
kind: Pod
metadata:
  name: multipod
spec:
  containers:
  - name: nginx-container
    image: nginx:1.14
    ports:
    - containerPort: 80
      protocol: TCP
  - name: centos-container
    image: cetos:7
    command:
    - sleep
    - "10000"
  • multipod 안에 있는 container들은 동일한 ip를 공유한다.
# centos-container 쉘 접속하여
$ kubectl exec multipod -it -c centos-container -- /bin/bash

# localhost 80 port로 접속하면 -> 같은 pod의 nginx web server로 접속된다.
$ curl http://localhost:80

# nginx container의 log를 확인
$ kubectl logs multipod -c nginx-container
# single-container 구성의 pod라면 pod이름만 쓰면 조회 가능
# ex) kubectl logs test01

환경변수 설정

# pod-nginx-env.yaml

apiVersion: apps/v1
kind: Pod
metadata:
  name: webserver
spec:
  containers:
  - name: nginx-container
    image: nginx:1.14
    imagePullPolicy: Always
    ports:
    - containerPort: 80
      protocol: TCP
    env:
    - name: MYVAR
      value: "testvalue"
$ kubectl create -f pod-nginx-env.yaml

$ kubectl exec -it nginx-pod-env -- /bin/bash

# env

MYVAR=testvalue

댓글남기기