Pod
์ด๋ฏธ์ง ํ๊ทธ
์ฌ์ฉ์ ๊ผญ ํ๊ทธ ๋๋ฒ๋ฅผ ์ฌ์ฉ ์๋ฌด๊ฒ๋ ์์ฐ๋ฉด latest๊ฐ ์๋์ผ๋ก ๋ถ๋๋ค.
latest ๋ฅผ ์ฌ์ฉํ์ง ๋ง์. ๊ณ์ ๋ฒ์ ์ด ๋ฐ๋๋ฏ๋ก ๋ฌธ์ ๊ฐ ๋๋ค.
์ฌ์ค sha ํ๊ทธ๋ ์ค๋ณต์ด ๋๋ค. ๊ฐ๋ฅํ๋ฉด container digest๋ฅผ ์ฌ์ฉํ์.
digest๋ ์ ์ผํ๋ค.
docker image ls --digests

ํ๊ฒฝ๋ณ์์ ์ต๋๊ฐ์ 32KiB๋ก ์ ํ
delete completed pod
kubectl delete pod --field-selector=status.phase==Succeededenv๋ฅผ configmap์ผ๋ก ์ด์ฉํ๊ธฐ
configmap ์ด ์๋ ์ํฉ์์ pod์์ env๊ฐ์ผ๋ก configmap์ ์ด์ฉํ๊ธฐ
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: ['/bin/sh', '-c', 'env']
env:
# Define the environment variable
- name: SPECIAL_LEVEL_KEY
valueFrom:
configMapKeyRef:
# The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
name: special-config
# Specify the key associated with the value
key: special.how
restartPolicy: NeverenvFrom๋ฅผ configmap์ผ๋ก ์ด์ฉํ๊ธฐ
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: ['/bin/sh', '-c', 'env']
envFrom:
- configMapRef:
name: special-config
restartPolicy: Never์ด๋ ๊ฒ ํ๋ฉด configmap์ ์๋ ๋ชจ๋ ๋ด์ฉ์ด env๊ฐ์ผ๋ก ๋ณํ๋๋ค.
securityContext
root๊ฐ ์๋ ์ฌ์ฉ์๋ก ์ปจํ ์ด๋ ์คํํ๊ธฐ
apiVersion: v1
kind: Pod
metadata:
name: securityContext
spec:
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000๋์ปค ์ด๋ฏธ์ง์์๋ ์ง์ ์ด ๊ฐ๋ฅํ๋ ์ด๋ ๊ฒ ์ฟ ๋ฒ๋คํฐ์ค์์ ๋ณ๊ฒฝ๋ ๊ฐ๋ฅํ๋ค.
1000๋ฒ์ ๋ฆฌ๋ ์ค์์ ์ฒ์ ์ ์ ๊ฐ ๊ฐ์ง๋ ๋ฒํธ์ด๋ฏ๋ก 1000๋ฒ ์ด์์ ์ฌ์ฉํ๋๊ฒ ์ข๋ค.
์ฟ ๋ฒ๋คํฐ์ค๊ฐ ๋์ปค์ ๋ชจ๋ ์ ์ ์ค์ ์ ๋ฎ์ด์ด๋ค.
๊ฐ ์ปจํ ์ด๋๋ง๋ค ๋ค๋ฅธ uid๋ฅผ ์ถ์ฒํ๋ค.
๋๊ฐ์ ์ปจํ ์ด๋๊ฐ ๋์ผํ ๋ฐ์ดํฐ์ ์ ๊ทผํ๋ฉด uid๋ ๊ฐ์์ผํ๋ค.
root container ์ฐจ๋จํ๊ธฐ
์ฟ ๋ฒ๋คํฐ์ค๊ฐ container๊ฐ root๋ก ์คํ๋๋๊ฒ์ ๋ฐฉ์งํด์ฃผ๋ ์ต์ ์ ์ ๊ณต
apiVersion: v1
kind: Pod
# ...
spec:
securityContext:
runAsNonRoot: trueroot๋ก ์คํ๋๋๊ฒ์ ๋ฐฉ์งํด์ค๋ค.
CreateContainerConfigError: container 'root' is not allowed to run as root ๋ฐ์
readOnlyRootFile
apiVersion: v1
kind: Pod
# ...
spec:
securityContext:
readOnlyRootFileSystem: true์ปจํ ์ด๋์ ์ฐ๊ธฐ ๊ถํ์ด ํ์ํ์ง ์์ผ๋ฉด ์ต์ ์ ์ฌ์ฉํ์.
๊ถํ ์์น ๋นํ์ฑํ
apiVersion: v1
kind: Pod
# ...
spec:
securityContext:
allowPrivilegeEscalation: false๋ฆฌ๋ ์ค ๋ฐ์ด๋๋ฆฌ๋ ์ด๋ฅผ ์คํํ ์ฌ์ฉ์์ ๊ฐ์ ๊ถํ์ผ๋ก ์คํ๋๋ค. ๊ทธ๋ฌ๋ ์์ธ๋ ์๋ค.
seuid ๋งค์ปค๋์ฆ์ ์ฌ์ฉํ๋ฉด ์ผ์์ ์ผ๋ก ๋ฐ์ด๋๋ฆฌ๋ฅผ ์์ ํ ์ฌ์ฉ์(์ผ๋ฐ์ ์ผ๋ก root)์ ๊ถํ์ผ๋ก ์คํํ ์ ์๋ค.
์ปจํ
์ด๋๋ฅผ ์ผ๋ฐ ์ฌ์ฉ์๋ก ์คํํ๋๋ผ๋ ์ปจํ
์ด๋๊ฐ setuid ๋ฐ์ด๋๋ฆฌ๋ฅผ ๊ฐ์ง๊ณ ์๋ ๊ฒฝ์ฐ์ ์ปจํ
์ด๋์์ root ๊ถํ์ ์ป์์ ์์ผ๋ฏ๋ก ์ ์ฌ์ ์ธ ๋ฌธ์ ๊ฐ ๋๋ค. ์ด๋ฅผ ๋ฐฉ์งํ๊ธฐ์ํด allowPrivilegeEscalation ๋ฅผ ์ฌ์ฉํ๋ค.
์ปจํ
์ด๋ ๋จ์๋ก ๊ถํ ์ค์
์ ์ค์ ๋ค์ pod๊ฐ ์๋๋ผ ์ปจํ ์ด๋ ์์ค์ผ๋ก ์ฌ๋ผ๊ฐ์๋ ์๋ค.
Last updated
Was this helpful?