今天會說明一下,實務上如何將 Open-Match svc endpoints,從 kubernetes 中暴露出來。由於先前都是以同 cluster 之間呼叫,並不會有需要外部 ip 的問題,但進入生產環境時,極有可能會將核心與部件分開在不同的 clusters 中,故此介紹一下端點暴露的方式與呼叫的方法。
方法一:透過修改 yaml
kind: Service
apiVersion: v1
metadata:
name: open-match-frontend
...
spec:
selector:
app: open-match
component: frontend
release: open-match
clusterIP: None
# type: ClusterIP
type: LoadBalancer
...
方法二:透過修改 helm 使用 values
frontend: &frontend
hostName:
grpcPort: 50504
httpPort: 51504
portType: LoadBalancer
replicas: 3
或直接 helm upgrade
helm upgrade open-match --namespace open-match open-match/open-match \
--set global.gcpProjectId=[YOUR_GCPPROJECT_ID] \
--set backend.portType=LoadBalancer
結果
~ kubectl get services -n open-match open-match-frontend
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
open-match-frontend ClusterIP 10.0.3.7 <none> 50504/TCP,51504/TCP 74d
~ kubectl get services -n open-match open-match-frontend
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
open-match-frontend LoadBalancer 10.0.3.7 104.198.205.71 50504/TCP,51504/TCP 74d
叢集外的對象須透過 EXTERNAL-IP
進行呼叫,而同樣位於叢集內的服務直接呼叫 SERVICE_NAME
叢集外
frontendConn, err := grpc.Dial("104.198.205.71:50504", grpc.WithInsecure())
叢集內
frontendConn, err := grpc.Dial("open-match-frontend:50504", grpc.WithInsecure())