이번엔 Multi Container 개념에 대해 정리하고자 한다.
1. 정의
- Kubernetes Pod 안에 배치된 여러 개의 컨테이너
> 이 컨테이너들은 같은 네트워크 / 같은 스토리지 / 동일한 생명주기를 공유하며 서로 강하게 결합된 기능을 수행할 때 사용
2. 대표적인 Multi-Container 구성 요소
- Main Container
> 실제 애플리케이션이 동작하는 핵심 컨테이너
- Sidecar Container
> 보조 작업 수행 (로그 수집, 캐싱, 통신 등)
- Init Container (선 실행)
> Pod 시작 전에 반드시 실행되어야 하는 초기 설정 작업 수행
3. 관련 문제 (KodeKloud 에서 제공하는 샘플 문제를 정리)
- Create a multi-container pod named yellow that includes 2 containers as specified below:
> Container 1 - Name: lemon / Image: busybox
> Container 2 - Name: gold / Image: redis
> If the pod encounters a crashloopbackoff status, modify the lemon container to include the command sleep 1000.
vi yellow.yaml
apiVersion: v1
kind: Pod
metadata:
name: yellow
spec:
containers:
- name: lemon
image: busybox
command:
- sleep
- "1000"
- name: gold
image: redis
kubectl apply -f yellow.yaml
- Inspect the app pod and identify the number of containers in it.
kubectl describe pod app
- The application outputs logs to the file /log/app.log. View the logs and try to identify the user having issues with Login.
kubectl -n elastic-stack exec -it app -- cat /log/app.log
- Edit the app pod in the elastic-stack namespace to add a sidecar container named sidecar to send logs to Elastic Search. Mount the log volume to the sidecar container at path /var/log/event-simulator/.
vi app.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
name: app
name: app
namespace: elastic-stack
spec:
initContainers:
- name: sidecar
image: kodekloud/filebeat-configured
restartPolicy: Always
volumeMounts:
- name: log-volume
mountPath: /var/log/event-simulator
containers:
- image: kodekloud/event-simulator
name: app
resources: {}
volumeMounts:
- mountPath: /log
name: log-volume
volumes:
- hostPath:
path: /var/log/webapp
type: DirectoryOrCreate
name: log-volume
kubectl delete pod app -n elastic-stack
kubectl apply -f app.yaml
4. 출처
'IT > Kubernetes' 카테고리의 다른 글
| [CKA] Namespace 란? (0) | 2025.11.24 |
|---|---|
| [CKA] HPA(Horizontal Pod Autoscaler) 란? (0) | 2025.11.24 |
| [CKA] Service 란? (0) | 2025.11.24 |
| [CKA] NetworkPolicy 란? (0) | 2025.11.22 |
| [CKA] PV(PersistentVolume) 란? (0) | 2025.11.22 |