Information in this document may be out of date
This document has an older update date than the original, so the information it contains may be out of date. If you're able to read English, see the English version for the most up-to-date information: Configure Pod Initialization
์ด๊ธฐํ ์ปจํ ์ด๋์ ๋ํ ๊ตฌ์ฑ
์ด ํ์ด์ง๋ ์ ํ๋ฆฌ์ผ์ด์ ์คํ ์ ์ ํ๋๋ฅผ ์ด๊ธฐํํ๊ธฐ ์ํด ์ด๋ป๊ฒ ์ด๊ธฐํ ์ปจํ ์ด๋๋ฅผ ๊ตฌ์ฑํด์ผ ํ๋์ง ๋ณด์ฌ์ค๋ค.
์์ํ๊ธฐ ์ ์
์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ๊ฐ ํ์ํ๊ณ , kubectl ์ปค๋งจ๋-๋ผ์ธ ํด์ด ํด๋ฌ์คํฐ์ ํต์ ํ ์ ์๋๋ก ์ค์ ๋์ด ์์ด์ผ ํ๋ค. ์ด ํํ ๋ฆฌ์ผ์ ์ปจํธ๋กค ํ๋ ์ธ ํธ์คํธ๊ฐ ์๋ ๋ ธ๋๊ฐ ์ ์ด๋ 2๊ฐ ํฌํจ๋ ํด๋ฌ์คํฐ์์ ์คํํ๋ ๊ฒ์ ์ถ์ฒํ๋ค. ๋ง์ฝ, ์์ง ํด๋ฌ์คํฐ๋ฅผ ๊ฐ์ง๊ณ ์์ง ์๋ค๋ฉด, minikube๋ฅผ ์ฌ์ฉํด์ ์์ฑํ๊ฑฐ๋ ๋ค์ ์ฟ ๋ฒ๋คํฐ์ค ํ๋ ์ด๊ทธ๋ผ์ด๋ ์ค ํ๋๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
๋ฒ์ ํ์ธ์ ์ํด์, ๋ค์ ์ปค๋งจ๋๋ฅผ ์คํ kubectl version
.
์ด๊ธฐํ ์ปจํ ์ด๋๋ฅผ ๊ฐ๋ ํ๋ ์์ฑ
์ด ์ฐ์ต์์ ํ๋์ ์ ํ๋ฆฌ์ผ์ด์ ์ปจํ ์ด๋์ ํ๋์ ์ด๊ธฐํ ์ปจํ ์ด๋๋ฅผ ๊ฐ๋ ํ๋๋ฅผ ์์ฑํ๋ค. ์ด๊ธฐํ ์ปจํ ์ด๋๋ ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ ์ ์คํ์ ์ข ๋ฃํ๋ค.
์๋๋ ํด๋น ํ๋์ ๊ตฌ์ฑ ํ์ผ์ด๋ค.
apiVersion: v1
kind: Pod
metadata:
name: init-demo
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: workdir
mountPath: /usr/share/nginx/html
# ์ด ์ปจํ
์ด๋๋ค์ ํ๋ ์ด๊ธฐํ ์ค์ ์คํ๋๋ค.
initContainers:
- name: install
image: busybox:1.28
command:
- wget
- "-O"
- "/work-dir/index.html"
- http://info.cern.ch
volumeMounts:
- name: workdir
mountPath: "/work-dir"
dnsPolicy: Default
volumes:
- name: workdir
emptyDir: {}
์ด ๊ตฌ์ฑ ํ์ผ์์, ํ๋๊ฐ ๊ฐ์ง ๋ณผ๋ฅจ์ ์ด๊ธฐํ ์ปจํ ์ด๋์ ์ ํ๋ฆฌ์ผ์ด์ ์ปจํ ์ด๋๊ฐ ๊ณต์ ํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
์ด๊ธฐํ ์ปจํ
์ด๋๋ ๊ณต์ ๋ ๋ณผ๋ฅจ์
/work-dir
์ ๋ง์ดํธํ๊ณ , ์ ํ๋ฆฌ์ผ์ด์
์ปจํ
์ด๋๋ ๊ณต์ ๋ ๋ณผ๋ฅจ์
/usr/share/nginx/html
์ ๋ง์ดํธํ๋ค. ์ด๊ธฐํ ์ปจํ
์ด๋๋ ๋ค์ ๋ช
๋ น์ ์คํ ํ
์ข
๋ฃํ๋ค.
wget -O /work-dir/index.html http://info.cern.ch
์ด๊ธฐํ ์ปจํ
์ด๋๋ nginx ์๋ฒ์ ๋ฃจํธ ๋๋ ํฐ๋ฆฌ ๋ด index.html
ํ์ผ์
์ ์ฅํ๋ค.
ํ๋๋ฅผ ์์ฑํ๋ค.
kubectl apply -f https://k8s.io/examples/pods/init-containers.yaml
nginx ์ปจํ ์ด๋๊ฐ ์คํ ์ค์ธ์ง ํ์ธํ๋ค.
kubectl get pod init-demo
์ถ๋ ฅ ๊ฒฐ๊ณผ๋ nginx ์ปจํ ์ด๋๊ฐ ์คํ ์ค์์ ๋ณด์ฌ์ค๋ค.
NAME READY STATUS RESTARTS AGE
init-demo 1/1 Running 0 1m
init-demo ํ๋ ๋ด ์คํ ์ค์ธ nginx ์ปจํ ์ด๋์ ์ ธ์ ์คํํ๋ค.
kubectl exec -it init-demo -- /bin/bash
์ ธ์์ GET ์์ฒญ์ nginx ์๋ฒ๋ก ์ ์กํ๋ค.
root@nginx:~# apt-get update
root@nginx:~# apt-get install curl
root@nginx:~# curl localhost
์ถ๋ ฅ ๊ฒฐ๊ณผ๋ nginx๊ฐ ์ด๊ธฐํ ์ปจํ ์ด๋์ ์ํด ์ ์ฅ๋ ์น ํ์ด์ง๋ฅผ ์ ๊ณตํ๊ณ ์์์ ๋ณด์ฌ์ค๋ค.
<html><head></head><body><header>
<title>http://info.cern.ch</title>
</header>
<h1>http://info.cern.ch - home of the first website</h1>
...
<li><a href="http://info.cern.ch/hypertext/WWW/TheProject.html">Browse the first website</a></li>
...
๋ค์ ๋ด์ฉ
- ๊ฐ์ ํ๋ ๋ด ์คํ ์ค์ธ ์ปจํ ์ด๋๋ค๊ฐ ํต์ ์ ๋ํด ๋ฐฐ์ฐ๊ธฐ.
- ์ด๊ธฐํ ์ปจํ ์ด๋์ ๋ํด ๋ฐฐ์ฐ๊ธฐ.
- ๋ณผ๋ฅจ์ ๋ํด ๋ฐฐ์ฐ๊ธฐ.
- ์ด๊ธฐํ ์ปจํ ์ด๋ ๋๋ฒ๊น ์ ๋ํด ๋ฐฐ์ฐ๊ธฐ.