반응형

 

 

 

 

 

 

파드안에 두개이상 컨테이너 생성 및 확인

YAML파일안에 sleep 5초를 준 이유는 Pod 안에 컨테이너가 동시에 시작되면 nginx 컨테이너에 오류가 발생할 수 있기에 mynginx 컨테이너 먼저 러닝상태가 되면 jinsunginx 컨테이너가 동작할 수 있게 옵션을 준 것입니다.

# 파드안에 두개의 컨테이너 생성하는 YAML파일 생성
master@master:~$ cat two-container.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: mynginx
spec:
  containers: 
  - name: mynginx
    image: nginx
  - name: jinsunginx
    image: curlimages/curl
    command: ["sh"]
    args: 
    - "-c"
    - "sleep 5 && curl localhost"
master@master:~$ 

master@master:~$ kubectl apply -f two-container.yaml 
pod/mynginx created
master@master:~$ 

master@master:~$ kubectl get pod
NAME      READY   STATUS    RESTARTS   AGE
mynginx   1/2     Running   0          18s
master@master:~$

# 그냥 pod의 logs를 조회하면 컨테이너를 선택하라는 문구가 나온다.
master@master:~$ kubectl logs mynginx 
error: a container name must be specified for pod mynginx, choose one of: [mynginx jinsunginx]

# 두개의 컨테이너가 있을떄는 -c 옵션을 사용한다.
master@master:~$ kubectl logs mynginx -c mynginx 
/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: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: 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: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/08/09 12:59:15 [notice] 1#1: using the "epoll" event method
2022/08/09 12:59:15 [notice] 1#1: nginx/1.23.1
2022/08/09 12:59:15 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
2022/08/09 12:59:15 [notice] 1#1: OS: Linux 4.15.0-189-generic
2022/08/09 12:59:15 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/08/09 12:59:15 [notice] 1#1: start worker processes
2022/08/09 12:59:15 [notice] 1#1: start worker process 32
2022/08/09 12:59:15 [notice] 1#1: start worker process 33
2022/08/09 12:59:15 [notice] 1#1: start worker process 34
2022/08/09 12:59:15 [notice] 1#1: start worker process 35
127.0.0.1 - - [09/Aug/2022:12:59:28 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.84.0-DEV" "-"
127.0.0.1 - - [09/Aug/2022:12:59:36 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.84.0-DEV" "-"
127.0.0.1 - - [09/Aug/2022:12:59:58 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.84.0-DEV" "-"
master@master:~$

master@master:~$ kubectl logs mynginx 
error: a container name must be specified for pod mynginx, choose one of: [mynginx jinsunginx]
master@master:~$ kubectl logs mynginx -c jinsunginx 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   615  100   615    0     0  1002k      0 --:--:-- --:--:-- --:--:--  600k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
master@master:~$

 

 

 

참고자료

https://kubernetes.io/ko/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/

 

반응형

+ Recent posts