실습 :: multi-pod
2개 이상의 container를 포함한 파드
[root@master ~/kube/06/multi-pod]# vi multi-pod.yaml
[root@master ~/kube/06/multi-pod]# cat multi-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: multipod
spec:
containers:
- name: nginx-container
image: nginx
ports:
- containerPort: 80
protocol: TCP
- name: ubuntu-container
image: ubuntu
command:
- sleep
- "86400"
[root@master ~/kube/06/multi-pod]# kubectl apply -f multi-pod.yaml
pod/multipod created
[root@master ~/kube/06/multi-pod]# kubectl get pod
NAME READY STATUS RESTARTS AGE
multipod 0/2 ContainerCreating 0 4s
[root@master ~/kube/06/multi-pod]# kubectl describe pod multipod
Name: multipod
Namespace: default
Priority: 0
Service Account: default
Node: node2/192.168.2.62
Start Time: Sat, 08 Mar 2025 16:15:36 +0900
Labels: <none>
Annotations: cni.projectcalico.org/containerID: 38247f2fbe3b0fdba808f44308205f4cd30ce8726160cd53e4b89f014f7ac4b6
cni.projectcalico.org/podIP: 10.233.75.7/32
cni.projectcalico.org/podIPs: 10.233.75.7/32
Status: Running
IP: 10.233.75.7
IPs:
IP: 10.233.75.7
Containers:
nginx-container:
Container ID: docker://d65c313f9bfee517dc7f7a87cdebc30e167a318abc307e0022409db6b4173689
Image: nginx
Image ID: docker-pullable://nginx@sha256:9d6b58feebd2dbd3c56ab5853333d627cc6e281011cfd6050fa4bcf2072c9496
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Sat, 08 Mar 2025 16:15:39 +0900
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-4zxjb (ro)
ubuntu-container:
Container ID: docker://f77cb89221c15a9c8e7331aabe26681a3f8239299b48a598d52f4fca82f74451
Image: ubuntu
Image ID: docker-pullable://ubuntu@sha256:72297848456d5d37d1262630108ab308d3e9ec7ed1c3286a32fe09856619a782
Port: <none>
Host Port: <none>
Command:
sleep
86400
State: Running
Started: Sat, 08 Mar 2025 16:15:46 +0900
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-4zxjb (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-4zxjb:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 17s default-scheduler Successfully assigned default/multipod to node2
Normal Pulling 17s kubelet Pulling image "nginx"
Normal Pulled 14s kubelet Successfully pulled image "nginx" in 2.265592064s (2.265617119s including waiting)
Normal Created 14s kubelet Created container nginx-container
Normal Started 14s kubelet Started container nginx-container
Normal Pulling 14s kubelet Pulling image "ubuntu"
Normal Pulled 7s kubelet Successfully pulled image "ubuntu" in 7.611666372s (7.611671619s including waiting)
Normal Created 7s kubelet Created container ubuntu-container
Normal Started 6s kubelet Started container ubuntu-container
[root@master ~/kube/06/multi-pod]# kubectl get pod
NAME READY STATUS RESTARTS AGE
multipod 2/2 Running 0 22s
nginx container 확인 및 test
[root@master ~/kube/06/multi-pod]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
multipod 2/2 Running 0 4m29s 10.233.75.7 node2 <none> <none>
[root@master ~/kube/06/multi-pod]# curl <http://10.233.75.7>
<!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>
[root@master ~/kube/06/multi-pod]# kubectl exec multipod -it -c nginx-container -it -- bash
root@multipod:/# cd /usr/share/nginx/html/
root@multipod:/usr/share/nginx/html# ls
50x.html index.html
root@multipod:/usr/share/nginx/html# echo "Nginx Test Web Page" > index.html
root@multipod:/usr/share/nginx/html# cat index.html
Nginx Test Web Page
root@multipod:/usr/share/nginx/html# exit
exit
[root@master ~/kube/06/multi-pod]# curl <http://10.233.75.7>
Nginx Test Web Page
ubuntu container 확인 및 test
[root@master ~/kube/06/multi-pod]# kubectl exec multipod -it -c ubuntu-container -- bash
root@multipod:/# apt-get update
Get:1 <http://archive.ubuntu.com/ubuntu> noble InRelease [256 kB]
Get:2 <http://security.ubuntu.com/ubuntu> noble-security InRelease [126 kB]
Get:3 <http://archive.ubuntu.com/ubuntu> noble-updates InRelease [126 kB]
Get:4 <http://archive.ubuntu.com/ubuntu> noble-backports InRelease [126 kB]
Get:5 <http://security.ubuntu.com/ubuntu> noble-security/main amd64 Packages [841 kB]
Get:6 <http://archive.ubuntu.com/ubuntu> noble/universe amd64 Packages [19.3 MB]
Get:7 <http://security.ubuntu.com/ubuntu> noble-security/restricted amd64 Packages [909 kB]
Get:8 <http://security.ubuntu.com/ubuntu> noble-security/multiverse amd64 Packages [34.0 kB]
Get:9 <http://security.ubuntu.com/ubuntu> noble-security/universe amd64 Packages [1062 kB]
Get:10 <http://archive.ubuntu.com/ubuntu> noble/multiverse amd64 Packages [331 kB]
Get:11 <http://archive.ubuntu.com/ubuntu> noble/restricted amd64 Packages [117 kB]
Get:12 <http://archive.ubuntu.com/ubuntu> noble/main amd64 Packages [1808 kB]
Get:13 <http://archive.ubuntu.com/ubuntu> noble-updates/main amd64 Packages [1163 kB]
Get:14 <http://archive.ubuntu.com/ubuntu> noble-updates/restricted amd64 Packages [955 kB]
Get:15 <http://archive.ubuntu.com/ubuntu> noble-updates/universe amd64 Packages [1345 kB]
Get:16 <http://archive.ubuntu.com/ubuntu> noble-updates/multiverse amd64 Packages [38.7 kB]
Get:17 <http://archive.ubuntu.com/ubuntu> noble-backports/universe amd64 Packages [16.0 kB]
Fetched 28.6 MB in 6s (5074 kB/s)
Reading package lists... Done
root@multipod:/# apt-get install -y net-tools
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
net-tools
0 upgraded, 1 newly installed, 0 to remove and 18 not upgraded.
Need to get 204 kB of archives.
After this operation, 811 kB of additional disk space will be used.
Get:1 <http://archive.ubuntu.com/ubuntu> noble/main amd64 net-tools amd64 2.10-0.1ubuntu4 [204 kB]
Fetched 204 kB in 1s (179 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package net-tools.
(Reading database ... 4383 files and directories currently installed.)
Preparing to unpack .../net-tools_2.10-0.1ubuntu4_amd64.deb ...
Unpacking net-tools (2.10-0.1ubuntu4) ...
Setting up net-tools (2.10-0.1ubuntu4) ...
root@multipod:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
inet 10.233.75.7 netmask 255.255.255.255 broadcast 0.0.0.0
inet6 fe80::806b:3aff:fe66:24ab prefixlen 64 scopeid 0x20<link>
ether 82:6b:3a:66:24:ab txqueuelen 0 (Ethernet)
RX packets 39509 bytes 30522938 (30.5 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8787 bytes 481071 (481.0 KB)
TX errors 0 dropped 1 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
▶ pod의 ip와 동일한 것을 확인할 수 있음 :: container는 따로 ip를 갖지 않고 pod의 ip를 공유
root@multipod:/# apt-get install -y curl
root@multipod:/# curl <http://127.0.0.1>
Nginx Test Web Page
root@multipod:/# exit
[root@master ~/kube/06/multi-pod]# kubectl exec -it multipod -c nginx-container -- bash
root@multipod:/# apt-get update
root@multipod:/# apt-get install -y net-tools
root@multipod:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
inet 10.233.75.7 netmask 255.255.255.255 broadcast 0.0.0.0
inet6 fe80::806b:3aff:fe66:24ab prefixlen 64 scopeid 0x20<link>
ether 82:6b:3a:66:24:ab txqueuelen 0 (Ethernet)
RX packets 60104 bytes 46501347 (44.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14361 bytes 787748 (769.2 KiB)
TX errors 0 dropped 1 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 12 bytes 968 (968.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 968 (968.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@multipod:/# exit
▶ nginx도 마찬가지로 확인 가능
[root@master ~/kube/06/multi-pod]# kubectl delete pod multipod
pod "multipod" deleted