Google Kubernetes Engine ๋ฐ ํ๋ก์๋ฆฌ์ค gRPC ์๋น์ค ์ค์
์ด ๊ฐ์ด๋์์๋ Google Kubernetes Engine, gRPC ์ ํ๋ฆฌ์ผ์ด์ , Cloud Service Mesh์ ํ์ํ ๋ถํ ๋ถ์ฐ ๊ตฌ์ฑ์์๋ฅผ ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํฉ๋๋ค.
์ด ๊ฐ์ด๋์ ์๋ด๋ฅผ ๋ฐ๋ฅด๊ธฐ ์ ์ ํ๋ก์๋ฆฌ์ค gRPC ์๋น์ค๋ก Cloud Service Mesh ์ค์ ์ค๋น๋ฅผ ๊ฒํ ํ์ธ์.
๊ฐ์
GKE ๋ฐ ํ๋ก์๋ฆฌ์ค gRPC ์๋น์ค๋ก Cloud Service Mesh๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- GKE ํด๋ฌ์คํฐ ์ค๋น
- gRPC ์๋ฒ ์ ํ๋ฆฌ์ผ์ด์ ์ Kubernetes ์๋น์ค๋ก ๋ฐฐํฌ ์๋น์ค์ ๋ํด ๋คํธ์ํฌ ์๋ํฌ์ธํธ ๊ทธ๋ฃน(NEG)์ ์๋์ผ๋ก ๋ง๋ค๋๋ก GKE ๋ฐฐํฌ ์ฌ์์ ์ฃผ์์ ์ง์ ํฉ๋๋ค.
- NEG ๋ฐ ๊ธฐํ Google Cloud ๋ถํ ๋ถ์ฐ ๊ตฌ์ฑ์์๋ฅผ ์ฌ์ฉํ์ฌ Cloud Service Mesh ๊ตฌ์ฑ
- ํ๋ก์๋ฆฌ์ค gRPC ํด๋ผ์ด์ธํธ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ฌ์ฉํ์ฌ gRPC ์๋ฒ ์ ํ๋ฆฌ์ผ์ด์ ์ ํธ๋ํฝ์ ์ ์กํ์ฌ ๋ฐฐํฌ๊ฐ ์ ๋๋ก ์๋ํ๋์ง ํ์ธํฉ๋๋ค.
Cloud Service Mesh์ฉ GKE ํด๋ฌ์คํฐ ๊ตฌ์ฑ
์ด ์น์ ์์๋ Cloud Service Mesh์์ ์ฌ์ฉํ ์ ์๋๋ก GKE ํด๋ฌ์คํฐ๋ฅผ ์ฌ์ฉ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํฉ๋๋ค.
GKE ํด๋ฌ์คํฐ ์๊ตฌ์ฌํญ
GKE ํด๋ฌ์คํฐ๋ ๋ค์๊ณผ ๊ฐ์ ์๊ตฌ์ฌํญ์ ์ถฉ์กฑํด์ผ ํฉ๋๋ค.
- ๋คํธ์ํฌ ์๋ํฌ์ธํธ ๊ทธ๋ฃน์ ๋ํด ์ง์์ ์ฌ์ฉ ์ค์ ํด์ผ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ๊ณผ ์์๋ ๋ ๋ฆฝํ ๋คํธ์ํฌ ์๋ํฌ์ธํธ ๊ทธ๋ฃน์ ์ฐธ์กฐํ์ธ์. ๋ ๋ฆฝํ NEG ๊ธฐ๋ฅ์ Cloud Service Mesh์ ์ ์ ๋ฒ์ ์ผ๋ก ์ ๊ณต๋ฉ๋๋ค.
- ํด๋ฌ์คํฐ ๋ ธ๋ ์ธ์คํด์ค์ ์๋น์ค ๊ณ์ ์ Cloud Service Mesh API์ ์ก์ธ์คํ ์ ์๋ ๊ถํ์ด ์์ด์ผ ํฉ๋๋ค. ํ์ํ ๊ถํ์ ๋ํ ์์ธํ ๋ด์ฉ์ Cloud Service Mesh API์ ์ก์ธ์คํ ์ ์๋๋ก ์๋น์ค ๊ณ์ ์ฌ์ฉ ์ค์ ์ ์ฐธ์กฐํ์ธ์.
- ์ปจํ ์ด๋๋ OAuth ์ธ์ฆ์ผ๋ก ๋ณดํธ๋๋ Cloud Service Mesh API์ ์ก์ธ์คํ ์ ์์ด์ผ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ํธ์คํธ ๊ตฌ์ฑ์ ์ฐธ์กฐํ์ธ์.
GKE ํด๋ฌ์คํฐ ๋ง๋ค๊ธฐ
๋ค์ ์์์์๋ us-central1-a zone
์์ grpc-td-cluster
๋ผ๋ GKE ํด๋ฌ์คํฐ๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค.
์ฝ์
Google Cloud ์ฝ์์ ์ฌ์ฉํ์ฌ ํด๋ฌ์คํฐ๋ฅผ ๋ง๋ค๋ ค๋ฉด ๋ค์ ๋จ๊ณ๋ฅผ ์ํํ์ธ์.
Google Cloud ์ฝ์์์ Kubernetes Engine ๋ฉ๋ด๋ก ์ด๋ํฉ๋๋ค.
ํด๋ฌ์คํฐ ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
ํ์ค ํด๋ฌ์คํฐ ํ ํ๋ฆฟ์ ์ ํํ๊ฑฐ๋ ์ํฌ๋ก๋์ ์ ํฉํ ํ ํ๋ฆฟ์ ์ ํํฉ๋๋ค.
ํ์ํ ๊ฒฝ์ฐ ํ ํ๋ฆฟ์ ๋ง์ถค์ค์ ํฉ๋๋ค. ๋ค์ ํ๋๋ ํ์์ ๋๋ค.
- ์ด๋ฆ:
grpc-td-cluster
๋ฅผ ์ ๋ ฅํฉ๋๋ค. - ์์น ์ ํ:
Zonal
- ์์ญ:
us-central1-a
- ๋ ธ๋ ํ:
- ์ด๋ฆ:
์ผ์ชฝ ๋ฉ๋ด์์ default-pool์ ํด๋ฆญํฉ๋๋ค.
์ด๋ฆ์
grpc-td-cluster
๋ก ๋ณ๊ฒฝํฉ๋๋ค.ํฌ๊ธฐ์ ๋ง๋ค ๋ ธ๋ ์๋ฅผ ์ ๋ ฅํฉ๋๋ค. ๋ ธ๋ ๋ฐ ํด๋น ๋ฆฌ์์ค(์: ๋ฐฉํ๋ฒฝ ๊ฒฝ๋ก)์ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฆฌ์์ค ํ ๋น๋์ด ์์ด์ผ ํฉ๋๋ค.
์ผ์ชฝ ๋ฉ๋ด์์ ๋ ธ๋๋ฅผ ํด๋ฆญํฉ๋๋ค.
๋จธ์ ๊ตฌ์ฑ์ ๋จธ์ ๊ณ์ด์์ ์ปดํจํ ์ต์ ํ๋ฅผ ํด๋ฆญํฉ๋๋ค.
๋จธ์ ์ ํ์ ์ ํํฉ๋๋ค. ๋จธ์ ์ ํ ๊ฐ๊ฒฉ ์ฑ ์ ์ ๋ณด๋ Compute Engine ๊ฐ๊ฒฉ ์ฑ ์ ํ์ด์ง๋ฅผ ์ฐธ์กฐํ์ธ์.
๋คํธ์ํน์์ ๋คํธ์ํฌ ํ๊ทธ
allow-health-checks
๋ฅผ ์ถ๊ฐํฉ๋๋ค.์ผ์ชฝ ๋ฉ๋ด์์ ๋ ธ๋ ๋ณด์์ ํด๋ฆญํฉ๋๋ค.
์ก์ธ์ค ๋ฒ์์์ ๋ชจ๋ Cloud API์ ๋ํ ์ ์ฒด ์ก์ธ์ค ํ์ฉ์ ์ ํํฉ๋๋ค.
๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
Google Cloud ์ฝ์์์ ํด๋ฌ์คํฐ๋ฅผ ๋ง๋ ํ ํด๋ฌ์คํฐ์ ์ํธ์์ฉํ๋ ค๋ฉด kubectl
์ ๊ตฌ์ฑํด์ผ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ kubeconfig
ํญ๋ชฉ ์์ฑ์ ์ฐธ์กฐํ์ธ์.
gcloud
ํด๋ฌ์คํฐ๋ฅผ ๋ง๋ญ๋๋ค.
gcloud container clusters create grpc-td-cluster \ --zone us-central1-a \ --scopes=https://www.googleapis.com/auth/cloud-platform \ --tags=allow-health-checks \ --enable-ip-alias
ํ์ GKE ํด๋ฌ์คํฐ ๊ถํ ๊ฐ์ ธ์ค๊ธฐ
๋ค์ ๋ช
๋ น์ด๋ฅผ ์คํํ์ฌ ๋ฐฉ๊ธ ๋ง๋ ํด๋ฌ์คํฐ๋ก ์ ํํฉ๋๋ค. ๊ทธ๋ฌ๋ฉด kubectl
์ด ์ฌ๋ฐ๋ฅธ ํด๋ฌ์คํฐ๋ฅผ ๊ฐ๋ฆฌํต๋๋ค.
gcloud
gcloud container clusters get-credentials grpc-td-cluster \ --zone us-central1-a
GKE ์๋น์ค ๊ตฌ์ฑ
์ด ์น์
์์๋ Cloud Service Mesh์์ ์ฌ์ฉํ ์ ์๋๋ก GKE ๋ฐฐํฌ ์ฌ์์ ์ค๋นํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช
ํฉ๋๋ค. ์ด๋ NEG ์ฃผ์์ด ์๋ GKE helloworld
์์ ์๋น์ค ๊ตฌ์ฑ์ผ๋ก ์ด๋ฃจ์ด์ง๋๋ค.
helloworld
์์ ์๋น์ค๋ gRPC ํด๋ผ์ด์ธํธ ์์ฒญ์ ๋ํ ์๋ต์ผ๋ก ๋ฉ์์ง๋ฅผ ๋ฐํํ๋ gRPC ์๋ฒ ์ ํ๋ฆฌ์ผ์ด์
์
๋๋ค. helloworld
์๋น์ค์๋ ํน๋ณํ ๊ฒ์ด ์์ต๋๋ค. ํ๋ก์๋ฆฌ์ค gRPC ์๋น์ค๊ฐ ์๋๋ฉฐ ๋ชจ๋ gRPC ํด๋ผ์ด์ธํธ์ ์์ฒญ์ ์๋ตํ ์ ์์ต๋๋ค.
'ํ๋ก์๋ฆฌ์ค' ๋ถ๋ถ์ gRPC ํด๋ผ์ด์ธํธ ์ ํ๋ฆฌ์ผ์ด์
์ด Cloud Service Mesh์ ์ฐ๊ฒฐํ ๋์๋ง ์๋ํ๋ฏ๋ก IP ์ฃผ์๋ DNS ๊ธฐ๋ฐ ์ด๋ฆ ๋ณํ์ ์ฌ์ฉํ ํ์ ์์ด helloworld
์๋น์ค๋ฅผ ์์๋ณด๊ณ ํธ๋ํฝ์ helloworld
์ ์ฐ๊ฒฐ๋ ํฌ๋์ ์ ์กํ ์ ์์ต๋๋ค.
NEG๋ก GKE ์๋น์ค ๊ตฌ์ฑ
Cloud Service Mesh์์ ์ฌ์ฉํ GKE ์๋น์ค๋ฅผ ๊ตฌ์ฑํ๋ ์ฒซ ๋ฒ์งธ ๋จ๊ณ๋ NEG๋ฅผ ํตํด ์๋น์ค๋ฅผ ๋ ธ์ถํ๋ ๊ฒ์ ๋๋ค. NEG๋ฅผ ํตํด ๋ ธ์ถํ๋ ค๋ฉด ๊ฐ ์ฌ์์ ๋ ธ์ถํ ํฌํธ์ ์ผ์นํ๋ ๋ค์ ์ฃผ์์ด ์์ด์ผ ํฉ๋๋ค.
... metadata: annotations: cloud.google.com/neg: '{"exposed_ports":{"8080":{"name": "example-grpc-server"}}}'
์ด ์ฃผ์์ ์๋น์ค๋ฅผ ์ฒ์ ๋ฐฐํฌํ ๋ ๋ ๋ฆฝํ NEG๋ฅผ ๋ง๋ญ๋๋ค. ์ด NEG์๋ ํฌ๋์ IP ์ฃผ์์ ํฌํธ์ธ ์๋ํฌ์ธํธ๊ฐ ํฌํจ๋ฉ๋๋ค. ์์ธํ ๋ด์ฉ๊ณผ ์์๋ ๋ ๋ฆฝํ ๋คํธ์ํฌ ์๋ํฌ์ธํธ ๊ทธ๋ฃน์ ์ฐธ์กฐํ์ธ์.
๋ค์ ์์์์๋ ํฌํธ 8080
์ผ๋ก ์ ๊ณต๋๋ helloworld
Kubernetes ์๋น์ค๋ฅผ ๋ฐฐํฌํฉ๋๋ค. ์ด ํฌํธ๋ ํด๋ฌ์คํฐ์์ ์๋น์ค๊ฐ ํ์๋๋ ํฌํธ์
๋๋ค. ํฌ๋์ gRPC ์๋น์ค๋ targetPort
50051
์์ ๋ฆฌ์จํฉ๋๋ค. ์ด ํฌํธ๋ ์์ฒญ์ด ์ ์ก๋๋ ํฌ๋์ ํฌํธ์
๋๋ค. ์ผ๋ฐ์ ์ผ๋ก port
๋ฐ targetPort
๋ ํธ์๋ฅผ ์ํด ๋์ผํ ๊ฐ์ผ๋ก ์ค์ ๋์ง๋ง, ์ด ์์์์๋ NEG ์ฃผ์์ ์ฌ์ฉํ ์ฌ๋ฐ๋ฅธ ๊ฐ์ ๋ํ๋ด๊ธฐ ์ํด ๋ค๋ฅธ ๊ฐ์ ์ฌ์ฉํฉ๋๋ค.
cat << EOF > grpc-td-helloworld.yaml apiVersion: v1 kind: Service metadata: name: helloworld annotations: cloud.google.com/neg: '{"exposed_ports":{"8080":{"name": "example-grpc-server"}}}' spec: ports: - port: 8080 name: helloworld protocol: TCP targetPort: 50051 selector: run: app1 type: ClusterIP --- apiVersion: apps/v1 kind: Deployment metadata: labels: run: app1 name: app1 spec: selector: matchLabels: run: app1 replicas: 2 template: metadata: labels: run: app1 spec: containers: - image: grpc/java-example-hostname:1.50.2 name: app1 ports: - protocol: TCP containerPort: 50051 EOF
kubectl apply -f grpc-td-helloworld.yaml
์ helloworld
์๋น์ค๊ฐ ๋ง๋ค์ด์ก๋์ง ํ์ธํฉ๋๋ค.
kubectl get svc
kubectl get svc
์ ์ถ๋ ฅ์ ๋ค์๊ณผ ๋น์ทํฉ๋๋ค.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE helloworld ClusterIP 10.71.9.71 <none> 8080/TCP 41m [..skip..]
์ ํ๋ฆฌ์ผ์ด์ ํฌ๋๊ฐ ์คํ ์ค์ธ์ง ํ์ธํฉ๋๋ค.
kubectl get pods
kubectl get pods
์ ์ถ๋ ฅ์ ๋ค์๊ณผ ๋น์ทํฉ๋๋ค.
NAME READY STATUS RESTARTS AGE app1-6db459dcb9-zvfg2 1/1 Running 0 6m app1-6db459dcb9-hlvhj 1/1 Running 0 6m [..skip..]
NEG ์ด๋ฆ์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํฉ๋๋ค.
์ฝ์
๋คํธ์ํฌ ์๋ํฌ์ธํธ ๊ทธ๋ฃน์ ๋ชฉ๋ก์ ๋ณด๋ ค๋ฉด Google Cloud ์ฝ์์ ๋คํธ์ํฌ ์๋ํฌ์ธํธ ๊ทธ๋ฃน ํ์ด์ง๋ก ์ด๋ํ์ธ์. example-grpc-server
๋ผ๋ NEG๊ฐ ํ์๋ฉ๋๋ค.
๋คํธ์ํฌ ์๋ํฌ์ธํธ ๊ทธ๋ฃน ํ์ด์ง๋ก ์ด๋
gcloud
# List the NEGs gcloud compute network-endpoint-groups list \ --filter "name=example-grpc-server" --format "value(name)" # Optionally examine the NEG gcloud compute network-endpoint-groups describe example-grpc-server \ --zone us-central1-a # Optionally examine the endpoint(s) contained gcloud compute network-endpoint-groups list-network-endpoints example-grpc-server \ --zone us-central1-a
๋ถํ ๋ถ์ฐ ๊ตฌ์ฑ์์๋ก Cloud Service Mesh ๊ตฌ์ฑ
์ด ์น์ ์์๋ ์๋น์ค์ Google Cloud ๋ถํ ๋ถ์ฐ ๊ตฌ์ฑ์์๋ฅผ ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํฉ๋๋ค. ์ด๋ฌํ ๊ตฌ์ฑ์์์๋ ํ๋ก์๋ฆฌ์ค gRPC ํด๋ผ์ด์ธํธ๊ฐ GKE ์๋น์ค์ ํต์ ํ ์ ์๊ฒ ํด์ฃผ๋ ๊ตฌ์ฑ ์ ๋ณด๊ฐ ํฌํจ๋ฉ๋๋ค.
๋ค์ Cloud Service Mesh ๊ตฌ์ฑ ์์์์๋ ๋ค์์ ๊ฐ์ ํฉ๋๋ค.
- NEG ๋ฐ ๊ธฐํ ๋ชจ๋ ๋ฆฌ์์ค๋
us-central1-a
์์ญ์ ์๋ ๋ชจ๋ ๊ธฐ๋ณธ ๋คํธ์ํฌ์์ ์์ฑ๋ฉ๋๋ค. - Google Cloud CLI๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ํด๋ฌ์คํฐ์ NEG ์ด๋ฆ์
example-grpc-server
์ ๋๋ค.
์ํ ํ์ธ, ๋ฐฉํ๋ฒฝ ๊ท์น ๋ฐ ๋ฐฑ์๋ ์๋น์ค ๋ง๋ค๊ธฐ
์ด ์น์
์์๋ ์ํ ํ์ธ ๋ฐ ์ํ ํ์ธ์ฉ ๋ฐฉํ๋ฒฝ ๊ท์น์ ๋ง๋ญ๋๋ค. ์ํ ํ์ธ์ gRPC ์ํ ํ์ธ ํ๋กํ ์ฝ์ ์ฌ์ฉํด์ผ ํฉ๋๋ค. ๋ฐฉํ๋ฒฝ ๊ท์น์ ์ฌ์ฉํ๋ฉด ์ํ ํ์ธ ํ๋ก๋ธ๊ฐ ๋ฐฐํฌ์ ์๋ VM์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค. --use-serving-port
์ง์๋ฌธ์ ์ํ ํ์ธ์ด ๊ฐ ์๋ํฌ์ธํธ์ ๋ํด ๊ตฌ์ฑ๋ ์์ ํฌํธ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํด ์ฌ์ฉ๋ฉ๋๋ค.
๋ฐฉํ๋ฒฝ ๊ท์น์ ๋คํธ์ํฌ์ ์ธ์คํด์ค์ ๋ํ ์์ ์ํ ํ์ธ ์ฐ๊ฒฐ์ ํ์ฉํฉ๋๋ค.
์ด ์น์
์์๋ INTERNAL_SELF_MANAGED
๋ฐ ํ๋กํ ์ฝ GRPC
์ ๋ถํ ๋ถ์ฐ ์คํค๋ง๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ญ ๋ฐฑ์๋ ์๋น์ค๋ฅผ ๋ง๋ ํ ์ํ ํ์ธ์ ๋ฐฑ์๋ ์๋น์ค์ ์ฐ๊ฒฐํฉ๋๋ค.
์์ธํ ๋ด์ฉ์ ์ํ ํ์ธ ๋ง๋ค๊ธฐ๋ฅผ ์ฐธ์กฐํ์ธ์.
gcloud
์ํ ํ์ธ์ ๋ง๋ญ๋๋ค.
gcloud compute health-checks create grpc grpc-gke-helloworld-hc \ --use-serving-port
๋ฐฉํ๋ฒฝ ๊ท์น ๋ง๋ค๊ธฐ
gcloud compute firewall-rules create grpc-gke-allow-health-checks \ --network default --action allow --direction INGRESS \ --source-ranges 35.191.0.0/16,130.211.0.0/22 \ --target-tags allow-health-checks \ --rules tcp:50051
๋ฐฑ์๋ ์๋น์ค๋ฅผ ๋ง๋ญ๋๋ค.
gcloud compute backend-services create grpc-gke-helloworld-service \ --global \ --load-balancing-scheme=INTERNAL_SELF_MANAGED \ --protocol=GRPC \ --health-checks grpc-gke-helloworld-hc
๋ฐฑ์๋ ์๋น์ค์ ๋ฐฑ์๋ NEG๋ฅผ ์ถ๊ฐํฉ๋๋ค.
gcloud compute backend-services add-backend grpc-gke-helloworld-service \ --global \ --network-endpoint-group example-grpc-server \ --network-endpoint-group-zone us-central1-a \ --balancing-mode RATE \ --max-rate-per-endpoint 5
๋ผ์ฐํ ๊ท์น ๋งต ๋ง๋ค๊ธฐ
์ด ์น์
์์๋ ํธ์คํธ ์ด๋ฆ ๋ฐ ๊ฒฝ๋ก๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์๋น์ค์ ํธ๋ํฝ์ ๋ผ์ฐํ
ํ๋ URL ๋งต, ๊ฒฝ๋ก ์ผ์น์, ํธ์คํธ ๊ท์น์ ๋ง๋ญ๋๋ค. ๋ค์ ์์์์๋ helloworld-gke
๋ฅผ ์๋น์ค ์ด๋ฆ์ผ๋ก ์ฌ์ฉํฉ๋๋ค. gRPC ํด๋ผ์ด์ธํธ๋ helloworld
์๋น์ค์ ์ฐ๊ฒฐํ ๋ ๋์ URI์ ์ด ์๋น์ค ์ด๋ฆ์ ์ฌ์ฉํฉ๋๋ค.
๋์ gRPC ํ๋ก์ ๋ฐ ์ ๋ฌ ๊ท์น๋ ๋ง๋ญ๋๋ค.
์์ธํ ๋ด์ฉ์ ๋ผ์ฐํ ๊ท์น ๋งต์ ์ฐธ์กฐํ์ธ์.
๋ค์ ์์์์๋ ์๋น์ค ์ด๋ฆ helloworld-gke
๋ฐ 8000
ํฌํธ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
์ฆ, gRPC ํด๋ผ์ด์ธํธ๋ xds:///helloworld-gke:8000
์ ์ฌ์ฉํ์ฌ ์ด ์๋น์ค์ ์ฐ๊ฒฐํด์ผ ํ๋ฉฐ URL ๋งต์ ํธ์คํธ ๊ท์น helloworld-gke:8000
์ด ๊ตฌ์ฑ๋์ด์ผ ํฉ๋๋ค. helloworld-gke:8000
์ targetPort
50051
์์ ๋ฆฌ์จํ๋ NEG ์๋ํฌ์ธํธ๋ก ์ง์ ํ์ธ๋๋ฏ๋ก ์ด์ ์น์
์ Kubernetes ์๋น์ค ์ฌ์์ ํ์๋ ์๋น์ค ํฌํธ 8080
์ Cloud Service Mesh์์ ์ฌ์ฉ๋์ง ์์ต๋๋ค.
์ผ๋ฐ์ ์ผ๋ก URL ๋งต ํธ์คํธ ๊ท์น์ ํฌํธ์ Kubernetes ์๋น์ค ์ฌ์ port
๋ฐ targetPort
๋ชจ๋ ํธ์์ ๊ฐ์ ๊ฐ์ผ๋ก ์ค์ ๋์ง๋ง ์ด ์์์์๋ Cloud Service Mesh๊ฐ ์๋น์ค ์ฌ์์ port
๋ฅผ ์ฌ์ฉํ์ง ์์์ ๋ณด์ฌ์ฃผ๊ธฐ ์ํด ์๋ก ๋ค๋ฅธ ๊ฐ์ ์ฌ์ฉํฉ๋๋ค.
gcloud
URL ๋งต์ ๋ง๋ญ๋๋ค.
gcloud compute url-maps create grpc-gke-url-map \ --default-service grpc-gke-helloworld-service
๊ฒฝ๋ก ์ผ์น์๋ฅผ ๋ง๋ญ๋๋ค.
gcloud compute url-maps add-path-matcher grpc-gke-url-map \ --default-service grpc-gke-helloworld-service \ --path-matcher-name grpc-gke-path-matcher \ --new-hosts helloworld-gke:8000
๋์ gRPC ํ๋ก์๋ฅผ ๋ง๋ญ๋๋ค.
gcloud compute target-grpc-proxies create grpc-gke-proxy \ --url-map grpc-gke-url-map \ --validate-for-proxyless
์ ๋ฌ ๊ท์น์ ๋ง๋ญ๋๋ค.
gcloud compute forwarding-rules create grpc-gke-forwarding-rule \ --global \ --load-balancing-scheme=INTERNAL_SELF_MANAGED \ --address=0.0.0.0 \ --target-grpc-proxy=grpc-gke-proxy \ --ports 8000 \ --network default
์ด์ Cloud Service Mesh๊ฐ URL ๋งต์ ์ง์ ๋ ์๋น์ค์ NEG์์ ์๋ํฌ์ธํธ ๊ฐ์ ํธ๋ํฝ์ ๋ถํ ๋ถ์ฐํ๋๋ก ๊ตฌ์ฑ๋ฉ๋๋ค.
๊ตฌ์ฑ ํ์ธ
๊ตฌ์ฑ ํ๋ก์ธ์ค๊ฐ ์๋ฃ๋๋ฉด ํ๋ก์๋ฆฌ์ค gRPC ํด๋ผ์ด์ธํธ๋ฅผ ์ฌ์ฉํ์ฌ helloworld
gRPC ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์๋์ง ํ์ธํฉ๋๋ค. ์ด ํด๋ผ์ด์ธํธ๋ Cloud Service Mesh์ ์ฐ๊ฒฐ๋์ด helloworld
์๋น์ค(grpc-gke-helloworld-service
๋ฐฑ์๋ ์๋น์ค๋ฅผ ์ฌ์ฉํ์ฌ Cloud Service Mesh๋ก ๊ตฌ์ฑ)์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๊ณ ์ด ์ ๋ณด๋ฅผ ์ฌ์ฉํ์ฌ ํธ๋ํฝ์ ์๋น์ค์ ๋ฐฑ์๋๋ก ์ ์กํฉ๋๋ค.
๋ํ Google Cloud ์ฝ์์ Cloud Service Mesh ์น์
์์ ๊ตฌ์ฑ๋ ์๋น์ค helloworld-gke
์ ๋ํ ์ ๋ณด๋ฅผ ํ์ธํ๊ณ ๋ฐฑ์๋๊ฐ ์ ์์ผ๋ก ๋ณด๊ณ ๋๋์ง ํ์ธํ ์ ์์ต๋๋ค.
ํ๋ก์๋ฆฌ์ค gRPC ํด๋ผ์ด์ธํธ๋ก ๊ฒ์ฆ
๋ค์ ์์์์๋ ์๋ก ๋ค๋ฅธ ์ธ์ด๋ก ๋ gRPC ํด๋ผ์ด์ธํธ๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ grpcurl
๋๊ตฌ๋ฅผ ์ฌ์ฉํ์ฌ Cloud Service Mesh๊ฐ ๋ฉ์์์ ํธ๋ํฝ์ ์ฌ๋ฐ๋ฅด๊ฒ ๋ผ์ฐํ
ํ๋์ง ํ์ธํฉ๋๋ค. ํด๋ผ์ด์ธํธ ํฌ๋๋ฅผ ๋ง๋ ํ ์
ธ์ ์ด๊ณ ์
ธ์์ ์ธ์ฆ ๋ช
๋ น์ด๋ฅผ ์คํํฉ๋๋ค.
ํ๊ฒฝ ๋ณ์ ๋ฐ ๋ถํธ์คํธ๋ฉ ํ์ผ ์ค์
ํด๋ผ์ด์ธํธ ์ ํ๋ฆฌ์ผ์ด์
์๋ ๋ถํธ์คํธ๋ฉ ๊ตฌ์ฑ ํ์ผ์ด ํ์ํฉ๋๋ค. ํ์ผ ์ ์ก์ ์ํด ๋ถํธ์คํธ๋ฉ ํ์ผ ๋ฐ ๋ณผ๋ฅจ์ ์์ฑํ๋ initContainer
๋ฅผ ์ถ๊ฐํ์ฌ Kubernetes ์ ํ๋ฆฌ์ผ์ด์
๋ฐฐํฌ ์ฌ์์ ์์ ํฉ๋๋ค. ๊ธฐ์กด ์ปจํ
์ด๋๋ฅผ ์
๋ฐ์ดํธํ์ฌ ํ์ผ์ ์ฐพ์ต๋๋ค.
๋ค์ initContainer
๋ฅผ ์ ํ๋ฆฌ์ผ์ด์
๋ฐฐํฌ ์ฌ์์ ์ถ๊ฐํฉ๋๋ค.
initContainers: - args: - --output - "/tmp/bootstrap/td-grpc-bootstrap.json" image: gcr.io/trafficdirector-prod/td-grpc-bootstrap:0.16.0 imagePullPolicy: IfNotPresent name: grpc-td-init resources: limits: cpu: 100m memory: 100Mi requests: cpu: 10m memory: 100Mi volumeMounts: - name: grpc-td-conf mountPath: /tmp/bootstrap/ volumes: - name: grpc-td-conf emptyDir: medium: Memory
๋ค์์ ํฌํจํ๋๋ก ์ ํ๋ฆฌ์ผ์ด์
์ปจํ
์ด๋์ env
์น์
์ ์
๋ฐ์ดํธํฉ๋๋ค.
env: - name: GRPC_XDS_BOOTSTRAP value: "/tmp/grpc-xds/td-grpc-bootstrap.json" volumeMounts: - name: grpc-td-conf mountPath: /tmp/grpc-xds/
๋ค์์ ํด๋ผ์ด์ธํธ Kubernetes ์ฌ์์ ์ ์ฒด ์์์ ๋๋ค.
cat << EOF | kubectl apply -f - apiVersion: apps/v1 kind: Deployment metadata: labels: run: client name: sleeper spec: selector: matchLabels: run: client template: metadata: labels: run: client spec: containers: - image: openjdk:8-jdk imagePullPolicy: IfNotPresent name: sleeper command: - sleep - 365d env: - name: GRPC_XDS_BOOTSTRAP value: "/tmp/grpc-xds/td-grpc-bootstrap.json" resources: limits: cpu: "2" memory: 2000Mi requests: cpu: 300m memory: 1500Mi volumeMounts: - name: grpc-td-conf mountPath: /tmp/grpc-xds/ initContainers: - args: - --output - "/tmp/bootstrap/td-grpc-bootstrap.json" image: gcr.io/trafficdirector-prod/td-grpc-bootstrap:0.16.0 imagePullPolicy: IfNotPresent name: grpc-td-init resources: limits: cpu: 100m memory: 100Mi requests: cpu: 10m memory: 100Mi volumeMounts: - name: grpc-td-conf mountPath: /tmp/bootstrap/ volumes: - name: grpc-td-conf emptyDir: medium: Memory EOF
๋ฐฐํฌ๊ฐ ์ค๋น๋๋ฉด ํด๋ผ์ด์ธํธ ํฌ๋์ ๋ํ ์ ธ์ ์ฝ๋๋ค.
kubectl exec -it $(kubectl get pods -o custom-columns=:.metadata.name \ --selector=run=client) -- /bin/bash
๊ตฌ์ฑ์ ํ์ธํ๋ ค๋ฉด ํฌ๋ ์ ธ์์ ์ ์ ํ ์์๋ฅผ ์คํํฉ๋๋ค.
์๋ฐ
gRPC ์๋ฐ ํด๋ผ์ด์ธํธ์์ ์๋น์ค๋ฅผ ํ์ธํ๋ ค๋ฉด ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
์ต์ ํจ์น์ ํจ๊ป ์ต์ ๋ฒ์ ์ gRPC ์๋ฐ๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ,
xds-hello-world
ํด๋ผ์ด์ธํธ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋น๋ํฉ๋๋ค.curl -L https://github.com/grpc/grpc-java/archive/v1.37.0.tar.gz | tar -xz cd grpc-java-1.37.0/examples/example-xds ../gradlew --no-daemon installDist
"world"
๋ฅผ ์ด๋ฆ์ผ๋ก,"xds:///helloworld-gke:8000"
์ ์๋น์ค URI ๋ฐ ํฌํธ๋ก ์ฌ์ฉํ์ฌ ํด๋ผ์ด์ธํธ๋ฅผ ์คํํฉ๋๋ค../build/install/example-xds/bin/xds-hello-world-client "world" \ xds:///helloworld-gke:8000
Go
gRPC Go ํด๋ผ์ด์ธํธ์์ ์๋น์ค๋ฅผ ํ์ธํ๋ ค๋ฉด ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
์ต์ ํจ์น์ ํจ๊ป ์ต์ ๋ฒ์ ์ gRPC Go๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ,
xds-hello-world
ํด๋ผ์ด์ธํธ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋น๋ํฉ๋๋ค.apt-get update -y apt-get install -y golang git curl -L https://github.com/grpc/grpc-go/archive/v1.37.0.tar.gz | tar -xz cd grpc-go-1.37.0/examples/features/xds/client go get google.golang.org/grpc@v1.37.0 go build .
"world"
๋ฅผ ์ด๋ฆ์ผ๋ก,"xds:///helloworld-gke:8000"
์ ์๋น์ค URI ๋ฐ ํฌํธ๋ก ์ฌ์ฉํ์ฌ ํด๋ผ์ด์ธํธ๋ฅผ ์คํํฉ๋๋ค../client "world" xds:///helloworld-gke:8000
C++
gRPC C++ ํด๋ผ์ด์ธํธ์์ ์๋น์ค๋ฅผ ํ์ธํ๋ ค๋ฉด ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
์ต์ ํจ์น์ ํจ๊ป ์ต์ ๋ฒ์ ์ gRPC C++๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ,
helloworld
ํด๋ผ์ด์ธํธ ์์๋ฅผ ๋น๋ํฉ๋๋ค.apt-get update -y apt-get install -y build-essential cmake git git clone --recurse-submodules -b v1.37.1 https://github.com/grpc/grpc cd grpc mkdir -p cmake/build pushd cmake/build cmake ../.. make make install popd mkdir -p third_party/abseil-cpp/cmake/build pushd third_party/abseil-cpp/cmake/build cmake ../.. make make install popd cd examples/cpp/helloworld mkdir -p cmake/build cd cmake/build/ cmake ../.. make
'xds:///helloworld-gke:8000'์ ์๋น์ค URI ๋ฐ ํฌํธ๋ก ํด๋ผ์ด์ธํธ๋ฅผ ์คํํฉ๋๋ค.
./greeter_client --target=xds:///helloworld-gke:8000
grpcurl
grpcurl
๋๊ตฌ๋ ํ๋ก์๋ฆฌ์ค gRPC ํด๋ผ์ด์ธํธ ์ญํ ์ ํ ์๋ ์์ต๋๋ค. ์ด ๊ฒฝ์ฐ grpcurl
์ ํ๊ฒฝ ๋ณ์์ ๋ถํธ์คํธ๋ฉ ์ ๋ณด๋ฅผ ์ฌ์ฉํ์ฌ Cloud Service Mesh์ ์ฐ๊ฒฐํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ grpc-gke-helloworld-service
๋ฐฑ์๋ ์๋น์ค๋ฅผ ํตํด Cloud Service Mesh๋ก ๊ตฌ์ฑ๋ helloworld
์๋น์ค๋ฅผ ์์๋ด
๋๋ค.
grpcurl
๋๊ตฌ๋ฅผ ์ฌ์ฉํ์ฌ ๊ตฌ์ฑ์ ํ์ธํ๋ ค๋ฉด ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
grpcurl
๋๊ตฌ๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ์ค์นํฉ๋๋ค.curl -L https://github.com/fullstorydev/grpcurl/releases/download/v1.8.1/grpcurl_1.8.1_linux_x86_64.tar.gz | tar -xz
'xds:///helloworld-gke:8000'์ ์๋น์ค URI๋ก,
helloworld.Greeter/SayHello
์ ํธ์ถํ ์๋น์ค ์ด๋ฆ๊ณผ ๋ฉ์๋๋ก ์ง์ ํ๊ณgrpcurl
๋๊ตฌ๋ฅผ ์คํํฉ๋๋ค.SayHello
๋ฉ์๋์ ๋ํ ๋งค๊ฐ๋ณ์๋-d
์ต์ ์ ์ฌ์ฉํ์ฌ ์ ๋ฌํฉ๋๋ค../grpcurl --plaintext \ -d '{"name": "world"}' \ xds:///helloworld-gke:8000 helloworld.Greeter/SayHello
Python
gRPC Python ํด๋ผ์ด์ธํธ์์ ์๋น์ค๋ฅผ ํ์ธํ๋ ค๋ฉด ๋ค์์ ์คํํฉ๋๋ค. ์ต์ ํจ์น๊ฐ ์ ์ฉ๋ ์ต์ ๋ฒ์ ์ gRPC๋ฅผ ์ฌ์ฉํฉ๋๋ค.
apt-get update -y apt-get install python3-pip -y pip3 install virtualenv curl -L https://github.com/grpc/grpc/archive/v1.37.1.tar.gz | tar -xz cd grpc-1.37.1/examples/python/xds virtualenv venv -p python3 source venv/bin/activate pip install -r requirements.txt python client.py xds:///helloworld-gke:8000
Ruby
gRPC Ruby ํด๋ผ์ด์ธํธ์์ ์๋น์ค๋ฅผ ํ์ธํ๋ ค๋ฉด ๋ค์์ ์คํํฉ๋๋ค. ์ต์ ํจ์น๊ฐ ์ ์ฉ๋ ์ต์ ๋ฒ์ ์ gRPC๋ฅผ ์ฌ์ฉํฉ๋๋ค.
apt-get update -y apt-get install -y ruby-full gem install grpc curl -L https://github.com/grpc/grpc/archive/v1.37.1.tar.gz | tar -xz cd grpc-1.37.1/examples/ruby ruby greeter_client.rb john xds:///helloworld-gke:8000
PHP
gRPC PHP ํด๋ผ์ด์ธํธ์์ ์๋น์ค๋ฅผ ํ์ธํ๋ ค๋ฉด ๋ค์์ ์คํํฉ๋๋ค. ์ต์ ํจ์น๊ฐ ์ ์ฉ๋ ์ต์ ๋ฒ์ ์ gRPC๋ฅผ ์ฌ์ฉํฉ๋๋ค.
apt-get update -y apt-get install -y php7.3 php7.3-dev php-pear phpunit python-all zlib1g-dev git pecl install grpc curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer curl -L https://github.com/grpc/grpc/archive/v1.37.1.tar.gz | tar -xz cd grpc-1.37.1 export CC=/usr/bin/gcc ./tools/bazel build @com_google_protobuf//:protoc ./tools/bazel build src/compiler:grpc_php_plugin cd examples/php composer install ../../bazel-bin/external/com_google_protobuf/protoc --proto_path=../protos \ --php_out=. --grpc_out=. \ --plugin=protoc-gen-grpc=../../bazel-bin/src/compiler/grpc_php_plugin \ ../protos/helloworld.proto php -d extension=grpc.so greeter_client.php john xds:///helloworld-gke:8000
Node.js
gRPC Node.js ํด๋ผ์ด์ธํธ๋ฅผ ์ฌ์ฉํ์ฌ ์๋น์ค๋ฅผ ํ์ธํ๋ ค๋ฉด ๋ค์์ ์คํํฉ๋๋ค. ์ต์ ํจ์น๊ฐ ์ ์ฉ๋ ์ต์ ๋ฒ์ ์ gRPC๋ฅผ ์ฌ์ฉํฉ๋๋ค.
apt-get update -y apt-get install -y nodejs npm curl -L https://github.com/grpc/grpc/archive/v1.34.0.tar.gz | tar -xz cd grpc-1.34.0/examples/node/xds npm install node ./greeter_client.js --target=xds:///helloworld-gke:8000
INSTANCE_HOST_NAME
์ด VM ์ธ์คํด์ค์ ํธ์คํธ ์ด๋ฆ์ธ ๋ค์๊ณผ ๋น์ทํ ์ถ๋ ฅ์ด ํ์๋ฉ๋๋ค.
Greetings: Hello world, from INSTANCE_HOST_NAME
์ด๋ ๊ฒ ํ๋ฉด ํ๋ก์๋ฆฌ์ค gRPC ํด๋ผ์ด์ธํธ๊ฐ ์ฑ๊ณต์ ์ผ๋ก Cloud Service Mesh์ ์ฐ๊ฒฐ๋๊ณ xds ์ด๋ฆ ๋ฆฌ์กธ๋ฒ๋ฅผ ์ฌ์ฉํ์ฌ helloworld-gke
์๋น์ค์ ๋ฐฑ์๋๋ฅผ ์์๋ดค๋์ง ํ์ธํ ์ ์์ต๋๋ค. ํด๋ผ์ด์ธํธ๋ IP ์ฃผ์ ์ ๋ณด๋ฅผ ํ์ธํ๊ฑฐ๋ DNS ํ์ธ์ ์ํํ ํ์ ์์ด ์๋น์ค์ ๋ฐฑ์๋ ์ค ํ๋์ ์์ฒญ์ ๋ณด๋์ต๋๋ค.
๋ค์ ๋จ๊ณ
- Cloud Service Mesh ์๋น์ค ๋ณด์ ์์๋ณด๊ธฐ
- ๊ณ ๊ธ ํธ๋ํฝ ๊ด๋ฆฌ ์์๋ณด๊ธฐ
- ๊ด์ธก ๊ฐ๋ฅ์ฑ ์ค์ ๋ฐฉ๋ฒ ์์๋ณด๊ธฐ
- ํ๋ก์๋ฆฌ์ค Cloud Service Mesh ๋ฐฐํฌ ๋ฌธ์ ํด๊ฒฐ ๋ฐฉ๋ฒ ์์๋ณด๊ธฐ