파드(pod)

컨테이너 애플리케이션의 기본 단위

1개 이상의 컨테이너로 구성된 컨테이너의 집합

여러 개의 컨테이너를 추상화해서 하나의 애플리케이션으로 동작하도록 묶어 놓은 컨테이너의 묶음

nginx 컨테이너로 구성된 파드를 생성

nginx-pod.yml

apiVersion: v1
kind: Pod
metadata:
  name: my-nginx-container
spec:
  containers:
  - name: my-nginx-container
    image: nginx:latest
    ports:
    - containerPort: 80
      protocol: TCP
# YAML 파일에서 정의한 오브젝트의 API 버전
# 리소스의 종류
# 라벨, 주석, 이름과 같은 리소스의 부가 정보

# 컨테이너 리소스 생성을 위한 정보

파드 생성

kubectl apply -f <YML_FILE_NAME>

# 새로운 파드 생성
vagrant@ubuntu:~/kub01$ kubectl apply -f nginx-pod.yml
pod/my-nginx-container created

모든 파드 확인

kubectl get pods

# 파드 확인
vagrant@ubuntu:~/kub01$ kubectl get pods
NAME                 READY   STATUS    RESTARTS   AGE
my-nginx-container   1/1     Running   0          63s

# 축약어를 사용할 수 있다
vagrant@ubuntu:~/kub01$ kubectl get po
NAME                 READY   STATUS    RESTARTS   AGE
my-nginx-container   1/1     Running   0          68s

상세 정보 조회

kubectl describe pods <POD_NAME>

# 생성된 리소스의 자세한 정보 확인
vagrant@ubuntu:~/kub01$ kubectl describe pods my-nginx-container
Name:         my-nginx-container
Namespace:    default
Priority:     0
Node:         minikube/172.17.0.3
Start Time:   Fri, 18 Sep 2020 06:39:13 +0000
Labels:       <none>
Annotations:  <none>
Status:       Running
IP:           172.18.0.3
IPs:
  IP:  172.18.0.3
Containers:
  my-nginx-container:
# <이하생략>

파드 컨테이너 생성과 확인 실습

# 클러스터 내부에 테스트를 위한 임시 파드를 생성
# alicek106/ubuntu:curl 이미지를 이용해서 debug 이름의 파드를 생성
vagrant@ubuntu:~/kub01$ kubectl run -it --rm debug --image=alicek106/ubuntu:curl --restart=Never bash
If you don't see a command prompt, try pressing enter.
root@debug:/#
# debug 파드가 생성 된 상태에서 파드 조회
vagrant@ubuntu:~/kub01$ kubectl get pod
NAME                 READY   STATUS    RESTARTS   AGE
debug                1/1     Running   0          73s
my-nginx-container   1/1     Running   0          8m36s

# nginx 파드의 동작을 확인 (172.18.0.3)
root@debug:/# curl 172.18.0.3
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
# <이하생략>

kubectl exec 명령으로 파드의 컨테이너에 명령을 전달

kubectl exec -it <POD_NAME> -- <COMAND>

vagrant@ubuntu:~/kub01$ kubectl exec -it my-nginx-container -- bash
root@my-nginx-container:/# whoami
root
root@my-nginx-container:/# exit
exit

kubectl logs 명령으로 파드 로그 확인

kubectl log <POD_NAME>

vagrant@ubuntu:~/kub01$ kubectl logs my-nginx-container
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
172.18.0.4 - - [18/Sep/2020:06:48:42 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.35.0" "-"

쿠버네티스 오브젝트를 YAML을 이용해 삭제

kubectl delete -f <YAML_FILE_NAME>

vagrant@ubuntu:~/kub01$ kubectl delete -f nginx-pod.yml
pod "my-nginx-container" deleted

# 모든 pod 조회
vagrant@ubuntu:~/kub01$ kubectl get pods
No resources found in default namespace.
vagrant@ubuntu:~/kub01$

1개의 pod안에 여러개의 컨테이너가 있는 경우 실습

nginx-pod-with-ubuntu.yml

apiVersion: v1
kind: Pod
metadata:
  name: my-nginx-pod
spec:
  containers:
- name: my-nginx-container
    image: nginx:latest
    ports:
    - containerPort: 80
      protocol: TCP

  - name: ubuntu-sidecar-container
    image: alicek106/rr-test:curl
    command: [ "tail" ]
    args: [ "-f", "/dev/null" ]

pod 생성

vagrant@ubuntu:~/kub01$ kubectl apply -f nginx-pod-with-ubuntu.yml
pod/my-nginx-pod created
vagrant@ubuntu:~/kub01$ kubectl get pods
NAME           READY   STATUS    RESTARTS   AGE
my-nginx-pod   2/2     Running   0          20s
  • pod로 명령어를 전달할 때 실행할 컨테이너를 지정 안하면 default 설정 컨테이너가 실행됨
vagrant@ubuntu:~/kub01$ kubectl exec -it my-nginx-pod -- bash
Defaulting container name to my-nginx-container.
Use 'kubectl describe pod/my-nginx-pod -n default' to see all of the containers in this pod.
root@my-nginx-pod:/# exit
exit
  • 특정 컨테이너에게 명령어를 전달 할 때는 -c 옵션을 사용한다.
vagrant@ubuntu:~/kub01$ kubectl exec -it my-nginx-pod -c ubuntu-sidecar-container -- bash
root@my-nginx-pod:/#

root@my-nginx-pod:/# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>

# 이 실습으로 알 수 있는점: 하나의 Pod 내에서는 네트워크 네임스페이스를 공유하는것을 알 수 있다.

 

반응형

+ Recent posts