ํ ํฌ๋์ ์ปจํ ์ด๋๋ฅผ ์ฌ๋ฌ๊ฐ ์คํํ ๊ฒฝ์ฐ ๋คํธ์ํฌ ์ธํฐํ์ด์ค, IPC, ๋ณผ๋ฅจ ๋ฑ์ ๊ณต์ ๊ฐ๋ฅํจ.
- ์ง์ญ์ฑ ๋ณด์ฅ
- ๋ฆฌ์์ค ๋ชจ๋ํฐ๋ง ์ฉ๋๋ก ๊ตฌ์ถํ๊ธฐ๋ ํจ.
apiVersion: v1
kind: Pod
metadata:
name: mc1
spec:
volumes:
- name: html
emptyDir: {}
containers:
- name: 1st
image: nginx
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
- name: 2nd
image: debian
volumeMounts:
- name: html
mountPath: /html
command: ["/bin/sh", "-c"]
args:
- while true; do
date >> /html/index.html;
sleep 1;
done
ํ๋๋ด์ ์ปจํ ์ด๋ ๊ฐ ํฌํธ๋ฒํธ ์ ๊ฒน์น๊ฒ ์ฃผ์
https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
ํ๋์ ์ฑ ์ปจํ ์ด๋๋ค์ด ์คํ๋๊ธฐ ์ ์ ์คํ๋๋ ํน์ํ ์ปจํ ์ด๋.
- ์ฑ ์ด๋ฏธ์ง์๋ ์๋ ์ ํธ๋ฆฌํฐ ๋๋ ์ค์ ์คํฌ๋ฆฝํธ ๋ฑ์ ํฌํจํ ์ ์๋ค.
initContainers.container
ํญ๋ชฉ์ ์ด๊ธฐํ ์ปจํ
์ด๋ ๋ฆฌ์คํธ ์ถ๊ฐ
.status.initContainerStatuses
: ์ปจํ
์ด๋ ์ํ ๋ฐฐ์ด๋ก ๋ฐํ๋จ.
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app.kubernetes.io/name: MyApp
spec:
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-myservice
image: busybox:1.28
command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
- name: init-mydb
image: busybox:1.28
command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]
containers: ์ฃผ ์ปจํ ์ด๋
initContainers: ์ด๊ธฐํ ์ปจํ ์ด๋
-> myservice, mydb๊ฐ ์คํ๋๊ฒ์ ํ์ธํ๊ธฐ ์ ๊น์ ์ด๊ธฐํ
- initService ์คํ ํ์ธ ์๋น์ค
apiVersion: v1 kind: Service metadata: name: myservice spec: ports: - protocol: TCP port: 80 targetPort: 9376 --- apiVersion: v1 kind: Service metadata: name: mydb spec: ports: - protocol: TCP port: 80 targetPort: 9377
init ์ปจํ ์ด๋ ๋จผ์ ์คํํ๋ฉด Status : Init์ผ๋ก ๊ณ์ ์งํ๋จ
Init ์กฐ๊ฑด ๋ง์กฑํ๊ณ Running์ผ๋ก ์ํ ๋ณ๊ฒฝ