Coder Social home page Coder Social logo

zengyuxing007 / kubernetes-envoy-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bakins/kubernetes-envoy-example

0.0 2.0 0.0 22.9 MB

Teaching myself about Envoy on Kubernetes

License: Apache License 2.0

Shell 8.95% Go 73.73% PHP 17.32%

kubernetes-envoy-example's Introduction

Kubernetes Envoy Example

A sample application using Envoy running in Kubernetes.

Motivation

I wanted to learn more about Envoy, so I decided to do it "the hard way." I wrote the contrived example application and pieced together the Envoy configurations from the documentation and examples.

Sample Application Summary

The sample application is fairly straight forward. It has four components:

  • frontend - HTTP service written in Go. It accepts the request from the client and makes calls to the other services.
  • user - gRPC service written in Go. Manages user information.
  • order - gRPC service written in Go. Tracks orders. Makes calls to the item service for details about each ordered item.
  • item - gRPC service written in PHP (more on this below). Inventory of items.

The basic flow of data through the service is

Logical Architecture

Services do not communicate directly with one another. All communication is via Envoy. An Envoy instance - named ingress - acts as the entrypoint into the cluster. This is similar to the "Service to service plus front proxy" example.

The network flow of data is

Service Communication

Services Detail

Each instance of each service runs in a Kubernetes pod. Each pod has multiple containers:

  • the application itself
  • Envoy proxy
  • statsd_exporter - Envoy emits metrics using statsd. statsd_exporter is a statsd server that exposes these metrics fo consumption by Prometheus.

The ingress contains only Envoy and statsd exporter.

The Envoy container in each pod listens on one port (8080) for incoming requests and routes these to the local application running within the pod. Envoy listens on a different port (7070) for outbound requests. Applications make requests to http://127.0.0.1:7070 for other services rather than connecting direct. See order.json for example.

All the applications expose metrics for Prometheus.

The frontend is the user facing service. It accepts HTTP/1.1 requests on the front and makes gRPC requests to the other services.

The item service uses grpc-fastcgi-proxy to expose a simple PHP applciation. This service could represent a legacy system written in PHP that we wish to expose.

The other services - user and order - are simple gRPC services written in Go.

Tracing

Jaeger is used for tracing. Envoy is configured to send tracing information to the Zipkin compatible endpoint of Jaeger.

The applications do not send any data to Jaeger. They only ensure the tracing headers are propogated.

Service Discovery

Envoy handles all service discovery - the applications just contact Envoy on lcoal host. Kubernetes headless services are used. This means a DNS request for the service will return a record for each running Pod. This is a simple service discovery mechanism that does not require additional helper services.

Usage

This example is designed to be ran on minikube. A working Go environment is required. Once minikube is installed and running, one should clone this repository into the GOPATH:

mkdir -p $HOME/go/src/github.com/bakins
git clone https://github.com/bakins/kubernetes-envoy-example.git
cd kubernetes-envoy-example

Now to build and deploy the example applications:

  • ./script/build will build the applications and push Docker images into the minikube Docker environment.
  • ./script/deploy will deploy the Kubernetes manifests.

After a few seconds, you should be able to access the application by running minikube service ingress - you should see a simple json body.

To access jaeger, run minikube service jaeger-query. You may need to reload in the browser a few times.

Prometheus is available via minikube service prometheus. You should be able to run adhoc queries for metrics.

TODO: grafana dashboards

Prometheus Queries

histogram_quantile(0.95, sum(rate(envoy_upstream_rq_time_bucket{cluster!="local_service"}[5m])) by (le,app, cluster))

sum(rate(envoy_upstream_rq_time_count{cluster!="local_service"}[5m])) by (app, cluster)

sum(envoy_health_check_healthy) by (app,cluster)

sum(envoy_upstream_cx_total) by (app,cluster)

LICENSE

See LICENSE

kubernetes-envoy-example's People

Contributors

bakins avatar

Watchers

James Cloos avatar  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.