๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ”Ž Kubernetes

Pinpoint Agent Helm Chart ์ž‘์„ฑํ•˜๊ธฐ

by Seongpyo Hong 2021. 3. 6.

์ž‘๋…„ 8์›”๋ถ€ํ„ฐ ์ง„ํ–‰ํ–ˆ๋˜ Pinpoint Helm Chart ์ค‘ Agent์— ๋Œ€ํ•œ Helm Chart ์ œ์ž‘ ๊ณผ์ •์— ๋Œ€ํ•ด์„œ ๋‹ค๋ฃจ์–ด๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค. 


Introduction

Pinpoint Agent๋Š” Java, Go, NodeJS, C ๋“ฑ ๋‹ค์–‘ํ•œ ์–ธ์–ด์— ๋Œ€ํ•œ agent๊ฐ€ ์กด์žฌํ•˜๊ณ  ๊ฐ๊ธฐ ๋‹ค๋ฅธ ์‚ฌ์šฉ๋ฐฉ๋ฒ•์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ์ค‘ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” Java Agent์— ๋Œ€ํ•ด Helm Chart ์ž‘์„ฑ์„ ์‹œ์ž‘ํ•˜์˜€์Šต๋‹ˆ๋‹ค. Java Agent๋Š” ์‹คํ–‰์„ ์œ„ํ•œ jar ํŒŒ์ผ๊ณผ ์ ์šฉํ•  config๋ฅผ ํ•„์š”๋กœ ํ•ฉ๋‹ˆ๋‹ค. jar ํŒŒ์ผ๊ณผ config option์„ target application์„ ์‹คํ–‰ํ•  ๋•Œ ๋ถ€์ฐฉํ•จ์œผ๋กœ์จ data๋ฅผ ์ˆ˜์ง‘, collector๋กœ ์ „์†กํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ฆ‰, application๊ณผ ๋™์ผํ•œ ์ปจํ…Œ์ด๋„ˆ์— agent๋ฅผ ์œ„ํ•œ ํŒŒ์ผ์ด ์กด์žฌํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ดˆ๊ธฐ ๊ณ„ํšํ–ˆ๋˜ ๋ฐฉ๋ฒ•์€ init-container๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Pod ์‹œ์ž‘ ์ „ ํ•„์š”ํ•œ ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›๋Š” ๋ฐฉ๋ฒ•์ด์—ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ init-container๋กœ ์„ค์ •ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด ๋ชจ๋“  Pod๋“ค์— ๋Œ€ํ•ด ๋™์ผํ•œ ํŒŒ์ผ(release)๋ฅผ ๋‹ค์šด๋ฐ›๋Š” ๊ณผ์ •์ด ์ค‘๋ณต๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๋…ธ๋“œ์˜ ์ง€์—ญ์— ๋”ฐ๋ผ ๋„คํŠธ์›Œํฌ ์ด์Šˆ๋กœ ์ธํ•ด ํŒŒ์ผ์„ ๋‹ค์šด ๋ฐ›๋Š” ๊ณผ์ •์—์„œ ์ƒ๋‹นํ•œ ์‹œ๊ฐ„์ด ์†Œ์š”๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Pod์ด ์‹œ์ž‘๋  ๋•Œ ๋งŽ์€ ์‹œ๊ฐ„์ด ์†Œ์š”๋œ๋‹ค๋Š” ๊ฒƒ์€ ๋ฐฐํฌ ๋ฐ ๋กค๋ฐฑ ๊ณผ์ •์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์‹œ๊ฐ„์ด ์ฆ๊ฐ€ํ•˜๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์„œ๋น„์Šค ์šด์˜ ์ธก๋ฉด์—์„œ ์ง€์–‘ํ•ด์•ผ ํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.

์ด์— ๋”ฐ๋ผ ๊ฒฐ์ •ํ•œ ๋ฐฉ๋ฒ•์€ ์ดˆ๊ธฐ ์›ํ•˜๋Š” ๋ฒ„์ „์— ๋Œ€ํ•œ Volume์„ ์ƒ์„ฑํ•˜๊ณ , ํ•ด๋‹น ๋ณผ๋ฅจ์„ Target Application์ด ์กด์žฌํ•˜๋Š” Pod์—์„œ ๋งˆ์šดํŠธํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ฒช์—ˆ๋˜ ๋ฌธ์ œ ์ƒํ™ฉ, ๊ณ ๋ฏผ์— ๋Œ€ํ•ด ๊ณต์œ ํ•ด๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.


์š”๊ตฌ์‚ฌํ•ญ

Agent Helm Chart๊ฐ€ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•  ์—ญํ• ์„ ์ •๋ฆฌํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ์›ํ•˜๋Š” ๋ฒ„์ „์˜ Agent Release๋ฅผ ๋‹ค์šด๋ฐ›์•„ ๋ณผ๋ฅจ์— ์ €์žฅ
  • ์‚ฌ์šฉ์ž๊ฐ€ ์›ํ•˜๋Š” Custom Config๋ฅผ ConfigMap์œผ๋กœ ์ƒ์„ฑ

PVC ์ƒ์„ฑ ๋ฐ Read-Only ์„ค์ •

๊ฐ€์žฅ ๋จผ์ € ํ•ด์•ผํ•˜๋Š” ์ž‘์—…์€ ๊ณต์œ ํ•  ๋ณผ๋ฅจ์„ ์ƒ์„ฑํ•˜๋Š” ์ž‘์—…์ž…๋‹ˆ๋‹ค.

๋ณผ๋ฅจ์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์€ PV๋ฅผ ์ •์˜ํ•˜๊ณ  ์ด๋ฅผ ์ •์  ํ”„๋กœ๋น„์ ธ๋‹ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์กด์žฌํ•˜์ง€๋งŒ ์ตœ๋Œ€ํ•œ ์ผ๋ฐ˜์ ์ธ ์ƒํ™ฉ์— ์ ์šฉํ•ด์•ผ ํ•˜๋Š” ์˜คํ”ˆ์†Œ์Šค์˜ ํŠน์„ฑ๊ณผ ๋งž์ง€ ์•Š๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๊ณ , PVC์™€ StorageClass๋ฅผ ํ†ตํ•ด ๋™์  ํ”„๋กœ๋น„์ ธ๋‹์„ ์ง€์›ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ ํด๋Ÿฌ์Šคํ„ฐ์— ์„ค์ •๋œ default StorageClass๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ๋งŒ์•ฝ ๊ฐœ์ธ์ ์œผ๋กœ ์ •์˜๋œ StorageClass๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค๋ฉด ํ•ด๋‹น ๊ฐ’์„ ์‚ฝ์ž…ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค. 

PVC๋ฅผ ์ƒ์„ฑํ•˜๋ฉฐ ๋˜ ํ•˜๋‚˜ ๊ณ ๋ คํ•ด์•ผ ํ•  ์ ์€ ๋™์ผํ•œ ๋ณผ๋ฅจ์„ ์—ฌ๋Ÿฌ Pod์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ํŒŒ์ผ ๋ณ€๊ฒฝ์ด ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด PVC์˜ accessMode๋ฅผ ReadOnlyMany๋กœ ์„ค์ •์„ ํ†ตํ•ด ๋‹ค์ˆ˜์˜ Pod์ด ๋ณผ๋ฅจ์„ ๋งˆ์šดํŠธํ•˜์—ฌ ์ฝ์„ ์ˆ˜ ์žˆ์ง€๋งŒ, ๋ณผ๋ฅจ์— ์“ฐ๋Š” ์ž‘์—…์€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋„๋ก ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ, ์ด๋ฅผ ํ…Œ์ŠคํŠธ ํ•˜๋ฉฐ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ๋ฌธ์ œ๋ฅผ ๊ฒช์—ˆ๋Š”๋ฐ ์ด๋Š” ROX(ReadOnlyMany)๋กœ PVC๋ฅผ ์„ค์ •ํ•˜์—ฌ ๋งˆ์šดํŠธํ–ˆ๋Š”๋ฐ๋„ ๋ถˆ๊ตฌํ•˜๊ณ  Pod์—์„œ ๋งˆ์šดํŠธ ๊ฒฝ๋กœ์— ํŒŒ์ผ์„ ์“ธ ์ˆ˜ ์žˆ๋Š” ํ˜„์ƒ์ด์˜€์Šต๋‹ˆ๋‹ค. ์›์ธ์„ ์ฐพ๊ธฐ ์œ„ํ•ด kubectl describe pod์„ ํ†ตํ•ด ํ™•์ธํ•ด๋ณด๋‹ˆ ๋งˆ์šดํŠธ ๋œ ๋ณผ๋ฅจ์ด rw ๊ถŒํ•œ์„ ๊ฐ€์ง€๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

Pod Describe ๋‚ด์šฉ

๋˜ํ•œ GKE์—์„œ StorageClass๋ฅผ ์„ค์ •ํ•˜์ง€ ์•Š์•˜์„ ๋•Œ ์„ ํƒ๋˜๋Š” pd-standard๋กœ ๋™์  ํ”„๋กœ๋น„์ ธ๋‹ ๋œ PV๋ฅผ ์‚ดํŽด๋ณด๋‹ˆ ์—ฌ๊ธฐ์„œ๋„ readOnly: false๋กœ ์„ค์ •๋˜์–ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

PV Describe ๋‚ด์šฉ

ํ•˜์ง€๋งŒ PVC๋Š” ๋ถ„๋ช… ROX๋กœ ์„ค์ •๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

PVC Describe ๋‚ด์šฉ

์ด์— ๋Œ€ํ•ด ์ฐพ์•„๋ณธ ๊ฒฐ๊ณผ, ๋™์ผํ•œ ์ด์Šˆ๊ฐ€ ์ด๋ฏธ ์กด์žฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. GooglePersistentDisk๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ PVC์— ROX๋กœ ์„ค์ •ํ•ด์ฃผ๋”๋ผ๋„ ์›Œํฌ๋กœ๋“œ์—์„œ readOnly: true๋ฅผ ์„ค์ •ํ•ด์ค˜์•ผ readOnly๊ฐ€ ์ ์šฉ๋œ๋‹ค๊ณ  ํ•˜์—ฌ ์ด๋ฅผ ์ ์šฉํ•ด์„œ ํ•ด๊ฒฐํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ด์— ๋Œ€ํ•œ ์›์ธ์€ ์ด์Šˆ์—์„œ๋„ ๋ช…ํ™•ํžˆ ์ œ์‹œ๋˜์ง€ ์•Š์•„์„œ ์ถ”ํ›„ ๋” ์ฐพ์•„๋ณผ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

 


Init Job ์ƒ์„ฑ

๋‹ค์Œ์œผ๋กœ ์ง„ํ–‰ํ•ด์•ผ ํ•  ์ž‘์—…์€ Job์„ ํ†ตํ•ด ์›ํ•˜๋Š” ๋ฒ„์ „์˜ pinpoint-agent ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์•„ ๋ณผ๋ฅจ์— ๊ณต์œ ํ•˜๋Š” ์ž‘์—…์ž…๋‹ˆ๋‹ค. Job์˜ Pod์€ ํŒŒ์ผ์„ ์ €์žฅํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— readOnly: true๋ฅผ ์ƒ๋žตํ•˜์˜€์Šต๋‹ˆ๋‹ค.

Job์—์„œ ์ˆ˜ํ–‰ํ•˜๋Š” ์ž‘์—…์€ values.yaml์— ์„ค์ •๋œ agent-version์— ๋งž๋Š” release๋ฅผ ๋‹ค์šด๋ฐ›์•„ ๋ณผ๋ฅจ์˜ /agent/config์— ์ €์žฅํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.


Helm Lifecycle Hook ์„ค์ •

Job์„ ์‚ฌ์šฉํ•จ์œผ๋กœ์จ ๊ณ ๋ คํ•ด์•ผ ํ•  ์ ์€ ํ•ด๋‹น Job์„ ์–ด๋–ป๊ฒŒ ํŠธ๋ฆฌ๊ฑฐ ์‹œํ‚ฌ ๊ฒƒ์ธ์ง€ ์ž…๋‹ˆ๋‹ค. Job์„ ์‹คํ–‰ํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์งค ์ˆ˜๋„ ์žˆ์ง€๋งŒ ์ด๋Š” ์™„์ „ํ•œ ์ž๋™ํ™”๊ฐ€ ์•„๋‹ˆ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๊ณ  ๊ด€๋ จ ๋‚ด์šฉ์„ ์ฐพ๋˜ ์ค‘ Helm Lifecycle Hook์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ์ ‘ํ–ˆ์Šต๋‹ˆ๋‹ค. 

Helm Lifecycle Hook ์ค‘ "helm.sh/hook"์€ ์–ธ์ œ ํ•ด๋‹น ์ž‘์—…์„ ์‹คํ–‰ํ• ์ง€ ๊ฒฐ์ •ํ•˜๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. PVC๋ฅผ ์ƒ์„ฑํ•˜๊ณ  Job์„ ์‹คํ–‰ํ•ด์•ผ ํ•˜๋Š” ์‹œ์ ์€ Helm Chart๋ฅผ ์„ค์น˜ํ•  ๋–„, ๊ทธ๋ฆฌ๊ณ  ๋ฒ„์ „ ์—…๊ทธ๋ ˆ์ด๋“œ๋ฅผ ์ง„ํ–‰ํ•  ๋•Œ์ด๊ธฐ ๋•Œ๋ฌธ์— "helm.sh/hook": pre-install,pre-upgrade ์–ด๋…ธํ…Œ์ด์…˜์„ ์ถ”๊ฐ€ํ•˜์—ฌ ํ•ด๋‹น ์ž‘์—…์ด ์„ค์น˜ ๋ฐ ์—…๊ทธ๋ ˆ์ด๋“œ ์‹œ ์ž๋™์œผ๋กœ ์ด๋ฃจ์–ด์งˆ ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ์œผ๋กœ ๊ณ ๋ คํ•  ์ ์€ PVC์™€ Job ์ƒ์„ฑ์˜ ์ˆœ์„œ์— ๋Œ€ํ•œ ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค. PVC๊ฐ€ ๋จผ์ € ์ˆ˜ํ–‰๋œ ์ดํ›„์— Job์ด ์ˆ˜ํ–‰๋˜์–ด์•ผ ํ•˜๋ฏ€๋กœ hook์˜ ๊ฐ€์ค‘์น˜๋ฅผ ์„ค์ •ํ•˜๋Š” "helm.sh/hook-weight" ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•ด ์ˆœ์„œ๋ฅผ ์ œ์–ดํ•˜์˜€์Šต๋‹ˆ๋‹ค. PVC์˜ ๊ฐ€์ค‘์น˜๋Š” 1๋กœ Job์˜ ๊ฐ€์ค‘์น˜๋Š” 2๋กœ ์„ค์ •ํ•˜์—ฌ PVC๊ฐ€ ์ƒ์„ฑ๋œ ์ดํ›„ Job์ด ์ƒ์„ฑ๋˜๋„๋ก ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.


Helm Lookup

๋‹ค์Œ์œผ๋กœ ๊ณ ๋ คํ•  ์ ์€ Agent์˜ ๋ฒ„์ „์ด ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์•˜์ง€๋งŒ ๋‹ค๋ฅธ ์„ค์ •๋“ค์ด ๋ณ€๊ฒฝ๋˜๋Š” ์ƒํ™ฉ์ž…๋‹ˆ๋‹ค(์˜ˆ๋ฅผ ๋“ค๋ฉด external configuation์ด ์ถ”๊ฐ€๋œ ๊ฒฝ์šฐ). agent์˜ ๋ฒ„์ „์ด ๋ณ€ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์—๋Š” PVC๊ฐ€ ์ด๋ฏธ ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— PVC ์ƒ์„ฑ ๋ฐ Job ์ƒ์„ฑ ์ž‘์—…์ด ์‹คํŒจํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์›ํ•˜๋Š” Agent Version์— ํ•ด๋‹นํ•˜๋Š” PVC๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ์œ„์˜ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜์ง€ ๋ง์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค. Helm ๋ฌธ์„œ๋ฅผ ์ฐพ์•„๋ณธ ๊ฒฐ๊ณผ kubectl get <resource-type> <name>๊ณผ ๋™์ผํ•œ ์—ญํ• ์„ ํ•˜๋Š” lookup ํ•จ์ˆ˜๋ผ๋Š” ๊ฒƒ์ด ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ๋ฐœ๊ฒฌํ–ˆ๊ณ  ์ด๋ฅผ ํ†ตํ•ด์„œ agent version์ด ๋ณ€ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์—๋Š” PVC ๋ฐ Job ์ƒ์„ฑ์„ ํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์ตœ์ข…์ ์œผ๋กœ ์„ค์ •ํ•œ PVC์™€ Job์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

PVC

{{- $agentpvc := (lookup "v1" "PersistentVolumeClaim" .Release.Namespace (printf "agent-%s-pvc" .Values.agent.version )) }}
{{- if not $agentpvc }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: agent-{{ .Values.agent.version }}-pvc
  annotations:
    "helm.sh/hook": pre-install,pre-upgrade
    "helm.sh/hook-weight": "1"
  labels:
{{ include "pinpoint-agent.labels" . | indent 4}}
spec:
    {{- if .Values.agent.storageClass }}
    storageClassName: {{ .Values.agent.storageClass}}
    {{- end}}
    accessModes:
        - ReadOnlyMany
    resources:
        requests:
            storage: 1Gi
{{- end -}}

 

Job

{{- $agentJob := (lookup "batch/v1" "Job" .Release.Namespace (printf "agent-%s-downloader" .Values.agent.version )) }}
{{- if not $agentJob }}
apiVersion: batch/v1
kind: Job
metadata:
  name: agent-{{.Values.agent.version}}-downloader
  annotations:
    "helm.sh/hook": pre-install,pre-upgrade
    "helm.sh/hook-delete-policy": before-hook-creation
    "helm.sh/hook-weight": "2"
  labels:
{{ include "pinpoint-agent.labels" . | indent 4}}
spec:
  template:
    spec:
      containers:
        - name: downloader
          image: alpine
          command:
            - sh
            - -c
            - |
              wget https://github.com/pinpoint-apm/pinpoint/releases/download/v{{ .Values.agent.version }}/pinpoint-agent-{{ .Values.agent.version }}.tar.gz
              tar xvzf pinpoint-agent-{{ .Values.agent.version }}.tar.gz
              mv pinpoint-agent-{{ .Values.agent.version }} ./agent-init/pinpoint-agent

          volumeMounts:
          - name: agent-init
            mountPath: /agent-init
      volumes:
      - name : agent-init
        persistentVolumeClaim:
          claimName: agent-{{ .Values.agent.version }}-pvc
      restartPolicy: Never
  backoffLimit: 3
{{- end -}}

์œ„์˜ ์ž‘์—…์„ ํ†ตํ•ด ๊ณตํ†ต์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” Pinpont Agent Release ํŒŒ์ผ์€ ์ค€๋น„๊ฐ€ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์œผ๋กœ ํ•ด์•ผํ•  ์ž‘์—…์€ ๊ฐ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋งž๋Š” Custom ์„ค์ •์„ ์ฃผ์ž…ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. 


ConfigMap ์ƒ์„ฑ

๊ฐœ์ธ์ ์œผ๋กœ Config ํŒŒ์ผ์„ ConfigMap์— ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง„๋‹ค๊ณ  ์ƒ๊ฐํ•˜์—ฌ(๊ฐœ์ธ์ ์ธ ์˜๊ฒฌ์ž…๋‹ˆ๋‹ค.) ์™ธ๋ถ€์— ์„ค์ •ํŒŒ์ผ์„ ์œ„์น˜์‹œํ‚ค๋Š” ๊ฒƒ์„ ์„ ํ˜ธํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ files/conf ์ด๋ผ๋Š” ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ ํ•˜์œ„์— ์žˆ๋Š” ํŒŒ์ผ์„ ConfigMap์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค. 

์ด ๋•Œ ๋ชจ๋“  ์„ค์ •ํŒŒ์ผ์„ ํ•˜๋‚˜์˜ ConfigMap์— ์„ค์ •ํ•  ์ˆ˜๋Š” ์žˆ์ง€๋งŒ ๊ฒฐ๊ตญ ํ•˜๋‚˜์˜ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ํ•„์š”ํ•œ ์„ค์ • ํŒŒ์ผ์„ ํ•˜๋‚˜์ด๊ณ  ๋‚˜๋จธ์ง€ ํŒŒ์ผ๋“ค์€ ๋ถˆํ•„์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•˜์—ฌ values.yaml์—์„œ externalConfigName์„ ํ†ตํ•ด application์— ์ถ”๊ฐ€ํ•˜๊ธฐ ์›ํ•˜๋Š” ์„ค์ • ํŒŒ์ผ์˜ ์ด๋ฆ„์„ ์ฃผ์ž…ํ•˜๋ฉด ํ•ด๋‹นํ•˜๋Š” configmap๋งŒ ์ƒ์„ฑํ•˜๋„๋ก ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค. 

ํŒŒ์ผ์„ ConfigMap์œผ๋กœ ์ €์žฅํ•˜๋Š” ๋ถ€๋ถ„์€ Files.Get์„ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

ConfigMap

{{ if .Values.agent.externalConfigName }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: external-config-{{ .Values.agent.externalConfigName }}
  labels:
{{ include "pinpoint-agent.labels" . | indent 4}}
data:
  {{ .Values.agent.externalConfigName}}.config: |
{{ .Files.Get (printf "files/conf/%s.config" .Values.agent.externalConfigName ) | indent 4 }}
{{- end -}}

์ตœ์ข…์ ์œผ๋กœ agent ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์„ค์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

  • EXTERNAL_CONFIG_PATH : ์ปค์Šคํ…€ ์„ค์ •์˜ ์œ„์น˜๋ฅผ ์‹คํ–‰ ์‹œ ์˜ต์…˜์œผ๋กœ ๋„ฃ์–ด์ฃผ๊ธฐ ์œ„ํ•œ ํ™˜๊ฒฝ๋ณ€์ˆ˜์ž…๋‹ˆ๋‹ค.
  • ConfigMap VolumeMount : ์›ํ•˜๋Š” ์ปค์Šคํ…€ ์„ค์ •์„ ๋งˆ์šดํŠธํ•˜๊ธฐ ์œ„ํ•œ ์˜ต์…˜์ž…๋‹ˆ๋‹ค.
  • PVC VolumeMount : ์›ํ•˜๋Š” ๋ฒ„์ „์˜ release ํŒŒ์ผ์„ ๋งˆ์šดํŠธํ•˜๊ธฐ ์œ„ํ•œ ์˜ต์…˜์ž…๋‹ˆ๋‹ค.

์˜ˆ์‹œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deploy-1
  labels:
    app: test-deploy-1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-deploy
  template:
    metadata:
      labels:
        app: test-deploy
    spec:
      containers:
      - name: test
        image: alpine
        command:
        - sh
        - -c
        - |
          tail -f /dev/null
        env:
          - name: EXTERNAL_CONFIG_PATH
            value: "/pinpoint/config/{{ .Values.agent.externalConfigName}}"
        volumeMounts:
        - name: agent-init
          mountPath: /agent-init
        - name: agent-external-config
          mountPath: /pinpoint/config
      volumes:
      - name: agent-init
        persistentVolumeClaim:
            claimName: agent-{{ .Values.agent.version }}-pvc
            readOnly: true
      - name: agent-external-config
        configMap:
          name: external-config-{{ .Values.agent.externalConfigName }}

๋ถ€์กฑํ•œ ๋ถ€๋ถ„์ด ๋ฌผ๋ก  ๋งŽ์ง€๋งŒ ๊ทธ๋Ÿผ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ๊ธ€์„ ์ž‘์„ฑํ•˜๋Š” ์ด์œ ๋Š” ํ•ด๋‹น ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ํ‰์†Œ ๋†“์น˜๊ณ  ์žˆ์—ˆ๋˜ accessMode๋‚˜ Helm์˜ ๋ถ€๊ฐ€ ๊ฐ€๋Šฅ์— ๋Œ€ํ•ด์„œ ์•Œ ์ˆ˜ ์žˆ๋˜ ์‹œ๊ฐ„์ด์˜€๊ณ  ์ด๋ฅผ ๊ณต์œ ํ•˜๊ธฐ ์œ„ํ•ด์„œ์ž…๋‹ˆ๋‹ค. Agent๋ฅผ ์œ„ํ•œ Helm Chart ์ž‘์„ฑ ์ž‘์—…์€ ์—ฌ์ „ํžˆ ์ง„ํ–‰ ์ค‘์ด๊ณ  ๋” ์ข‹์€ ์˜๊ฒฌ์ด ์žˆ์œผ์‹  ๋ถ„๋“ค์€ ๊ณต์œ ํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

๋ชจ๋“  ์ฝ”๋“œ๋Š” Github์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


2021.03.23 ์ˆ˜์ •
- jar ํŒŒ์ผ์— ๋Œ€ํ•ด ์—ฌ๋Ÿฌ Pod์ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๊ธฐ ๋–„๋ฌธ์—, PV๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

๋Œ“๊ธ€