k-jun / gopy-grpc

golang and python server connecting via grpc template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gopy-grpc

Download

git clone https://github.com/K-jun1221/gopy-grpc-server.git
cd gopy-grpc-server

ProtocolBuffer

# golang
go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/protoc-gen-go

# `proto.pb.go`を生成
mkdir ./server/protolib
protoc -I protos/ --go_out=plugins=grpc:./server/protolib protos/proto.proto

# python
python -m pip install --upgrade pip
python -m pip install grpcio
python -m pip install grpcio-tools

# `proto_pb2.py`と`proto_pb2_grpc.py`を生成
python -m grpc_tools.protoc -I./protos --python_out=./ml/protolib --grpc_python_out=./ml/protolib ./protos/proto.proto

※Pythonは注意が必要

Module化に伴い/ml/protolib/proto_pb2_grpc.pyのimportを適宜修正

変更前

import proto_pb2 as proto__pb2

変更後

import protolib.proto_pb2 as proto__pb2

Activate

環境変数は./env.shを適宜いじる。

# golang
cd server
source ../env.sh && go run ./main.go

# python
cd ml
source ../env.sh && python3 ./main.py

Deploy

gcloud container clusters create k8s --cluster-version 1.13.7-gke.8 --zone asia-northeast1-a --num-nodes 3 --project XXX
gcloud container clusters get-credentials k8s --zone asia-northeast1-a # kubernetesのCredentialを~/.kube/configに保存

kubectl

kubectl apply -f kubernetes/deploy.yaml --prune --all # update, create, or delete

watch kubectl get pods # watching pods
watch kubectl top pods # used pod resources
watch kubectl get nodes # watching nodes
watch kubectl top nodes # used node resources

kubectl describe node [node_name]  # check node resource usage

kubectl delete -f kubernetes/deploy.yaml # delete all

About

golang and python server connecting via grpc template


Languages

Language:Go 64.4%Language:Python 22.2%Language:Dockerfile 9.2%Language:Shell 4.3%