Istio์˜ ๊ณต์‹ ์˜ˆ์ œ ๋”ฐ๋ผ์„œ ์‹ค์Šตํ•ด๋ณด๊ธฐ. ๐Ÿ“š

4 minute read

์ด๋ฒˆ ํฌ์ŠคํŠธ์—์„  Istio ๊ณต์‹ ๋ฌธ์„œ๋กœ ๋‚˜์™€์žˆ๋Š” Bookinfo ์˜ˆ์ œ๋ฅผ ๋”ฐ๋ผ์„œ ์‹ค์Šต ํ•ด๋ณด๊ณ , ๊ทธ ๊ณผ์ •์„ ์ •๋ฆฌํ•ด๋ณด๊ณ ์ž ํ•œ๋‹ค. ๐Ÿ“š

์ผ๋‹จ book info ์˜ˆ์ œ์˜ ์ „์ฒด ๊ตฌ์กฐ๋Š” ์š”๋ ‡๋‹ค.

์ผ๋‹จ ๋„์šฐ๊ณ  ๋ณด์ž

kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/bookinfo/platform/kube/bookinfo.yaml

๋ญ”๊ฐ€๊ฐ€ ์ž”๋œฉ ๋–ด๋‹ค!

Bookinfo๋Š” ์ผ์ข…์˜ โ€œ์›น์•ฑโ€œ์ด๋‹ค. ์™ธ๋ถ€์—์„œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก IngressGateway ๋ฆฌ์†Œ์Šค์™€ ๋ฌผ๋ ค๋ณด์ž. ์•„๋ž˜์˜ ์ปค๋งจ๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด, Gateway์™€ VirtualService ๋ฆฌ์†Œ์Šค๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/bookinfo/networking/bookinfo-gateway.yaml

Gateway ๋ฆฌ์†Œ์Šค๋Š” istio์˜ default IngressGateway์ธ isito-ingressgateway์™€ ๋ฌผ๋ ค์žˆ๋‹ค.

ํ•ด๋‹น default IngressGateway๋Š” LoadBalancer ํƒ€์ž…์˜ K8s Service๋กœ ๋…ธ์ถœ๋œ๋‹ค.

ํ•ด๋‹น K8s Service์˜ EXTERNAL-IP์ธ 192.168.64.2์— ์ ‘์† ํ•ด๋ณด์ž!

์™€!! ์›น์•ฑ์— ์ ‘์†ํ–ˆ๋‹ค!!

kiali๋กœ ํ™•์ธํ•˜๋ฉด, ์ „์ฒด ๊ตฌ์กฐ๊ฐ€ ํ•œ๋ˆˆ์— ๋“ค์–ด์˜จ๋‹ค!

์ „์ฒด ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ตฌ์กฐ๋ฅผ ๋‹ค์‹œ ๋ณด๋ฉด, ๋ฆฌ๋ทฐ ํ•ญ๋ชฉ์„ ๋ณด์—ฌ์ฃผ๋Š” ๋ถ€๋ถ„์ด 3๊ฐœ์˜ ๋ฒ„์ „์œผ๋กœ ๋‚˜๋ˆ ์ ธ ์žˆ๋‹ค. ๊ทธ๋ž˜์„œ ํŽ˜์ด์ง€๋ฅผ ์ƒˆ๋กœ๊ณ ์นจ(refresh) ํ•  ๋•Œ๋งˆ๋‹ค ์•„๋ž˜ 3๊ฐ€์ง€ ๋ทฐ๊ฐ€ ๋ฒˆ๊ฐˆ์•„๊ฐ€๋ฉฐ ๋ณด์ธ๋‹ค.

  • ๋ณ„์ ์ด ์—†๋Š” ๋ทฐ
  • ๋ณ„์ ์ด ์žˆ์œผ๋‚˜ ๊ฒ€์€์ƒ‰์œผ๋กœ ํ‘œ์‹œ๋˜๋Š” ๋ทฐ
  • ๋ณ„์ ์ด ์žˆ์œผ๋‚˜ ๋ถ‰์€์ƒ‰์œผ๋กœ ํ‘œ์‹œ๋˜๋Š” ๋ทฐ

์ด๋ฒˆ์—๋Š” ๋ณ„์ ์ด ๋ถ‰์€์ƒ‰์œผ๋กœ ๋ณด์ธ๋‹ค!

๋ฒ„์ „๋ณ„ ํŠธ๋ž˜ํ”ฝ ์ œ์–ดํ•˜๊ธฐ

์ด๋ฒˆ์—๋Š” istio์˜ DestinationRule๊ณผ VirtualService๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์•ฑ ๋ฒ„์ „๋ณ„๋กœ ํŠธ๋ž˜ํ”ฝ์„ ๋ถ„์‚ฐํ•˜๊ณ  ์ œ์–ดํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค.

์šฐ์„  DestinationRule ๋ฆฌ์†Œ์Šค๋ฅผ ๋จผ์ € ์ƒ์„ฑํ•˜์ž. ๋‚ด์šฉ์€ ๋ณ„๊ฑฐ ์—†๊ณ  ๊ทธ๋ƒฅ ์•ฑ ๋ฒ„์ „๋ณ„ subset๋งŒ ๋ถ„๋ฆฌ๋˜์–ด ์žˆ๋‹ค.

kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/bookinfo/networking/destination-rule-all.yaml

๊ฐ Service ์—”๋“œํฌ์ธํŠธ ๋ณ„ DestinationRule ๋ฆฌ์†Œ์Šค๊ฐ€ ์ž˜ ์ƒ์„ฑ ๋˜์—ˆ๋‹ค!!

์ด์ œ๋ถ€ํ„ฐ๋Š” istio์˜ Traffic Management / Request Routing ๋ฌธ์„œ๋ฅผ ๋ณด๋ฉฐ, ๋ฒ„์ „๋ณ„ ํŠธ๋ž˜ํ”ฝ์„ ์ œ์–ด ํ•ด๋ณด์ž.

์ „๋ถ€ v1์— ๋ผ์šฐํŒ…

์•„๋ž˜ ์ปค๋งจ๋“œ๋กœ ์ „๋ถ€ v1์œผ๋กœ ๋ณด๋‚ด๋Š” VirtualService๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/bookinfo/networking/virtual-service-all-v1.yaml

์ด๋ ‡๊ฒŒ ํ•˜๊ณ , ๋‹ค์‹œ ์›น์•ฑ์— ์ ‘์†ํ•ด๋ณด๋ฉด, ๋ฆฌ๋ทฐ๋งŒ ๋ณด์ผ ๋ฟ ๋”์ด์ƒ ๋ณ„์  ์ •๋ณด๋Š” ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค.

Kiali๋กœ ํ™•์ธํ•ด๋ด๋„, Reviews ์›Œํฌ๋กœ๋“œ์—์„œ v1์œผ๋กœ๋งŒ ํŠธ๋ž˜ํ”ฝ์ด ํ๋ฅด๊ณ  ์žˆ๋‹ค!

๋กœ๊ทธ์ธ ์ •๋ณด ์žˆ๋Š” ์œ ์ €์—๊ฒ v2๋กœ ๋ผ์šฐํŒ…

๋†€๋ž๊ฒŒ๋„!! bookinfo ์˜ˆ์ œ์—๋Š” ๋กœ๊ทธ์ธ ๊ธฐ๋Šฅ๋„ ๊ตฌํ˜„๋˜์–ด ์žˆ๋‹ค!! (,,โŸกoโŸก,,)

์šฐ์ธก ์ƒ๋‹จ์˜ Sign in ๋ฒ„ํŠผ์œผ๋กœ ๋กœ๊ทธ์ธ ์ฐฝ์„ ๋„์›Œ์„œ ID/PW ๋‘˜๋‹ค jason์œผ๋กœ ์ ‘์†ํ•˜๋ฉด ๋กœ๊ทธ์ธ์ด ๋œ๋‹ค!!

์šฐ๋ฆฐ ๋กœ๊ทธ์ธํ•œ ์œ ์ €์—๊ฒŒ๋Š” Review์— ๋ณ„์ (rating)์ด ํ•จ๊ป˜ ๋ณด์ด๋„๋ก ํ•˜๊ณ  ์‹ถ๋‹ค. ๊ทธ๋Ÿฌ๊ธฐ ์œ„ํ•ด์„œ ์•„๋ž˜์™€ ๊ฐ™์ด Request Header ๊ธฐ๋ฐ˜์œผ๋กœ routing ํ•˜๋Š” VirtualService ๋ฆฌ์†Œ์Šค๋ฅผ ์ถ”๊ฐ€ํ•ด๋ณด์ž!

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
  hosts:
  - reviews
  http:
  - match:
    - headers:
        end-user:
          exact: jason
    route:
    - destination:
        host: reviews
        subset: v2
  - route:
    - destination:
        host: reviews
        subset: v1
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml

์™€์šฐ! ์œ ์ € jason์€ ์ด์ œ ๋ฆฌ๋ทฐ์˜ ๋ณ„์  ์ •๋ณด๋„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๋‹ค!!

Kiali๋กœ ํ™•์ธํ•ด๋ณด๋ฉด, ์ด์   v2๋กœ๋„ ํŠธ๋ž˜ํ”ฝ์ด ๊ฐ€๊ณ  ์žˆ๋‹ค!


๋งบ์Œ๋ง

์•ผํ˜ธ~~~ ์ด๊ฒƒ์œผ๋กœ Istio์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ์˜ˆ์ œ์ธ bookinfo ์˜ˆ์ œ๋ฅผ ๋ง›๋ณด๊ธฐ ํ–ˆ๋‹ค (ใฃห˜ฺกห˜ฯ‚)

์ฒ˜์Œ์—๋Š” ์˜ˆ์ œ๋„ ์–ด๋ ค์›Œ ๋ณด์˜€๋Š”๋ฐ, ๋ง‰์ƒ ํ•˜๋ผ๋Š” ๋Œ€๋กœ ํ•ด๋ณด๋‹ˆ ๋ณ„๋กœ ์•ˆ ์–ด๋ ค์› ๋˜ ๊ฒƒ ๊ฐ™๋‹ค ใ…‹ใ…‹ ํŠนํžˆ Kiali๋กœ ๋„คํŠธ์›Œํฌ Topology๋ฅผ ๋ฐ”๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์„œ ๊ตฌ์กฐ๋ฅผ ์ดํ•ดํ•˜๋Š”๋ฐ ๋„ˆ๋ฌด๋„ˆ๋ฌด๋„ˆ๋ฌด ํŽธํ–ˆ๋‹ค!!

์ด์   Istio ์ž๊ฒฉ์ฆ ์‹œํ—˜ ์ค€๋น„ํ•˜๋ฉด์„œ ์กฐ๊ธˆ ๊นŠ๊ฒŒ ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ๋“ค์„ ๋ธ”๋กœ๊ทธ์— ์ •๋ฆฌํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค ใ…Žใ…Ž


(๋ถ€๋ก) ํ•œ๋ฒˆ์— bookinfo ๋„์šฐ๊ณ /๋‚ด๋ฆฌ๊ธฐ

bookinfo ์˜ˆ์ œ๋Š” ์‹œ๊ฐ์ ์ด๊ธฐ๋„ ํ•˜๊ณ , ๊ฐ„๋‹จํ•˜๊ฒŒ MSA ๊ตฌ์กฐ๋ฅผ ๋„์›Œ๋ณผ ์ˆ˜ ์žˆ๋Š” ์˜ˆ์ œ๋ผ์„œ istio ๋ฌธ์„œ์—์„œ istio์˜ ๊ธฐ๋Šฅ์„ ์†Œ๊ฐœํ•  ๋•Œ ์š” bookinfo ์˜ˆ์ œ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์„ค๋ช…ํ•˜๋Š” ๊ฒƒ๋“ค์ด ๊ฝค ์žˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค๋ฉด, ์ด๋ ‡๊ฒŒ ๋‚˜์˜จ๋‹ค (istio์˜ Fault Injection ๋ฌธ์„œ์˜ ํ•œ ๋ถ€๋ถ„)

๊ทธ๋ž˜์„œ bookinfo ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋„์›Œ๋‘๊ณ  ์ด๋Ÿฐ ๊ธฐ๋Šฅ๋“ค์„ ์‹คํ—˜ํ•˜๊ณ  ์ตํžˆ๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์€๋ฐ, ํ•œ๋ฒˆ์— bookinfo ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋„์šฐ๊ณ , ๋˜ ๋‚ด๋ฆฌ๋Š” ์ปค๋งจ๋“œ๋ฅผ ์ •๋ฆฌํ•ด๋ดค๋‹ค.

# ๋„์šธ ๋•Œ
# istiod, istio-ingressgateway, kiali๋Š” ์ด๋ฏธ ๋–ด๋‹ค๊ณ  ๊ฐ€์ •
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/bookinfo/platform/kube/bookinfo.yaml
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/bookinfo/networking/destination-rule-all.yaml

# ๋‚ด๋ฆด ๋•Œ
$ kubectl delete -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/bookinfo/networking/destination-rule-all.yaml
$ kubectl delete -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/bookinfo/platform/kube/bookinfo.yaml