non-kubernetes ์›Œํฌ๋กœ๋“œ๋ฅผ Istio ์„œ๋น„์Šค ๋ฉ”์‰ฌ์— ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•. WorkloadEntry์™€ WorkloadGroup์œผ๋กœ VM ์›Œํฌ๋กœ๋“œ ๊ด€๋ฆฌํ•˜๊ธฐ! ๐Ÿค

6 minute read

์†”์งํžˆ ์ด ๋ถ€๋ถ„์€ ์ œ๋Œ€๋กœ ์ดํ•ด ๋ชป ํ–ˆ์Šต๋‹ˆ๋‹ค ใ… ใ…  ์ง์ ‘ ์‹ค์Šต ํ•ด๋ณด๊ธฐ๋„ ์–ด๋ ค์šด ์ฃผ์ œ๋ผ์„œ ์ผ๋‹จ Istio์—์„œ ์ œ๊ณตํ•œ ๋ฌธ์„œ๋“ค์„ ๊ผผ๊ผผํžˆ ๊ทธ๋ฆฌ๊ณ  ์ถฉ์‹คํžˆ ์ฝ๊ณ  ์ œ๊ฐ€ ์ดํ•ดํ•œ ๊ฑธ ์ตœ๋Œ€ํ•œ ์„ค๋ช…ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ํ˜น์‹œ๋‚˜ ์˜ค๋ฅ˜๋‚˜ ๋ณด์ถฉ์ด ํ•„์š”ํ•œ ๋ถ€๋ถ„์„ ๋ฐœ๊ฒฌํ•˜์‹ ๋‹ค๋ฉด ์•Œ๋ ค์ฃผ์‹ฌ ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ™

Istio๋Š” ์‹ ๊ธฐํ•˜๊ฒŒ๋„ ์„œ๋น„์Šค ๋ฉ”์‰ฌ๋ฅผ K8s ํด๋Ÿฌ์Šคํ„ฐ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ non-kubernetes ์›Œํฌ๋กœ๋“œ๊นŒ์ง€ ์ง€์›์„ ํ•œ๋‹ค!! Istio ๋ฌธ์„œ์—์„œ๋Š” ์ด๋Ÿฐ non-kubernetes ์›Œํฌ๋กœ๋“œ์˜ ํ™˜๊ฒฝ์„ โ€œVirtual Machineโ€œ(์ดํ•˜ VM)๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

์ฒ˜์Œ์—๋Š” โ€˜k8s ํด๋Ÿฌ์Šคํ„ฐ ๋ฐ”๊นฅ์˜ ์›Œํฌ๋กœ๋“œ๊นŒ์ง€ ์‹ ๊ฒฝ ์“ฐ๋Š”๊ฑด ๋‡Œ์ ˆ ์•„๋‹ˆ์•ผ?โ€™๋ผ๊ณ  ์ƒ๊ฐ ํ–ˆ๋Š”๋ฐ, ์ฒœ์ฒœํžˆ ๋ฌธ์„œ๋ฅผ ์ฝ์–ด๋ณด๋‹ˆ ์•„๋ฌด๋ฆฌ K8s๊ฐ€ ์ข‹์•„๋„ ์–ด๋–ค ์ปดํฌ๋„ŒํŠธ๋Š” ๋ณด์•ˆ์ด๋‚˜ ๊ทœ์ œ ๋•Œ๋ฌธ์— K8s ํ™˜๊ฒฝ์—์„œ ์šด์˜ํ•˜์ง€ ๋ชปํ•˜๊ณ , Virtual Machine์—์„œ ์šด์˜ํ•  ์ˆ˜ ๋ฐ–์— ์—†๋Š” ์ƒํ™ฉ ์ƒ๊ธธ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋‹ค. Istio๋Š” ์ด๋Ÿฐ ์ƒํ™ฉ๊นŒ์ง€ ๊ณ ๋ คํ•œ ๊ฒƒ!!

์ƒ๊ฐํ•ด๋ณด๋‹ˆ ์šธ ํšŒ์‚ฌ๋„ DB๋‚˜ Kafka ๊ฐ™์€ ์„œ๋น„์Šค๋Š” K8s๊ฐ€ ์•„๋‹ˆ๋ผ ๋ณ„๋„์˜ managed ์„œ๋น„์Šค์— ๋„์›Œ์„œ ์šด์˜ํ•˜๊ณ  ์žˆ๊ธฐ ํ•˜๋„คโ€ฆ

Bookinfo with a Virtual Machine

Istio์—์„œ VM Architecture๋ฅผ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด ์นœ์ ˆํžˆ ์˜ˆ์ œ๋„ ๋งˆ๋ จํ•ด๋’€๋‹ค. istio ์œ„์˜ ๊ทธ๋ฆผ์— ๋”ฐ๋ฅด๋ฉด โ€œMySQLโ€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋งŒ K8s ๋ฐ”๊นฅ์˜ VM์—์„œ ๋Œ๋ฆฌ๊ณ  ์žˆ๋‹ค.

Virtual Machine Installation

https://istio.io/latest/docs/setup/install/virtual-machine/

๊ทธ๋ฆผ์—์„œ๋„ ๋ณด์ด๋“ฏ istio๊ฐ€ VM ์›Œํฌ๋กœ๋“œ๋ฅผ ์„œ๋น„์Šค ๋ฉ”์‰ฌ์— ํ†ตํ•ฉํ•˜๊ธฐ ์œ„ํ•ด์„  VM ์›Œํฌ๋กœ๋“œ์—๋„ istio๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค!! (์—ญ์‹œ ๊ทธ๋ƒฅ ๋˜๋Š”๊ฒŒ ์•„๋‹ˆ๋‹คโ€ฆ ใ…‹ใ…‹)

์ผ๋‹จ VM์— ์ „๋‹ฌํ•  Istio ์„œ๋น„์Šค๋ฉ”์‰ฌ์˜ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•œ๋‹ค. ์ด๋•Œ, Istio์˜ WorkloadGroup ๋ฆฌ์†Œ์Šค๊ฐ€ ํ•„์š”ํ•œ๋ฐ, ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋’ค์—์„œ ์ข€๋” ์ƒ์„ธํžˆ ๋‹ค๋ฃจ๊ฒ ๋‹ค.

์•”ํŠผ WorkloadGroup์ด ์ƒ์„ฑ๋œ ์ƒํƒœ๋ผ๋ฉด, isitoctl x workload entry configure ... ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด VM์— ์ „๋‹ฌํ•  Istio ์„œ๋น„์Šค๋ฉ”์‰ฌ ์ •๋ณด๊ฐ€ ๋‹ด๊ธด ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ๊ฐ์ข… ํŒŒ์ผ๋“ค์„ VM ์ชฝ์œผ๋กœ ์˜ฎ๊ฒจ์ค€๋‹ค.

VM์— istio์˜ VM integration runtime์„ ์„ค์น˜ํ•ด์ค€๋‹ค.

curl -LO https://storage.googleapis.com/istio-release/releases/1.21.0/deb/istio-sidecar.deb
sudo dpkg -i istio-sidecar.deb

VM์— istio runtime๋ฅผ ๋™์ž‘์‹œํ‚จ๋‹ค.

sudo systemctl start istio

์ด๋ ‡๊ฒŒ VM ์ชฝ์— istio runtime์„ ๋Œ๋ฆฌ๊ฒŒ ๋˜๋ฉด, k8s ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ํ•˜๋˜ ๊ฒƒ์ฒ˜๋Ÿผ CoreDNS์˜ FQDN์œผ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด ๊ทธ๊ฑธ istio runtime์ด ์•Œ์•„๋“ฃ๊ณ  ์ž˜ ๋ผ์šฐํŒ… ํ•ด์ค€๋‹ค๊ณ  ํ•œ๋‹ค!!

# VM์—์„œ k8s ๋„คํŠธ์›Œํฌ์˜ ์›Œํฌ๋กœ๋“œ๋กœ ์š”์ฒญ!!
$ curl helloworld.sample.svc:5000/hello
Hello version: v1, instance: helloworld-v1-578dd69f69-fxwwk

์ง„์งœ ์‹ ๊ธฐํ•˜๋‹ค!!

์ด์ œ ๋ฐ˜๋Œ€๋กœ K8s์—์„œ VM์— ์žˆ๋Š” mysql์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„  ์•„๋ž˜์™€ ๊ฐ™์ด K8s svc๋ฅผ ๋งŒ๋“  ํ›„, ์ ‘๊ทผํ•˜๋ฉด ๋œ๋‹ค.

apiVersion: v1
kind: Service
metadata:
  name: mysqldb
  namespace: vm
  labels:
    app: mysqldb
spec:
  ports:
  - port: 3306
    name: tcp
  selector:
    app: mysqldb
$ k exec -it ... -- sh
~ $ mysql -h http://mysqldb.vm.svc.cluster.local ...

VM Service Association

์•ž์—์„œ istioctl x workload entry configure ... ๋ช…๋ น์–ด๋กœ VM์— ์ „๋‹ฌํ•  istio ์„œ๋น„์Šค ๋ฉ”์‰ฌ ์ •๋ณด๊ฐ€ ๋‹ด๊ธด ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค๋Š” ๊ฒƒ ๊ธฐ์–ตํ•˜๋Š”๊ฐ€? ์ด๋•Œ, Istio์˜ WorkloadEntry ๋˜๋Š” WorkloadGroup์ด ํ•„์š”ํ•˜๋‹ค๊ณ  ๋งํ–ˆ๋Š”๋ฐ, ์ด ๋ฆฌ์†Œ์Šค๊ฐ€ ๋ญ”์ง€ ์‚ดํŽด๋ณด์ž.

์ผ๋‹จ WorkloadEntry์™€ WorkloadGroup ๋‘˜๋‹ค Istio์—์„œ VM workload๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ๋ฆฌ์†Œ์Šค์ด๋‹ค. Istio ๋ฌธ์„œ์—์„œ๋Š” ๋‘˜์ด ๊ฐ๊ฐ K8s Pod๊ณผ K8s Deployment์— ๋Œ€์‘๋œ๋‹ค๊ณ  ์†Œ๊ฐœํ•˜๊ณ  ์žˆ๋‹ค. WorkloadGroup๋ฅผ ์žฌ๋ฃŒ๋กœ istioctl x workload entry configure ...์—์„œ ์„œ๋น„์Šค๋ฉ”์‰ฌ ์ •๋ณด ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ , ์‹ค์ œ VM์ด ์„œ๋น„์Šค ๋ฉ”์‰ฌ์— ์ถ”๊ฐ€๋˜๋ฉด WorkloadEntry ๋ฆฌ์†Œ์Šค๊ฐ€ ์ž๋™์œผ๋กœ ๋œจ๊ฒŒ ๋œ๋‹ค๊ณ  ํ•œ๋‹ค!! (์‹ ๊ธฐ์‹ ๊ธฐ)

WorkloadGroup ๋งŒ๋“ค๊ธฐ

์ผ๋‹จ WorkloadGroup ๋ฆฌ์†Œ์Šค๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€ istioctl x workload๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๊ณผ ๊ทธ๋ƒฅ yaml ํŒŒ์ผ ๋งŒ๋“ค์–ด์„œ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ 2๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

istioctl๋กœ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

istioctl x workload group create \
    --name product-vm \
    --namespace default \
    --labels app=product \
    --ports http=8080 \
    --serviceAccount default
---
# WorkloadGroup์ด ์ƒ์„ฑ๋˜์ง„ ์•Š๊ณ , yaml๋งŒ ํ”„๋ฆฐํŠธ ํ•ด์ค€๋‹ค!
apiVersion: networking.istio.io/v1alpha3
kind: WorkloadGroup
metadata:
  name: product-vm
  namespace: default
spec:
  metadata:
    labels:
      app: product
  template:
    ports:
      http: 8080
    serviceAccount: default

์™€์šฐ! ๋ฐ”๋กœ yaml ํŒŒ์ผ์ด ์ถœ๋ ฅ ๋๋‹ค!! ์ €๊ฑธ ๊ทธ๋Œ€๋กœ ์ €์žฅํ•˜๊ณ  ๋งŒ๋“ค๊ธฐ๋งŒ ํ•˜๋ฉด ๋œ๋‹ค ใ…Žใ…Ž

VM์„ ์ถ”๊ฐ€ํ•˜๋ฉด WorkloadEntry ๋ฆฌ์†Œ์Šค๊ฐ€ ์ƒ์„ฑ

์•”ํŠผ ์œ„์—์„œ ๋งŒ๋“  WorkloadGroup์œผ๋กœ VM์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋Œ€์‘ํ•˜๋Š” WorkloadEntry๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค!!

apiVersion: networking.istio.io/v1beta1
kind: WorkloadEntry
metadata:
  annotations:
    istio.io/autoRegistrationGroup: product-vm # ๋งŒ๋“ค์—ˆ๋˜ ๊ฒƒ!
  labels:
    app: product
  name: product-vm-1.2.3.4
spec:
  address: 1.2.3.4 # ์ž๋™์œผ๋กœ ๋‹ด๊ธด!
  labels:
    app: product
  serviceAccount: default

์ด๋ ‡๊ฒŒ ๋งŒ๋“  WorkloadEntry์— ์ ‘๊ทผํ•˜๋ ค๋ฉด K8s Service๋ฅผ ๋งŒ๋“ค์–ด์„œ ์ฃผ๋ฉด ๋œ๋‹ค.

์ด๋•Œ, ์‹ ๊ธฐํ•œ ์ ์€ K8s Service๋ฅผ ๋งŒ๋“ค ๋•Œ, K8s Pod์ด๋ž‘ VM workload๋ž‘ ๊ฐ™์ด ๋ฌถ์„ ์ˆ˜๋„ ์žˆ๋‹ค๋Š” ๊ฑฐ๋‹ค!!

K8s Svc๊ฐ€ ์ด๋ ‡๊ฒŒ ๊ตฌ์„ฑ๋˜๋ฉด, ํŠธ๋ž˜ํ”ฝ์€ K8s Pod๊ณผ Istio WorkloadEntry์— ๋‘ ๊ณณ์— ๋ผ์šฐํŒ… ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค!! (๋†€๋ผ์›Œ!!)

์ด๊ฑธ ๊ณต๋ถ€ํ•ด์•ผ ํ•˜๋‚˜?

์•„๋†” ์ด๊ฑธ ๊ณต๋ถ€ํ•ด์•ผ ํ•˜๋‚˜ ๋ง์•„์•ผ ํ•˜๋‚˜ ๊ณ ๋ฏผ์„ ์ข€ ํ–ˆ๋Š”๋ฐ, ICA ์‹œํ—˜์˜ ์‹œํ—˜ ์ฃผ์ œ ๋ชฉ๋ก์— โ€œnon-kubernetes ์›Œํฌ๋กœ๋“œ์— ๋Œ€ํ•ด์„œ๋„ ๋ฌผ์–ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹คโ€๋ผ๊ณ  ์ ํ˜€์žˆ์–ด์„œ ์ด ์•…๋ฌผ๊ณ  ๊ณต๋ถ€ํ–ˆ๋‹คโ€ฆ ๐Ÿ˜ฌ

์ฐธ๊ณ ์ž๋ฃŒ