Skip to content

Spring Pet Clinic Example runs on IBM Cloud Kubernetes Service (IKS)

Notifications You must be signed in to change notification settings

hongjsk/spring-petclinic-kubernetes

Repository files navigation

Kubernetes์—์„œ ์‹คํ–‰๋˜๋Š” Spring PetClinic Microservice ์˜ˆ์ œ

์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ฝ”๋“œ๋Š” Spring PetClinic Microservices version์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ค. Spring Cloud Netflix๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ตฌ์„ฑ๋œ ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค๋ฅผ Kubernetes์—์„œ ์‹คํ–‰ํ•˜๋„๋ก ๋ช‡ ๊ฐ€์ง€ ์˜์กด์„ฑ๊ณผ ์ฝ”๋“œ๋ฅผ ์ œ๊ฑฐํ•  ๋ฟ ์ตœ๋Œ€ํ•œ ์›๋ณธ ์ฝ”๋“œ๋ฅผ ์œ ์ง€ํ•œ ํ˜•ํƒœ๋กœ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ๊ตฌ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๋ณธ ๋ฌธ์„œ๋Š” Kuberentes์—์„œ ์‹คํ–‰ ๋ฐ ๋ฐฐํฌ๋ฅผ ์œ„ํ•œ ๋‚ด์šฉ์— ๋Œ€ํ•œ ๊ฒƒ์„ ์„ค๋ช…ํ•˜๋ฉฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜์— ๋Œ€ํ•œ ์ •๋ณด๋Š” Migration.md๋ฅผ ์ฐธ๊ณ  ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋นŒ๋“œ ๋ฐ ๋ฐฐํฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‹จ๊ณ„๋กœ ์ง„ํ–‰ ํ•ฉ๋‹ˆ๋‹ค.

์ค€๋น„ ์‚ฌํ•ญ

Kubernetes ์‹คํ–‰ ํ™˜๊ฒฝ์€ ๊ฐœ๋ฐœ์šฉ์œผ๋กœ minikube๋ฅผ ์ด์šฉํ•˜๊ฑฐ๋‚˜, Public Cloud Vendor๊ฐ€ ์ œ๊ณตํ•˜๋Š” ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ Local VM์ด๋‚˜ Baremetal ์„œ๋ฒ„์— ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ ์ด์šฉ ํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜, ๋ณธ ๊ธ€์—์„œ๋Š” Kubernetes ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑ์— ๋ชฉ์ ์ด ์žˆ์ง€ ์•Š์œผ๋ฏ€๋กœ, IBM Cloud Kubernetes Service(์ดํ•˜ IKS)๋ฅผ ์ด์šฉํ•ด ๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. IKS๋Š” Kubernetes Cluster Control Plane์„ ์ž๋™์œผ๋กœ ๊ด€๋ฆฌํ•ด ์ฃผ๋ฏ€๋กœ ๊ฐœ๋ฐœ์ž๋Š” Kubernetes Node๋งŒ ์‹ ๊ฒฝ์“ฐ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, IKS์˜ Node๋ฅผ ํ•œ๊ตญ(ํŒ๊ตD/C)์— ์ƒ์„ฑ ํ•  ์ˆ˜ ์žˆ๋Š” ํฐ ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

IBM Cloud ํšŒ์› ๊ฐ€์ž…

IKS๋ฅผ ์ด์šฉํ•˜๋ ค๋ฉด ๋จผ์ € IBM Cloud ๊ณ„์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ, ํšŒ์› ๊ฐ€์ž…์„ ํ•˜์ง€ ์•Š์œผ์…จ๋‹ค๋ฉด, ์•„๋ž˜ URL์„ ํ†ตํ•ด ํšŒ์› ๊ฐ€์ž…์„ ํ•ด ์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

IBM Cloud ํšŒ์› ๊ฐ€์ž…

IBM Cloud ๊ณ„์ • ์—…๊ทธ๋ ˆ์ด๋“œ

ํšŒ์› ๊ฐ€์ž…์ด ๋๋‚ฌ๋‹ค๋ฉด, IBM Cloud ์‚ฌ์šฉ์„ ์œ„ํ•œ ์นด๋“œ ๋“ฑ๋ก์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์นด๋“œ ๋“ฑ๋ก์ด ์—†๋Š” ์ƒํƒœ์˜ trail ๊ณ„์ •์€ Kubernetes Node๋ฅผ ์ƒ์„ฑ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๊ฒฝ์šฐ์— ๋”ฐ๋ผ ์‹ ์šฉ์นด๋“œ ๋“ฑ๋ก์— ์ตœ๋Œ€ 2์ผ ์ •๋„๊ฐ€ ์†Œ์š”๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

IBM Cloud Kubernetes ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ

์นด๋“œ ๋“ฑ๋ก ์™„๋ฃŒ ํ›„ standard ๊ณ„์ •์œผ๋กœ ์—…๊ทธ๋ ˆ์ด๋“œ ๋˜์—ˆ๋‹ค๋ฉด, IBM Cloud Kubernetes ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

์ƒ์„ฑ ํ•  ์ˆ˜ ์žˆ๋Š” ํด๋Ÿฌ์Šคํ„ฐ ์ข…๋ฅ˜๋Š” Free์™€ Standard๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. Free ํด๋Ÿฌ์Šคํ„ฐ๋Š” ๋ฏธ๊ตญ Dallas์™€ ํ˜ธ์ฃผ Melbourne ์ค‘ ํ•œ ๊ณณ์„ ์„ ํƒํ•˜์—ฌ ๋ฌด๋ฃŒ๋กœ 1๊ฐœ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌด๋ฃŒ ํด๋Ÿฌ์Šคํ„ฐ๋Š” 2 CPUs, 4 GB RAM, 1 Worker Node๋กœ ๊ตฌ์„ฑ๋˜๋ฉฐ 30์ผ ๋™์•ˆ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์ผ๋ถ€ ๊ธฐ๋Šฅ ์‚ฌ์šฉ์— ์ œํ•œ์ ์ž…๋‹ˆ๋‹ค. ํ‘œ์ค€ ํด๋Ÿฌ์Šคํ„ฐ์™€ ์ฐจ์ด์ ์€ ๋ฌด๋ฃŒ ๋ฐ ํ‘œ์ค€ ํด๋Ÿฌ์Šคํ„ฐ ๋น„๊ต์„ ์ฐธ๊ณ  ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

์ด ์˜ˆ์ œ๋Š” ๊ณ ์„ฑ๋Šฅ ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ํ•„์š”ํ•œ ๊ฒƒ์€ ์•„๋‹ˆ์ง€๋งŒ, ํ•œ๊ตญ ๋ฐ์ดํ„ฐ ์„ผํ„ฐ๋ฅผ ์„ ํƒ ํ•  ์ˆ˜ ์žˆ๊ณ  Ingress ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•œ ์žฅ์ ์ด ์žˆ์–ด ์œ ๋ฃŒ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์„ค๋ช…ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ œ์ผ ์ €๋ ดํ•œ 2์ฝ”์–ด 4GB ๋ฉ”๋ชจ๋ฆฌ์˜ Shared VM์„ ์ด์šฉํ•˜์—ฌ 1๊ฐœ์˜ Worker Node๋งŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ 1์‹œ๊ฐ„์— 133์› ์ •๋„์˜ ๋น„์šฉ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ์ถ”๊ฐ€์ ์ธ IKS ๊ฐ€๊ฒฉ ์ •๋ณด๋Š” IBM Cloud Kubernetes ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑํ•˜๊ธฐ์—์„œ ์˜ˆ์ƒ ๊ธˆ์•ก์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ ์ด๋ฅผ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

ํ‘œ์ค€ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜๋ฉด ํ•ด๋‹น ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์™ธ๋ถ€์—์„œ ์ ‘์† ๊ฐ€๋Šฅํ•œ Ingress Subdomain ์ฃผ์†Œ๋ฅผ ๋ถ€์—ฌ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

<CLUSTER_NAME>.<DC_ZONE_NAME>.containers.appdomain.cloud

์˜ˆ๋ฅผ ๋“ค์–ด, ํด๋Ÿฌ์Šคํ„ฐ ์ด๋ฆ„์„ mycluster๋กœ ์ž‘์„ฑํ•˜๊ณ  ํ•œ๊ตญ์— ํ‘œ์ค€ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜์˜€๋‹ค๋ฉด,

mycluster.seo01.containers.appdomain.cloud

๋กœ ๋ถ€์—ฌ๋ฉ๋‹ˆ๋‹ค.

IBM Cloud CLI ์ค€๋น„

IKS๋Š” IBM Cloud์˜ ์„œ๋น„์Šค๋กœ์„œ IBM Cloud CLI๋ฅผ ์ด์šฉํ•˜์—ฌ ์ •๋ณด๋ฅผ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌผ๋ก  ์›น ๋Œ€์‹œ๋ณด๋“œ๋ฅผ ํ†ตํ•ด์„œ๋„ ํ™•์ธ์ด ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, Kubernetes CLI (kubectl) ์‚ฌ์šฉ์„ ์œ„ํ•œ ์ •๋ณด๊ฐ€ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ๋‚˜์˜ค๋Š” CLI ์„ค์ •์€ IBM Cloud ์ปจํ…Œ์ด๋„ˆ Dashboard์—์„œ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ CLI ๋ฐ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

curl -sL https://ibm.biz/idt-installer | bash

Windows 10 Pro ํ™˜๊ฒฝ์—์„œ๋Š” Windows PowerShell์„ ์ด์šฉ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์‹œ์ž‘ ๋ฉ”๋‰ด์—์„œ PowerShell์„ ๊ฒ€์ƒ‰ํ•˜์—ฌ ํŒŒ์ผ์„ ์ฐพ์€ ํ›„, ํ•ด๋‹น ํŒŒ์ผ์„ ๋งˆ์šฐ์Šค๋กœ ์˜ค๋ฅธ์ชฝ ํด๋ฆญํ•˜์—ฌ ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ , ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

Set-ExecutionPolicy Unrestricted; iex(New-Object Net.WebClient).DownloadString('http://ibm.biz/idt-win-installer')

IBM Cloud account์— ๋กœ๊ทธ์ธ ํ•ฉ๋‹ˆ๋‹ค.

ibmcloud login

IBM Cloud ์ปจํ…Œ์ด๋„ˆ์˜ ์„œ๋น„์Šค ์ง€์—ญ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

ibmcloud ks region-set <REGION>

Kubernetes ํ™˜๊ฒฝ ์„ค์ • ์ •๋ณด๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•ฉ๋‹ˆ๋‹ค.

ibmcloud ks cluster-config <CLUSTER_NAME>

KUBECONFIG ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

export KUBECONFIG=/Users/$USER/.bluemix/plugins/container-service/clusters/<CLUSTER_NAME>/kube-config-<DC_ZONE_NAME>-<CLUSTER_NAME>.yml

Windows ํ„ฐ๋ฏธ๋„ ํ™˜๊ฒฝ์—์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

SET KUBECONFIG=%HOMEPATH%\.bluemix\plugins\container-service\clusters\<CLUSTER_NAME>\kube-config-<DC_ZONE_NAME>-<CLUSTER_NAME>.yml

๋งŒ์•ฝ, Windows PowerShell์„ ์ด์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

$env:KUBECONFIG=$env:HOMEPATH+'\.bluemix\plugins\container-service\clusters\<CLUSTER_NAME>\kube-config-<DC_ZONE_NAME>-<CLUSTER_NAME>.yml'

ํ™˜๊ฒฝ ์„ค์ •์ด ๋˜์—ˆ๋‹ค๋ฉด Worker ๋…ธ๋“œ ์ •๋ณด๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

kubectl get nodes

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌ

Container Image ์ƒ์„ฑ (์„ ํƒ ์‚ฌํ•ญ)

๋ณธ ํŠœํ† ๋ฆฌ์–ผ์— ์‚ฌ์šฉ๋˜๋Š” ์ด๋ฏธ์ง€๋Š” ์‚ฌ์ „์— ๋งŒ๋“ค์–ด ๋†“์€ ์ด๋ฏธ์ง€๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ, ์—ฌ๋Ÿฌ๋ถ„์ด ์ง์ ‘ ์ƒ์„ฑํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฒฝ์šฐ Container Image ์ƒ์„ฑ ๊ฐ€์ด๋“œ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑ ํ›„ ์•„๋ž˜ ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

์ฐธ๊ณ ๋กœ, Container ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ–ˆ๋‹ค๋ฉด ์•„๋ž˜ Kubernetes Deployment์˜ Container Image ์ •๋ณด๋Š” ์ƒˆ๋กœ Build๋œ ์ •๋ณด์— ๋งž์ถ”์–ด ๋ณ€๊ฒฝํ•ด ์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

...
      containers:
        - image: <YOUR_IMAGE_NAME_SPACE>/spring-petclinic-visits-service:latest
          imagePullPolicy: Always
...

API ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค ์ƒ์„ฑํ•˜๊ธฐ

๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ API ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค Deployment์™€ Service๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

kubectl create -f k8s/api-gateway.yaml

Customers ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค ์ƒ์„ฑํ•˜๊ธฐ

๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ Customers ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค Deployment์™€ Service๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

kubectl create -f k8s/customers-service.yaml

Vets ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค ์ƒ์„ฑํ•˜๊ธฐ

๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ Vets ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค Deployment์™€ Service๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

kubectl create -f k8s/vets-service.yaml

Visits ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค ์ƒ์„ฑํ•˜๊ธฐ

๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ Visits ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค Deployment์™€ Service๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

kubectl create -f k8s/visits-service.yaml

๋ฐฐํฌ ์ƒํƒœ ํ™•์ธ

๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค๋“ค์ด ์ •์ƒ์ ์œผ๋กœ ๋ฐฐํฌ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ ํ•˜์‹ญ์‹œ์˜ค

kubectl get pods -o=wide
NAME                           READY     STATUS    RESTARTS   AGE       IP              NODE
api-gateway-745db58c94-zdwfb   1/1       Running   0          1h        xxx.xxx.xxx.16   xxx.xxx.xxx.247
customers-77b6c4784f-tp8gn     1/1       Running   0          1h        xxx.xxx.xxx.20   xxx.xxx.xxx.247
vets-6ddf965b54-7jhpt          1/1       Running   0          1h        xxx.xxx.xxx.23   xxx.xxx.xxx.247
visits-7f97889974-psmsh        1/1       Running   0          1h        xxx.xxx.xxx.24   xxx.xxx.xxx.247
kubectl get svc
NAME                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
api-gateway         NodePort    xxx.xxx.xxx.104   <none>        80:32002/TCP     1h
customers-service   NodePort    xxx.xxx.xxx.63    <none>        80:32003/TCP     1h
kubernetes          ClusterIP   xxx.xxx.xxx.1     <none>        443/TCP          2d
vets-service        NodePort    xxx.xxx.xxx.129   <none>        80:32005/TCP     1h
visits-service      NodePort    xxx.xxx.xxx.196   <none>        80:32004/TCP     1h

Ingress ์„ค์ • ๋ฐ ์›น ๋ธŒ๋ผ์šฐ์ €๋กœ ํ™•์ธ

ํ‘œ์ค€ ํด๋Ÿฌ์Šคํ„ฐ์— ๋ฐฐํฌ๋œ ๊ฒฝ์šฐ subdomain์€ cluster name๊ณผ region์— ๋”ฐ๋ผ ์ž๋™์œผ๋กœ ํ• ๋‹น๋˜๋ฉฐ ๋ณธ ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ์ด ์ •๋ณด๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ํ‘œ์ค€ ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ subdomain ์ƒ์„ฑ ์ •๋ณด๊ฐ€ ์—†์œผ๋ฏ€๋กœ ์•„๋ž˜ IKS ๋ฌด๋ฃŒ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์ด์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋ฅผ ์ฐธ๊ณ ํ•ฉ๋‹ˆ๋‹ค.

ํด๋Ÿฌ์Šคํ„ฐ์— ์ž๋™์œผ๋กœ ํ• ๋‹น๋˜๋Š” subdomain์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์œผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ibmcloud ks cluster-get <CLUSTER_NAME>
$ ibmcloud ks cluster-get mycluster
Retrieving cluster mycluster...
OK

                                
Name:                           mycluster
ID:                             xxxx
State:                          normal
Created:                        2019-03-20T06:13:44+0000
Location:                       seo01
Master URL:                     https://xxx.xxx.xxx:xxxx
Public Service Endpoint URL:    https://xxx.xxx.xxx:xxxx
Private Service Endpoint URL:   -
Master Location:                seo01
Master Status:                  Ready (1 day ago)
Master State:                   deployed
Master Health:                  normal
Ingress Subdomain:              mycluster.seo01.containers.appdomain.cloud
Ingress Secret:                 mycluster
Workers:                        1
Worker Zones:                   seo01
Version:                        1.12.9_1555* (1.13.6_1524 latest)
Owner:                          xxxx@xxxx.xxx
Monitoring Dashboard:           -
Resource Group ID:              xxxxxxxxxxx
Resource Group Name:            default

๊ทธ ์ค‘ Ingress Subdomain ํ•ญ๋ชฉ์ด ์ž๋™์œผ๋กœ ํ• ๋‹น๋˜๋Š” subdomain ์ฃผ์†Œ ์ž…๋‹ˆ๋‹ค. ์œ„์˜ ๊ฒฝ์šฐ๋Š” <cluster_name>์ด mycluster <region_or_zone>์ด seo01์ด๋ฏ€๋กœ mycluster.seo01.containers.appdomain.cloud์ด ํ• ๋‹น๋œ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

k8s/ingress.yaml ํŒŒ์ผ์„ ์—ด์–ด <INGRESS_SUBDOMAIN>๋ฅผ ์œ„์—์„œ ํ™•์ธํ•œ ingress subdomin ๊ฐ’์œผ๋กœ ๋ณ€๊ฒฝ ํ›„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

spec:
  rules:
  - host: petclinic.<INGRESS_SUBDOMAIN>

ingress.yaml ํŒŒ์ผ์ด ์ค€๋น„๋˜์—ˆ์œผ๋ฉด ์•„๋ž˜ ๋ช…๋ น์œผ๋กœ Ingress ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

kubectl create -f k8s/ingress.yaml

Ingress๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ƒ์„ฑ๋œ ๊ฒฝ์šฐ ๋‹ค์Œ URL์— ์ ‘๊ทผํ•˜๋ฉด ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ petclinic ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

https://petclinic.<INGRESS_SUBDOMAIN>

IKS ๋ฌด๋ฃŒ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์ด์šฉํ•˜๋Š” ๊ฒฝ์šฐ

๋ฌด๋ฃŒ ํด๋Ÿฌ์Šคํ„ฐ์˜ ๊ฒฝ์šฐ Node์˜ Public IP๋งŒ ์ œ๊ณต๋˜๋ฉฐ ์•„๋ž˜์™€ ๊ฐ™์ด ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Nginx ์ด๋ฏธ์ง€์™€ NodePort ํƒ€์ž… Service๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ Nginx Deployment์™€ Service๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

kubectl create -f k8s/nginx/nginx-configmap.yaml
kubectl create -f k8s/nginx/nginx-service.yaml
kubectl create -f k8s/nginx/nginx.yaml

๋‹ค์Œ ๋ช…๋ น์„ ์ด์šฉํ•˜์—ฌ worker node์˜ EXTERNAL-IP๋ฅผ ํ™•์ธ ํ•ฉ๋‹ˆ๋‹ค.

kubectl get nodes -o wide

nginx๋Š” NodePort 32010์„ ์ด์šฉํ•˜๋ฏ€๋กœ ์›น ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์€ URL์— ์ ‘๊ทผํ•ฉ๋‹ˆ๋‹ค.

http://<EXTERNAL-IP>:32010/

Nginx Ingress Controller๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

Nginx Ingress Controller๋Š” Ingress Controller๋ฅผ Nginx๋กœ ๊ตฌํ˜„ํ•œ ๊ฒƒ์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์ฝ”๋“œ๊ฐ€ ๊ณต๊ฐœ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์–‘ํ•œ ํ˜•ํƒœ๋กœ ์„ค์น˜ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ Helm Chart๋ฅผ ์ด์šฉํ•˜๋ฉด ๋ณ„๋‹ค๋ฅธ ์˜ต์…˜ ์—†์ด ๋ฐ”๋กœ ๋ฐฐํฌ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Helm Chart๋ฅผ ์ด์šฉํ•œ nginx ํŒจํ‚ค์ง€ ๋ฐฐํฌ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜๋ฉด Nginx Ingress Controller๋ฅผ ์„ค์น˜ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Ingress Controller๊ฐ€ ์ค€๋น„๋˜์—ˆ๋‹ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์œผ๋กœ ingress๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

kubectl create -f k8s/ingress-nginx.yaml

Ingress๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ƒ์„ฑ๋œ ๊ฒฝ์šฐ ๋‹ค์Œ URL์— ์ ‘๊ทผํ•˜๋ฉด ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ petclinic ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

http://<EXTERNAL-IP>/

MySQL DB ์ด์šฉํ•˜๊ธฐ (์„ ํƒ ์‚ฌํ•ญ)

Spring PetClinic Microservice๋Š” Database๋ฅผ HSQL์„ ๊ธฐ๋ณธ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์ถ”๊ฐ€์ ์œผ๋กœ MySQL DB๋ฅผ ์‚ฌ์šฉ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ๋จผ์ € MySQL DB๋ฅผ ์ค€๋น„ํ•ฉ๋‹ˆ๋‹ค.

MySQL Database ์ค€๋น„ํ•˜๊ธฐ

MySQL DB๋Š” IBM Cloud์—์„œ ์ ‘์†๊ฐ€๋Šฅํ•œ Instance ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์ „์— MySQL DB๊ฐ€ ์ค€๋น„๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ Kubernetes ํด๋Ÿฌ์Šคํ„ฐ์— MySQL์„ ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

MySQL ํ˜ธ์ŠคํŠธ ์„œ๋ฒ„ ๋ฐ ํฌํŠธ ์ •๋ณด ์ž…๋ ฅํ•˜๊ธฐ

๋ณธ ์˜ˆ์ œ์—์„œ๋Š” k8s/mysql/mysql-configmap.yaml ํŒŒ์ผ์— MySQL ์„œ๋ฒ„ ํ˜ธ์ŠคํŠธ ๋ฐ ํฌํŠธ ๋ฒˆํ˜ธ๊ฐ€ ์ž…๋ ฅ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ Kubernetes ํด๋Ÿฌ์Šคํ„ฐ์— ์ƒ์„ฑํ•œ MySQL ์„œ๋ฒ„๋กœ ์—ฐ๊ฒฐํ•˜๋„๋ก hostinfo ๊ฐ’์ด mysql:3306์œผ๋กœ ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์™ธ๋ถ€ DB ์„œ๋ฒ„๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ํ•ด๋‹น ์ •๋ณด๋ฅผ ๋ณ€๊ฒฝํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ , ๋‹ค์Œ ๋ช…๋ น์„ ์ด์šฉํ•˜์—ฌ ConfigMap ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

kubectl create -f k8s/mysql/mysql-configmap.yaml

MySQL Secret ์ƒ์„ฑํ•˜๊ธฐ

MySQL DB์— ์ ‘๊ทผํ•œ๋Š” ์‚ฌ์šฉ์ž์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ConfigMap์ด ์•„๋‹Œ Secret์œผ๋กœ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ๋Š” Kubernetes ํด๋Ÿฌ์Šคํ„ฐ์— ์ƒ์„ฑํ•œ MySQL ์„œ๋ฒ„๋กœ ์—ฐ๊ฒฐ์„ ์œ„ํ•œ username๋Š” root, password๋Š” petclinic์œผ๋กœ ๋‹ค์Œ ๋ช…๋ น์œผ๋กœ Secret ์ •๋ณด๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ, ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ •๋ณด์™€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ ํŒŒ์ผ์—์„œ MySQL Secret ์ƒ์„ฑํ•˜๊ธฐ๋ฅผ ์ด์šฉํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

kubectl create -f k8s/mysql/mysql-secret.yaml

ํŒŒ์ผ์—์„œ MySQL Secret ์ƒ์„ฑํ•˜๊ธฐ

ํŒŒ์ผ์—์„œ Secret์„ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

# Create files needed for rest of example.
echo -n "<YOUR_MYSQL_USERNAME" > username
echo -n "<YOUR_MYSQL_PASSWORD" > password

์ฐธ๊ณ ๋กœ, username๊ณผ password ํŒŒ์ผ์€ ๋ณด์•ˆ์— ์œ„ํ˜‘์ด ๋˜๋ฏ€๋กœ Secret ์ƒ์„ฑ ํ›„ ์‚ญ์ œํ•ด ์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

kubectl create secret ๋ช…๋ น์œผ๋กœ mysql-credential Secret์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

kubectl create secret generic mysql-credential --from-file=username --from-file=password

์ƒ์„ฑํ•œ secret ์ •๋ณด๋ฅผ ํ™•์ธํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

kubectl get secret/mysql-credential -o yaml

์ด๋ ‡๊ฒŒ ์ƒ์„ฑ๋œ Secret์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด secretKeyRef๋ฅผ ํ†ตํ•ด ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋กœ ๋กœ๋”ฉ๋ฉ๋‹ˆ๋‹ค.

env:
- name: MYSQL_USERNAME
valueFrom:
  secretKeyRef:
    name: mysql-credential
    key: username
- name: MYSQL_PASSWORD
valueFrom:
  secretKeyRef:
    name: mysql-credential
    key: password

MySQL DB ์ด์šฉ์„ ์œ„ํ•œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ • ํ•˜๊ธฐ

Spring PetClinic์—์„œ MySQL DB๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด DB๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋‹ค์Œ ์„ธ ๊ฐœ์˜ ์„œ๋น„์Šค ๋ชจ๋“ˆ์— MySQL ๊ด€๋ จ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • customers-service
  • vets-service
  • visits-service

ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋Š” Deployment์˜ Container Template ์ •๋ณด์— ์ถ”๊ฐ€ํ•˜๊ฒŒ ๋˜๋ฉฐ, ๋‹ค์Œ์€ vets-service์— ๋Œ€ํ•œ ์˜ˆ์‹œ ์ž…๋‹ˆ๋‹ค.

spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: spring-petclinic
        tier: visits
    spec:
      containers:
        - image: hongjs/spring-petclinic-visits-service:latest
          imagePullPolicy: Always
          name: visits
          ports:
            - containerPort: 8080
          env:
          - name: MYSQL_HOSTINFO
            valueFrom:
              configMapKeyRef:
                name: mysql-config
                key: hostinfo
          - name: MYSQL_USERNAME
            valueFrom:
              secretKeyRef:
                name: mysql-credential
                key: username
          - name: MYSQL_PASSWORD
            valueFrom:
              secretKeyRef:
                name: mysql-credential
                key: password
          - name: spring.profiles.active
            value: mysql

์ด ๋‚ด์šฉ์„ ์ ์šฉํ•œ Deployment ํŒŒ์ผ๋“ค์„ ๋‹ค์Œ ๋ช…๋ น์œผ๋กœ Kubernetes Cluster์— ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.

kubectl apply -f k8s/mysql/mysql-customers-service.yaml
kubectl apply -f k8s/mysql/mysql-vets-service.yaml
kubectl apply -f k8s/mysql/mysql-visits-service.yaml

About

Spring Pet Clinic Example runs on IBM Cloud Kubernetes Service (IKS)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published