Alert if an image used in Kubernetes cannot be pulled from container registry

5 minute read

Image Registry ๋ชจ๋‹ˆํ„ฐ๋ง

K8s ํด๋Ÿฌ์Šคํ„ฐ์—์„œ python Pod์„ ๋„์šฐ๋ ค๋Š” ๋‹น์‹ ! ๊ทธ๋Ÿฐ๋ฐ, ์šฐ์—ฐํžˆ๋„ Dockerhub์˜ ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•ด๋ฒ„๋ฆฌ๊ณ โ€ฆ ๋‹น์‹ ์ด ๋„์šฐ๋ ค๋Š” Pod์€ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ›์•„์˜ค์ง€ ๋ชปํ•ด ImagePullBackOff์— ๋น ์ ธ๋ฒ„๋ฆฐ๋‹คโ€ฆ Dockerhub์˜ ์•ˆ์ •์„ฑ์„ ์ฒ ์ฉ ๊ฐ™์ด ๋ฏฟ์–ด๋ฒ„๋ฆฐ ๋‹น์‹ ์€ ์„ค๋งˆ ์ด ๋‹จ๊ณ„์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋‚  ๊ฑฐ๋ผ๊ณ ๋Š” ์ƒ๊ฐํ•˜์ง€๋„ ๋ชปํ•œ์ฑ„โ€ฆ

ํ„ฐ์ ธ๋ฒ„๋ฆฐ Dockerhubโ€ฆ

K8s๋Š” Image๋ฅผ ์ €์žฅํ•˜๋Š” โ€œRegistryโ€ ๋‹จ์—์„œ ์žฅ์• ๊ฐ€ ์ƒ๊ธฐ๋ฉด Pod์„ ๋„์šฐ๋Š” ๊ฒƒ์กฐ์ฐจ ๋ชปํ•˜๋Š” ์ƒํƒœ์— ์ง๋ฉดํ•œ๋‹ค. ๊ทธ๋ž˜์„œ K8s ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์šด์˜ํ•œ๋‹ค๋ฉด Dockerhub, AWS ECR, Github ghcr ๊ฐ™์€ Image Registry์˜ ์ƒํƒœ๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜๋ฉฐ Registry ์žฅ์• ๊ฐ€ K8s ํด๋Ÿฌ์Šคํ„ฐ ์šด์˜์— ์˜ํ–ฅ์„ ์ฃผ์ง„ ์•Š์„์ง€ ์ฃผ์‹œํ•  ํ•„์š”๊ฐ€ ์žˆ์„ ๊ฒƒ์ด๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ ๋งค๋ฒˆ ์ƒํƒœ ํŽ˜์ด์ง€์— ๋“ค์–ด๊ฐ€์„œ ํ™•์ธํ•˜๊ธฐ๋„ ํž˜๋“ค๊ณ , Registry ์ „์ฒด ์žฅ์• ๊ฐ€ ์•„๋‹ˆ๋ผ ๋ณธ์ธ์ด ์‚ฌ์šฉํ•˜๋Š” Image์˜ Registry์—๋งŒ ์žฅ์• ๊ฐ€ ์ƒ๊ธธ ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ์ด๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ K8s ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์šด์˜ํ•  ์ •๋„๋ฉด ์‚ฌ์šฉํ•˜๋Š” ์ด๋ฏธ์ง€๋„ ๊ฐ์–‘๊ฐ์ƒ‰ ์ผํ„ฐ Pod์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์ด๋ฏธ์ง€๋“ค์ด ์ˆ˜์‹ญ๊ฐœ๋Š” ๋  ๊ฒƒ์ด๊ณ , ํด๋Ÿฌ์Šคํ„ฐ์— ๋– ์žˆ๋Š” ๋ชจ๋“  ์ด๋ฏธ์ง€๋ฅผ ๋‚˜์—ดํ•ด์„œ ์ •๋ฆฌํ•˜๋Š” ๊ฒƒ๋„ ์ผ์ด๋‹ค.

์ด๋Ÿฐ ๊ท€์ฐฎ์€ ์ž‘์—…์„ ๋Œ€์‹  ํ•ด์ฃผ๋Š” Prometheus Exporter๊ฐ€ ์žˆ์œผ๋‹ˆ ๋ฐ”๋กœ โ€œKubernetes Image Availability Exporterโ€œ๋‹ค!

K8s Image Availability Exporter

K8s Image Availability Exporter, ์ค„์—ฌ์„œ k8s-iae exporter๋Š” K8s ํด๋Ÿฌ์Šคํ„ฐ์• ์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ์ด๋ฏธ์ง€ ์ข…๋ฅ˜๋ฅผ ์ˆ˜์ง‘ํ•ด ํ•ด๋‹น Image์˜ ์ƒํƒœ๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜๋Š” Exporter๋‹ค. ์—๋ฅผ ๋“ค์–ด, K8s ํด๋Ÿฌ์Šคํ„ฐ์—์„œ python:3.9, public.ecr.aws/docker/library/node ๋“ฑ์„ ์‚ฌ์šฉํ•˜๋Š” Pod๋“ค์ด ์กด์žฌํ•œ๋‹ค๋ฉด, ๊ทธ๋“ค์— ๋Œ€ํ•œ ์ƒํƒœ๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

๊ธฐ์กด์—๋Š” ์‚ฌ๋žŒ์ด K8s ํด๋Ÿฌ์Šคํ„ฐ ์ „์ฒด Pod์„ ํ™•์ธํ•˜๋ฉฐ ์‚ฌ์šฉํ•˜๋Š” Image๋ฅผ ์ •๋ฆฌํ•ด์•ผ ํ–ˆ๋‹ค๋ฉด, K8s iae exporter๋Š” ๊ทธ ๋ชฉ๋ก์„ ์•Œ์•„์„œ ์ถ”์ถœํ•œ๋‹ค!

๊ทธ๋ž˜์„œ K8s iae exporter๋งŒ ๋„์›Œ๋‘๋ฉด, K8s ํด๋Ÿฌ์Šคํ„ฐ์˜ Pod image์˜ ์ƒํƒœ๊ฐ€ ์•Œ์•„์„œ ๊ฐ์‹œ๋˜๊ณ , ๊ทธ ์ •๋ณด๊ฐ€ Prometheus์— ์ €์žฅ๋œ๋‹ค!

์ด๊ฑฐ ์ •๋ง ํ•„์š”ํ•œ ๊ฑธ๊นŒ?

๋†‰! ๋ณธ์ธ์€ ์š” Exporter๊ฐ€ ๊ตณ์ด ํ•„์š” ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹ค! ๊ตฌ๊ตฌ์ ˆ์ ˆ ์š” Exporter๋ฅผ ์„ค๋ช…ํ–ˆ์ง€๋งŒโ€ฆ ์ด๊ฒŒ ๋ฌด์Šจ ๋ง์ธ๊ฐ€ ใ…‹ใ…‹

์ผ๋‹จ k8s iae exporter๊ฐ€ ํ•ด๋‹น ์ด๋ฏธ์ง€์˜ ์žฅ์• ๋ฅผ ํฌ์ฐฉํ–ˆ๋‹ค๊ณ  ํ•ด์„œ, ๊ทธ๊ฑธ ๊ฐ€๋Šฅํ•œ ๋‹ค๋ฅธ ํƒœ๊ทธ๋กœ Pod yaml์„ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๊ทธ๋Ÿฐ ๋Œ€์‘์„ ํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ๋‹ค. ๊ทธ๋ƒฅ โ€œ์–ด? ์ด ์ด๋ฏธ์ง€, ์ด ํƒœ๊ทธ ์ง€๊ธˆ ๋ชป ์”€. ์ˆ˜๊ณ ์š”.โ€ ์ •๋„ ๋งํ•ด์ค„ ๋ฟ์ด๋‹ค.

Pod์„ ๋„์šธ ๋‹น์‹œ์—๋Š” ํ•ด๋‹น Image Registry์— ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ ์ƒํƒœ์˜€๋Š”๋ฐ, ์ž ์‹œ Registry์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•ด๋„ ์•Œ๋žŒ์ด ๊ฐ„๋‹ค. ์‚ฌ์‹ค Pod์„ ๋„์›Œ์„œ ์ž˜ ๋Œ๊ณ  ์žˆ๊ณ , ๋‹น์žฅ ๋‹ค์‹œ ๋„์šธ ์˜ˆ์ •๋„ ์—†๋‹ค๋ฉด, ์ด๋ฏธ ์ž˜ ๋„๋Š” Pod์˜ Image Availability๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•  ํ•„์š˜ ๊ฑฐ์˜ ์—†๋‹ค. ์ž ์‹œ ์žฅ์• ๊ฐ€ ์ƒ๊ฒจ๋„ ๊ทธ๋“ค๋„ ๊ธˆ๋ฐฉ ๋ณต๊ตฌํ•˜๊ฒŒ ๋œ๋‹ค. (์‚ฌ์‹ค ๊ทธ์ชฝ์—์„œ ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด, ์šฐ๋ฆฐ ๋ณต๊ตฌ ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ˆ˜ ๋ฐ–์— ์—†๋‹คโ€ฆ ใ…‹ใ…‹ใ…‹ ใ… ใ… )

๋˜, ๋„์šฐ๋ ค๋Š” Pod์˜ ์ด๋ฏธ์ง€๊ฐ€ unavailable ํ•˜๋‹ค๋ฉด ๋ถ„๋ช… ImagePullBackoff ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”๋ฐ, ๋ณดํ†ต ์ด๋Ÿฌ๋ฉด Pod ๋„์šฐ๋Š” ์‚ฌ๋žŒ์ด๋‚˜ K8s ํด๋Ÿฌ์Šคํ„ฐ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜๋Š” ์‚ฌ๋žŒ์ด ๋จผ์ € ๋ฐœ๊ฒฌํ•˜๊ณ  ๋Œ€์‘ํ•œ๋‹ค.

์ด ๋…€์„ ์ง„์งœ ๋ณ„๋ก ๊ฐ€โ€ฆ?

๋†‰, ๊ทธ๊ฑด ์•„๋‹Œ ๊ฒƒ ๊ฐ™๋‹ค. ์ฒ˜์Œ ์š” Exporter๊ฐ€ ๊ณต๊ฐœ๋˜์—ˆ์„ ๋•Œ ๊ธฐ๋ผˆํ•œ ์‚ฌ๋žŒ๋„ ์žˆ๋‹ค.

quay.io๋ฅผ ์œ„ํ•œ Exporter๊ฐ€ ๋“ฑ์žฅํ–ˆ๋‹ค๊ณ  ์ข‹์•„ํ•œ ์‚ฌ๋žŒ๋„ ์žˆ๋‹ค ใ…‹ใ…‹ ๋ณธ์ธ์€ ๊ฑฐ์˜ ์“ด ์ ์ด ์—†๋Š”๋ฐ, quay.io๋„ Dockerhub, ECR ์ฒ˜๋Ÿผ Image Registry ์ค‘ ํ•˜๋‚˜๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์ข€โ€ฆ ์žฅ์• ๊ฐ€ ๋งŽ์€ ๊ฒƒ ๊ฐ™์€โ€ฆ ๊ทธ๋Ÿฐ Registry์ธ ๊ฒƒ ๊ฐ™๋‹ค ใ…‹ใ…‹

๋ณธ์ธ ํŒ€์—์„œ K8s iae exporter๋ฅผ ๊ฒ€ํ† ํ•˜๊ฒŒ ๋œ ์ด์œ ๋„ quay.io์˜ ์žฆ์€ ์žฅ์•  ๋•Œ๋ฌธ์ด์—ˆ๋‹คโ€ฆ ใ…‹ใ…‹

์–ด์จ‹๋“  Registry ๋ชจ๋‹ˆํ„ฐ๋ง ์ธก๋ฉด์—์„  ์œ ์šฉ์„ฑ์ด ์žˆ์œผ๋‹ˆ, ํ•„์š”ํ•˜๋‹ค๋ฉด ํ•œ๋ฒˆ ์‚ฌ์šฉํ•ด๋ณด์ž!

์ด๊ฑธ ๊ฐœ๋ฐœํ•œ deckhouse์— ๋Œ€ํ•ด์„œ

์š” k8s iae exporter๋Š” deckhouse๋ž€ ํšŒ์‚ฌ์—์„œ ๊ฐœ๋ฐœํ–ˆ๋Š”๋ฐ, โ€œNoOps Kubernetes platformโ€๋ผ๋Š” ์Šฌ๋กœ๊ฑด์œผ๋กœ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋‹ค.

์‚ฌ์ดํŠธ์— ๋“ค์–ด๊ฐ€์„œ ์‚ดํŽด๋ณด๋ฉด, K8s ํด๋Ÿฌ์Šคํ„ฐ ์šด์˜๊ณผ ๊ด€๋ฆฌ ์„œ๋น„์Šค๋ฅผ ์ „๋ฌธ์ ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค. spark cluster๋ฅผ ์‰ฝ๊ฒŒ ์šด์˜/๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด Databricks๋ฅผ ์ฑ„ํƒํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ, K8s ํด๋Ÿฌ์Šคํ„ฐ ์†”๋ฃจ์…˜์„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ ๊ฐ™์•˜๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, AWS EKS๋ฅผ ์šด์˜ํ•  ๋•Œ๋„ csi provider๋ฅผ ์ง์ ‘ ๊ด€๋ฆฌํ•˜๊ฒŒ ๋˜๋Š”๋ฐ, deckhouse ์†”๋ฃจ์…˜์€ ๊ทธ๋Ÿฐ ํด๋Ÿฌ์Šคํ„ฐ ์šด์˜์— ํ•„์š”ํ•œ provider๋ฅผ ์ž๋™์œผ๋กœ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ๊ฒƒ ๊ฐ™์•˜๋‹ค. ๊ทธ๋Ÿฐ ๊ฒƒ๋“ค ์ง์ ‘ ๊ด€๋ฆฌํ•˜๋ฉด์„œ ์žฅ์•  ํ•œ๋ฒˆ ๋‚˜๋ด์•ผ ์‹ค๋ ฅ์ด ๋งŽ์ด ๋Š๋Š”๋ฐโ€ฆ ใ…‹ใ…‹

Kubernetes is an extremely dynamic system. When operating the infrastructure in the K8s cluster, we always assume that any pod (or even a node!) might be deleted at any moment. To improve resilience, we are testing the system using various chaos engineering approaches. Mainly, we randomly kill Kubernetes nodes to see whether our applications are ready for pod restarts.

์™œ ์ด๋Ÿฐ ์ง“์„ ํ•˜๋Š”์ง€โ€ฆ ์•”ํŠผ ์—ฌ๋Ÿฌ ํšŒ์‚ฌ์˜ K8s ์šด์˜ ํ•ด๋ดค์„ ํ…Œ๋‹ˆ, ์—ฌ๋Ÿฌ ๋ฌธ์ œ์™€ ์—ฌ๋Ÿฌ ๊ณ ๋ฏผ๋“ค์„ ํ•ด๊ฒฐํ•œ ํšŒ์‚ฌ๋ผ๊ณ  ์ƒ๊ฐํ•œ๋‹ค. k8s iae exporter๋„ ๋งŒ๋“ค๊ฑธ ๋ณด๋ฉด K8s์— ๋Œ€ํ•ด์„  ์ „๋ฌธ๊ฐ€ ์ผ ๊ฒƒ ๊ฐ™๋‹ค.

์ฐธ๊ณ ์ž๋ฃŒ

Categories:

Updated: