Sign inSign up

himanshusdec8/rpc

By himanshusdec8

•Updated about 6 years ago

two services with grpc-rest api gateway

Image
0

1.5K

himanshusdec8/rpc repository overview

⁠RPC services

Rpc servcies in golang using grpc with protobuff

⁠Getting Started

Include grpc-rest api gateway for rest to rpc calls

⁠Running server

⁠Mysql Server

create a my sql user with privileges

$ go run cmd/server/main.go -grpc-port=9090 -db-host=127.0.0.1:3306 -db-user=`db-user` -db-password=`db-pass` -db-schema=`db-name`

⁠Running Client

$ go run cmd/client-grpc/main.go -server=127.0.0.1:9090

⁠Deployment (Local)

⁠build a docker image
$ docker build -t rpc .
⁠get host ip to connect docker container with database running on localhost
$ ifconfig | grep "inet " | grep -v 127.0.0.1

Note:- update host-ip with ip of docker host

⁠run the docker image with env_file for environment variables and add host address of docker (for linux: $ ip addr show)
$ docker run --env-file env_file --add-host=mysql_server:$(host_ip) -d -p 9090:9090 --name rpc-server rpc:latest
⁠run the client with ip of docker host
$ go run cmd/client-grpc/main.go -server=$(host_ip):9090
⁠or you can push dockerfile to docker hub to build a docker image

Automated builds with docker using docker hub

⁠Versioning

Version 1.0.0

⁠Authors

⁠Starting server

⁠To update the image from docker after pushing to github use

$ kubectl set image deployment/rpc-minikube rpc=`docker-username`/`docker-repo`:`repo-tag`

⁠Connecting to local host using docker in local environment

⁠Create a docker image and run the container using :-
$ docker run --net=host --publish 90:90 image_name
⁠--net=host option will let docker container to connect with localhost database
⁠minikube deployement
  • create a service without selector to connect to local mysql database
$ kubectl apply -f service.yaml
  • create a deployment with image on docker hub address using yaml
$ kubectl apply -f deployment.yaml
  • credentials of docker repository to be saved inside regcred of deployment.yaml
$ kubectl create secret docker-registry regcred --docker-username=`username` --docker-password=`password` --docker-email=`email`
  • run deployment with 2 replica in current case to scale
  • create a service to expose the deployment outside of cluster which will be needed to access by grpc client from local system.

Note:- The service will be exposed like below:

kubectl expose deployment rpc-deployment --type=NodePort --port=grpc-server-port-exposed-in-docker --name=rpc-service

grpc-server-port will be port on which grpc server is running

⁠test to check if deployment is running

get exposed service url using:-

minikube service exposed-service-name --url

⁠testing service on minikube-

$ go run main.go -server=`service-url:NodePort`

or check the logs of running pods to verify if service is running

grpc client

$ go run cmd/client-grpc/main.go -server=`service-url:NodePort`
example:-
$ go run cmd/client-grpc/main.go -server=192.168.5.182:31442

Its done !

debugging minikube service:-

$ kubectl get svc

Note:

[x] get the clusterIP of svc on which mysql is running and try to access the same using that url.

$ mysql -h `service-ip`:`port` -u `mysql-user` -p

[x] Checking mysql service inside pods:-

$ mysql -u `user-name` -p `password`
$ mysql> show processlist;

Above command will show if the running pods are connected to mysql local or not.

Tag summary

Content type

Image

Digest

Size

20.2 MB

Last updated

about 6 years ago

docker pull himanshusdec8/rpc