DevOps/K8S

[k8s] Pod

kyoulho 2024. 8. 29. 19:50

Pod는 Kubernetes에서 가장 기본적인 배포 단위로, 하나 이상의 컨테이너를 포함할 수 있다. 같은 Pod에 있는 컨테이너들은 동일한 네트워크와 저장소를 공유한다.

 

예제

다음은 Kubernetes에서 nginx라는 이름의 Pod를 생성하고, 상태를 확인하며, 컨테이너에 접근하는 과정이다

Pod 생성

nginx라는 이름의 Pod가 nginx 이미지를 사용하여 생성된다.

$ k run nginx --image=nginx
pod/nginx created

Pod 상태 확인

Pod가 생성되었지만 아직 컨테이너가 준비되지 않았다. ContainerCreating 상태는 컨테이너가 생성되는 중임을 나타낸다.

$ k get pod
NAME    READY   STATUS              RESTARTS   AGE
nginx   0/1     ContainerCreating   0          8s

Pod의 IP 확인

Pod의 IP 주소가 172.16.103.130으로 할당되었으며, Running 상태로 확인된다.

$ k get pod -o wide
NAME    READY   STATUS    RESTARTS   AGE   IP               NODE     NOMINATED NODE   READINESS GATES
nginx   1/1     Running   0          90s   172.16.103.130   w2-k8s   <none>           <none>

Pod에 접속

curl 명령어를 통해 nginx 웹 서버의 기본 페이지에 접근할 수 있다. 이는 nginx 컨테이너가 정상적으로 실행되고 있음을 의미한다.

$ curl 172.16.103.130
<!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>

'DevOps > K8S' 카테고리의 다른 글

[k8s] 클러스터의 주요 구성 요소와 문제 발생 시 영향  (2) 2024.08.29
[k8s] Deployment  (0) 2024.08.29
[k8s] NodePort  (0) 2024.08.29
[k8s] Namespace  (0) 2024.08.28
[k8s] Service  (0) 2024.08.28