๋กœ์ผ“๐Ÿพ
article thumbnail

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—์„œ๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋‚˜ ์ƒˆ๋กญ๊ฒŒ ์ž‘์„ฑํ•œ ํŒŒ์ผ์„ ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์— ์ „๋‹ฌํ•ด์ฃผ๊ธฐ ์œ„ํ•ด์„œ Configmap, Secret ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. 

 

์ด๋ฆ„์—์„œ ์œ ์ถ”ํ•  ์ˆ˜ ์žˆ๋“ฏ Configmap ์€ ๋ณด์•ˆ์ ์œผ๋กœ ์ค‘์š”์น˜ ์•Š์€ ๋ฐ์ดํ„ฐ๋“ค์„ ์‚ฌ์šฉํ•  ๋•Œ, Secret ์€ ๋ณด์•ˆ์ ์œผ๋กœ ์ค‘์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ Configmap ์€ Plain Text ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜๋Š” ๋ฐ˜๋ฉด, Secret ์€ ์ธ์ฝ”๋”ฉ ๋˜์–ด ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.

 

๊ทธ๋ž˜์„œ ์ด๋ฒˆ ๊ธ€์—์„œ๋Š” Secret ์„ ์ƒ์„ฑ ํ›„ ์–ด๋–ป๊ฒŒ ํŒŒ๋“œ์—๊ฒŒ ์ „๋‹ฌํ•˜๋Š” ์ง€๋ฅผ ์•Œ์•„๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

 

์—ฌ๋‹ด์œผ๋กœ Secret ์˜ ์ธ์ฝ”๋”ฉ ๋˜๋Š” ๋ฐฉ๋ฒ•์€ ์‚ฌ์‹ค ๋””์ฝ”๋”ฉ ํ•˜๋ฉด ์–ด๋–ค ๊ฐ’์ธ์ง€ ์•Œ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ณด์•ˆ์ ์œผ๋กœ ์•ˆ์ „ํ•˜์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค. ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ์ด๋ ‡๊ฒŒ ๊ตณ์ด Secret ์˜ ๊ฐ’์„ ์ธ์ฝ”๋”ฉํ•ด์„œ ์ €์žฅํ•˜๋Š” ์ด์œ ๋Š” ํ•ด์ปค์—๊ฒŒ ํ˜ผ๋ˆ์„ ์ฃผ๊ธฐ ์œ„ํ•ด์„œ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

๋งŒ์•ฝ, ์ •๋ง ๋ณด์•ˆ์ ์œผ๋กœ ์•ˆ์ „ํ•˜๊ฒŒ Secret ์„ ๊ด€๋ฆฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, RBAC ๋ฅผ ํ†ตํ•ด ์ ‘๊ทผ ๊ถŒํ•œ์„ ์ œํ•œํ•˜๊ฑฐ๋‚˜ Vault ์™€ ๊ฐ™์€ ํ‚ค ๋งค๋‹ˆ์ € ํˆด์„ ์ด์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿผ ๋ ›์ธ ๋‘๋”์ฝ”๋“œ~

๋ ›์ธ ๋‘๋”์ฝ”๋“œ

 

 

์‹œ์ž‘ํ•˜๊ธฐ ์ „์—


์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—์„œ๋Š” Secret ์„ ์ฃผ์ž…ํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ํฌ๊ฒŒ 2๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

  • Env ์„ ์ด์šฉํ•œ ๋ฐฉ๋ฒ•
  • Volume ์„ ์ด์šฉํ•œ ๋ฐฉ๋ฒ•

 

์ฐจ๋ก€๋Œ€๋กœ ํ•˜๋‚˜์”ฉ ์•Œ์•„๋ณด๋„๋ก ํ•˜์ฃ  !

 

(๊ณต์‹ ๋ฌธ์„œ๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์—ฌ๊ธฐ)

 

 

Env ์„ ์ด์šฉํ•œ ๋ฐฉ๋ฒ•

 

๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ Secret ์˜ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ

(๊ณต์‹ ๋ฌธ์„œ๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์—ฌ๊ธฐ)

 

apiVersion: v1
data:
  password: Mzk1MjgkdmRnN0pi # 39528$vdg7Jb
  username: bXktYXBw # my-app
kind: Secret
metadata:
  creationTimestamp: null
  name: env-each-secret
---
apiVersion: v1
kind: Pod
metadata:
  name: env-each-secret
spec:
  containers:
  - name: tester
    image: nginx
    env:
    - name: SECRET_USERNAME # ์ปจํ…Œ์ด๋„ˆ ๋‚ด์—์„œ ๋“ฑ๋ก ๋  ํ™˜๊ฒฝ๋ณ€์ˆ˜์˜ ์ด๋ฆ„
      valueFrom:
        secretKeyRef:
          name: env-each-secret # secret ์˜ ์ด๋ฆ„
          key: username # secret data ์— ๋ช…์‹œ๋œ ํ‚ค
    - name: SECRET_PASSWORD # ์ปจํ…Œ์ด๋„ˆ ๋‚ด์—์„œ ๋“ฑ๋ก ๋  ํ™˜๊ฒฝ๋ณ€์ˆ˜์˜ ์ด๋ฆ„
      valueFrom:
        secretKeyRef:
          name: env-each-secret # secret ์˜ ์ด๋ฆ„
          key: password # secret data ์— ๋ช…์‹œ๋œ ํ‚ค

 

df -h

 

Volume ์ด ์•„๋‹Œ Env ๋ฐฉ์‹์ด๊ธฐ ๋•Œ๋ฌธ์— ๋งˆ์šดํŠธ๋œ ๊ฒฝ๋กœ๋Š” ๋”ฐ๋กœ ์—†์Šต๋‹ˆ๋‹ค.

 

 

env

 

env ๋ฅผ ์‹คํ–‰ํ•œ ๊ฒฐ๊ณผ SECRET_USERNAME ๊ณผ SECRET_PASSWORD ๊ฐ’์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์œ„์—์„œ ์–ธ๊ธ‰ํ–ˆ๋˜ ๊ฒƒ์ฒ˜๋Ÿผ Secret ์ด ๊ฐ’์ด ์ปจํ…Œ์ด๋„ˆ ๋‚ด์—์„  ์ด๋Ÿฐ ์‹์œผ๋กœ ์™„์ „ํžˆ ๋…ธ์ถœ๋˜๊ธฐ ๋•Œ๋ฌธ์— RBAC ๋ฅผ ํ†ตํ•ด ์ ‘๊ทผ ์ œํ•œ์„ ๋ฐ˜๋“œ์‹œ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

 

์œ„์— ๋ฐฉ๋ฒ•์€ ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ด๊ณ  ๊น”๋”ํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ Secret ์˜ data ๊ฐฏ์ˆ˜๋งŒํผ .spec.containers[].env ์˜ ๋ฆฌ์ŠคํŠธ ๋˜ํ•œ ๋Š˜์–ด๋‚œ๋‹ค๋Š” ๋‹จ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ Secret ์˜ data ๊ฐ€ 100๊ฐœ๋ผ๋ฉด pod.yaml ์˜ ์ฝ”๋“œ๊ฐ€ ์ƒ๋‹นํ•ด์ง€์ฃ .

 

๊ทธ๋Ÿผ ๋ฐ”๋กœ ์ด์–ด์„œ data ๊ฐฏ์ˆ˜๊ฐ€ ๋งŽ์€ ๊ฒฝ์šฐ์—๋Š” ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•˜๋Š” ์ง€ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

ํ•œ๊บผ๋ฒˆ์— Env ๋กœ Secret ์˜ data ์ฒ˜๋ฆฌ

(๊ณต์‹ ๋ฌธ์„œ๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์—ฌ๊ธฐ)

 

apiVersion: v1
data:
  password: Mzk1MjgkdmRnN0pi # 39528$vdg7Jb
  username: bXktYXBw # my-app
kind: Secret
metadata:
  creationTimestamp: null
  name: env-all-secrets
---
apiVersion: v1
kind: Pod
metadata:
  name: env-all-secrets
spec:
  containers:
  - name: tester
    image: nginx
    envFrom:
    - secretRef:
        name: env-all-secrets

 

ํ™•์—ฐํžˆ pod.yaml ์˜ ์ฝ”๋“œ ์ˆ˜๊ฐ€ ์ ์–ด์กŒ์Šต๋‹ˆ๋‹ค.

 

df -h

 

Volume ์ด ์•„๋‹Œ Env ๋ฐฉ์‹์ด๊ธฐ ๋•Œ๋ฌธ์— ๋งˆ์šดํŠธ๋œ ๊ฒฝ๋กœ๋Š” ๋”ฐ๋กœ ์—†์Šต๋‹ˆ๋‹ค.

 

env

 

env ๋ฅผ ์‹คํ–‰ํ•œ ๊ฒฐ๊ณผ SECRET_USERNAME ๊ณผ SECRET_PASSWORD ๊ฐ’์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Secret ์˜ data ๋ฅผ ํ•˜๋‚˜ํ•˜๋‚˜ ์ฒ˜๋ฆฌํ•  ํ•„์š”์—†์ด ํ•œ๊บผ๋ฒˆ์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿผ ์ด์ œ๋Š” Env ๊ฐ€ ์•„๋‹Œ Volume ์„ ํ†ตํ•ด Secret ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

๊ธฐ๋ณธ์ ์ธ Volume ์„ ํ†ตํ•œ Secret ์˜ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ

(๊ณต์‹ ๋ฌธ์„œ๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์—ฌ๊ธฐ)

 

apiVersion: v1
data:
  password: Mzk1MjgkdmRnN0pi # 39528$vdg7Jb
  username: bXktYXBw # my-app
kind: Secret
metadata:
  name: volume-basic-secret
---
apiVersion: v1
kind: Pod
metadata:
  name: volume-basic-secret
spec:
  containers:
    - name: tester
      image: nginx
      volumeMounts:
        - name: test-secret
          mountPath: /etc/secret-volume
          readOnly: true
  volumes:
    - name: test-secret
      secret:
        secretName: volume-basic-secret

 

df -h

 

Volume ์„ ์ด์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— Env ์™€ ๋‹ฌ๋ฆฌ ๋งˆ์šดํŠธ ๊ฒฝ๋กœ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ ๋งˆ์šดํŠธ๋Š” tmpfs ๋กœ ๋ฉ๋‹ˆ๋‹ค.

Configmap ๊ณผ ๋‹ฌ๋ฆฌ Secret ์€ Volume Mount ํ•  ๊ฒฝ์šฐ tmpfs ๋กœ ๋งˆ์šดํŠธ ๋ฉ๋‹ˆ๋‹ค.
tmpfs ๋Š” RAM ๊ธฐ๋ฐ˜์˜ ๊ฐ€์ƒ ํŒŒ์ผ ์‹œ์Šคํ…œ์œผ๋กœ ๋ฌผ๋ฆฌ์ ์ธ ํ•˜๋“œ์›จ์–ด๊ฐ€ ํƒˆ์ทจ ๋‹นํ•ด๋„ ๊ณต๊ฒฉ์ž๊ฐ€ ์‹œํฌ๋ฆฟ์„ ์ทจ๋“ํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค.

 

 

 

๊ทธ๋ฆฌ๊ณ  Env ์™€ ๋‹ฌ๋ฆฌ Secret ์˜ data ๊ฐ€ password, username ์˜ ํŒŒ์ผ๋กœ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ์ด ํŒŒ์ผ์€ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๊ฐ€ ๊ฑธ๋ ค์žˆ๋Š” ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์‹ค์ œ ํŒŒ์ผ์€ ..data ๊ฒฝ๋กœ์— ์žˆ๋Š” ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.

 

์ด ๋ฐฉ๋ฒ•์€ Secret ์˜ data ๊ฐ€ ํ•œ๊บผ๋ฒˆ์— ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ํ•˜๋‚˜ํ•˜๋‚˜ ๋‹ค๋ฅธ ๊ฒฝ๋กœ์— ์ฒ˜๋ฆฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Volume ์„ ํ†ตํ•ด ํ•˜๋‚˜ํ•˜๋‚˜ Secret ์˜ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ

(๊ณต์‹ ๋ฌธ์„œ๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์—ฌ๊ธฐ)

 

apiVersion: v1
data:
  password: Mzk1MjgkdmRnN0pi # 39528$vdg7Jb
  username: bXktYXBw # my-app
kind: Secret
metadata:
  name: volume-basic-secret
---
apiVersion: v1
kind: Pod
metadata:
  name: volume-basic-secret
spec:
  containers:
  - name: tester
    image: nginx
    volumeMounts:
    - name: foo
      mountPath: "/etc/foo"
      readOnly: true
  volumes:
  - name: foo
    secret:
      secretName: volume-basic-secret
      items:
      - key: username
        path: my-group/my-username

 

df -h

 

Volume ์„ ์ด์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— Env ์™€ ๋‹ฌ๋ฆฌ ๋งˆ์šดํŠธ ๊ฒฝ๋กœ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

 

 

 

/etc/foo ๋ฐ‘์— /my-group/my-username ์— usernmae ์˜ data ๋งŒ ๋งˆ์šดํŠธ ๋  ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋˜ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—์„  posix ๋กœ ํŒŒ์ผ์„ ๋งˆ์šดํŠธํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ถŒํ•œ ์„ค์ •๋„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Volume ์„ ํ†ตํ•ด ์ „๋‹ฌ๋œ Secret ์˜ ๋ฐ์ดํ„ฐ ๊ถŒํ•œ ์„ค์ •

(๊ณต์‹ ๋ฌธ์„œ๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์—ฌ๊ธฐ)

 

apiVersion: v1
data:
  password: Mzk1MjgkdmRnN0pi # 39528$vdg7Jb
  username: bXktYXBw # my-app
kind: Secret
metadata:
  name: volume-posix-secret
---
apiVersion: v1
kind: Pod
metadata:
  name: volume-posix-secret
spec:
  containers:
  - name: test
    image: nginx
    volumeMounts:
    - name: foo
      mountPath: "/etc/foo"
  volumes:
  - name: foo
    secret:
      secretName: volume-posix-secret
      defaultMode: 0400

 

df -h

 

Volume ์„ ์ด์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— Env ์™€ ๋‹ฌ๋ฆฌ ๋งˆ์šดํŠธ ๊ฒฝ๋กœ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

 

 

์–ด? ์ด์ƒํ•ฉ๋‹ˆ๋‹ค.. 0400 ์œผ๋กœ ์„ค์ •ํ–ˆ๋Š”๋ฐ ์‹ค์ œ๋กœ ๋ณด๋‹ˆ 0777 ์ž…๋‹ˆ๋‹ค.

 

์ด๋Š” ์‚ฌ์‹ค ์ œ๋Œ€๋กœ ๋œ ๊ฒƒ์ด ๋งž์Šต๋‹ˆ๋‹ค. ๋ณด๋ฉด ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๊ฐ€ ๊ฑธ๋ ค ์žˆ๋Š”๋ฐ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ์˜ ํŠน์ง•์„ ์ƒ๊ฐํ•ด๋ณด๋ฉด ํฌ๊ฒŒ ๋ฌธ์ œ๋  ๊ฒƒ์€ ์—†์–ด๋ณด์ž…๋‹ˆ๋‹ค.

 

 

์‹ฌ๋ณผ๋ฆญ ๋งํฌ์˜ ๋Œ€์ƒ ํŒŒ์ผ์€ ์‹ค์ œ๋กœ 0400 ์ด ์ž˜ ์„ค์ •๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.

 

 

์ด๋ฒˆ ๊ธ€์—์„œ๋Š” Secret ์˜ data ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค. ๋งค๋ฒˆ ํ—ท๊ฐˆ๋ฆฌ๋Š” ๋ถ€๋ถ„์ด์ฃ ..

Configmap ์˜ data ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€ Secret ๊ณผ 99% ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค. Secret ์„ ์•Œ๋ฉด Configmap ๋˜ํ•œ ์‰ฝ๊ฒŒ ์ฒ˜๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜์ฃ .

 

ํŠน์ดํ•œ ์ ์€ Configmap ์˜ ๊ฒฝ์šฐ Volume ์„ ์‚ฌ์šฉํ•ด๋„ ๋งˆ์šดํŠธ๊ฐ€ ๋˜์ง„ ์•Š์Šต๋‹ˆ๋‹ค. (df -h ์˜ ๊ฒฐ๊ณผ๊ฐ’์ด ์—†์Œ)

 

๊ทธ๋Ÿผ ์˜ค๋Š˜์€ ์—ฌ๊ธฐ๊นŒ์ง€!

profile on loading

Loading...