Coder Social home page Coder Social logo

akka-grpc-sample-kubernetes-scala's Introduction

Akka gRPC Kubernetes

This is an example of an Akka HTTP application communicating with an Akka gRPC application inside of Kubernetes.

This example does not show Akka Cluster. If you are interested in Akka Cluster, see for the 'Cluster' examples (for Scala or Java), 'Akka Cluster with docker-compose' (for Scala or Java) or 'Akka Cluster on Kubernetes (for Java)

The Akka HTTP application discovers the Akka gRPC application using Akka Discovery. It uses the akka-dns mechanism which relies on the SRV records created by kubernetes.

All the technologies used in this example are open source.

Other approaches

This project uses sbt and the Scala language.

If you are using Java and sbt you can use exactly the same approach.

If you are using another build tool, such as Maven or Gradle, the code would still be the same, but you would have to build the Docker image and deploy it to Kubernetes yourself.

Usage

Prerequisites

Install the following:

Running

Once minikube is running and ingress enabled with minikube addons enable ingress, the two applications can be deployed using:

kubectl apply -f kubernetes/grpcservice.yml

and

kubectl apply -f kubernetes/httptogrpc.yml

Verify the deployments:

$ kubectl get deployments
NAME                          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
grpcservice-v0-1-0-snapshot   1         1         1            1           40s
httptogrpc-v0-1-0-snapshot    1         1         1            1           40s

There are services for both:

$ kubectl get services
NAME          TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
grpcservice   ClusterIP   10.106.188.203   <none>        8080/TCP   1m
httptogrpc    ClusterIP   10.103.134.197   <none>        8080/TCP   1m

Ingress just for the HTTP app:

$ kubectl get ingress
NAME         HOSTS              ADDRESS   PORTS     AGE
httptogrpc   superservice.com             80        2m

The HTTP application periodically hits the gRPC applicaton which you can see in the logs:

[INFO] [08/15/2018 07:02:51.712] [HttpToGrpc-akka.actor.default-dispatcher-4] [akka.actor.ActorSystemImpl(HttpToGrpc)] Scheduled say hello to chris
[INFO] [08/15/2018 07:02:51.730] [HttpToGrpc-akka.actor.default-dispatcher-4] [akka.actor.ActorSystemImpl(HttpToGrpc)] Scheduled say hello response Success(HelloReply(Hello, Christopher))

And you can send a HTTP request via Ingress to the httptogrpc application:

$ curl -v --header 'Host: superservice.com' $(minikube ip)/hello/donkey
> GET /hello/donkey HTTP/1.1
> Host: superservice.com
> User-Agent: curl/7.59.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx/1.13.12
< Date: Wed, 15 Aug 2018 07:03:56 GMT
< Content-Type: text/plain; charset=UTF-8
< Content-Length: 13
< Connection: keep-alive
< 
* Connection #0 to host 192.168.99.100 left intact
Hello, donkey%

The Host header needs to be set as that is how minikube Ingress routes requests to services.

akka-grpc-sample-kubernetes-scala's People

Contributors

b-vesco avatar chbatey avatar ennru avatar ignasi35 avatar octonato avatar raboof avatar scala-steward avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.