• This repository has been archived on 21/Dec/2018
  • Stars
    star
    120
  • Rank 294,425 (Top 6 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Teaching myself about Envoy on Kubernetes

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

More Repositories

1

php-fpm-exporter

Prometheus exporter for php-fpm status.
Go
181
star
2

kubernetes-coreos-terraform

Simple Kubernetes cluster on CoreOS in AWS using Terraform
HCL
113
star
3

minikube-prometheus-demo

Simple demo using minikube to deploy Prometheus and Grafana
Shell
106
star
4

omnibus-nginx

Omnibus packaging for Openresty/nginx
Ruby
36
star
5

cookbook-gdebi

Simple cookbook that wraps gdebi
Ruby
34
star
6

lua-resty-riak

Lua riak protocol buffer client driver for the ngx_lua based on the cosocket API
Lua
25
star
7

gearman-exporter

Gearmand metrics exporter for Prometheus
Go
21
star
8

alertmanager-webhook-example

simple webhook receiver for Prometheus Alertmanager
Go
18
star
9

zocker

bocker with ZFS: ZFS based "docker" implementation in bash
Shell
16
star
10

lua-resty-beanstalkd

Simple Beanstalkd client for nginx/openresty
Lua
15
star
11

kube-log-tail

Deprecated. I now use https://github.com/wercker/stern
Go
15
star
12

ansible-runit

Ansible role for runit
Python
13
star
13

nginx-example-lua-module

C
13
star
14

logrus-middleware

Simple logging middleware for Go net/http
Go
12
star
15

zfsd

Simple HTTP interface for ZFS
Go
12
star
16

k8s-client

Simple Kubernetes client for Go
Go
11
star
17

knife-fifo

Project Fifo Support for Chef's Knife Command
Ruby
11
star
18

vagrant-chef-apply

Simple Vagrant provisioner using chef-apply
Ruby
10
star
19

stardust

Simple OpenResty web framework
Lua
8
star
20

grpc-fastcgi-proxy

WIP: grpc to fastcgi proxy
Go
7
star
21

zfs-flex-volume

Simple ZFS flexVolume driver for Kubernetes
Go
7
star
22

terraform-provider-etcd

etcd provider for Terraform
Go
7
star
23

alertmanager-config-controller

Construct an Alertmanager config from snippets stored in Kubernetes ConfigMaps
Go
6
star
24

terraform-provider-coreos

Terraform Provider for getting the latest CoreOS AMI
Go
6
star
25

protoc-gen-php-grpc

Experimental PHP gRPC server generation
PHP
6
star
26

project-fifo-ruby

Basic Ruby client for project-fifo
Ruby
6
star
27

iap-token-source

Go oauth2 Token Source for client authentication with GCP Identity Aware Proxy
Go
5
star
28

terraform-provider-kubernetes

Placeholder for a Kubernetes provider for Terraform
Go
5
star
29

json-rpc-example

Example JSON-RPC over HTTP server in Go using Gorilla
Go
5
star
30

k8s-nginx

Simple nginx proxy for kubernetes api
Shell
4
star
31

kitchen-fifo

Project-FIFO driver for Kitchen
Ruby
4
star
32

lua-resty-logstash-logger

Simple logger for ngx_lua for logging directly to logstash
Lua
4
star
33

diary

Simple Log package for Go
Go
3
star
34

vagrant-fifo

Vagrant provider for Project-FiFo
Ruby
3
star
35

lua-resty-redis-lock

Simple locking mechanism for redis in nginx/Lua
Lua
3
star
36

ngx_http_filter_cache

C
3
star
37

openresty-buildpack

Simple buildpack for openresty apps
Shell
3
star
38

slogotlp

OPenTelemetry otlp exporter for slog
Go
3
star
39

openresty-example-app

Example app using openresty-buildpack
Ruby
3
star
40

prometheus-http-discovery

Prometheus sidecar to discover targets by calling HTTP endpoints
Go
3
star
41

statsd-exporter-convert

Converter for statsd_exporter mappings config
Go
3
star
42

neckbeard

JSON log munger and forwarder for logstash
2
star
43

nginx-php-grpc

PHP gRPC server using only nginx
PHP
2
star
44

fog-fifo

Initial Fifo driver for fog
Ruby
2
star
45

single-box-kubernetes

Simple, single box Kubernetes install on CoreOS using Vagrant
Shell
2
star
46

twirpzap

Structured logs for twirp servers using zap
Go
2
star
47

grpc-the-hard-way

Go gRPC clients and servers written without using https://github.com/grpc/grpc-go
Go
2
star
48

configmap-aggregator

Aggregate multiple Kubernetes configmaps into a single one.
Go
2
star
49

blog

Brian's blog
Ruby
1
star
50

go-real-ip

Go net/http middleware inspired by nginx real_ip
Go
1
star
51

kubernetes-goodies-list

List of Interesting Kubernetes addons, etc
1
star
52

protoc-gen-grpc-transcode

Protoc plugin to generate json->grpc transcoder for Go
Go
1
star
53

simple-process-manager

Experimental simple process manager
Go
1
star
54

openresty-docker

Shell
1
star
55

ansible-runit-module

simple runit module for ansible
Python
1
star
56

cookbook-riak-cluster

Simple cookbook for creating riak clusters
Ruby
1
star
57

grpc-fastcgi-example

Example application for use with grpc-fastcgi-proxy
PHP
1
star
58

tcp2stdout

Copy from TCP socket to STDOUT
Go
1
star
59

dial-dns-cache

DNS caching Dialer for Go
Go
1
star
60

main-combiner

Combine multiple Go main packages into a single binary
Go
1
star
61

etcd-helper

Simple etcd cluster helper
Go
1
star
62

coreos-kubernetes-ansible

WIP for Ansible+CoreOS+Vagrant+Kubernetes
1
star
63

kubernetes-example-controller

Example Kubernetes controller for a custom resource
Go
1
star
64

go-metrics-map

Simple map-based store for go-metrics
Go
1
star
65

omnibus-couchdb

very simple omnibus for couch
Ruby
1
star
66

berkshelf-gitpattern

Simple helper for berkshelf to add locations with template
Ruby
1
star
67

lua-resty-statsd

Statsd client for OpenResty
Lua
1
star
68

static-pod-validate

CLI utility for validating Kubernetes static pod manifests
Go
1
star
69

k8s-pod-deleter

Delete Kubernetes pods that have failed
Go
1
star
70

pubsub-push-middleware

PubSub Push helper for Go HTTP servers
1
star
71

net-http-recover

Simple Go net/http recovery middleware
Go
1
star
72

kubernetes-grafana-updater

Update grafana dasboards and datasources from data in Kubernetes
Go
1
star
73

octwirp

OpenCensus instrumentation for twirp services in Go
Go
1
star
74

grpc-client-transcode

Experiment with client side gRPC to HTTP/1.1 transcoding.
Go
1
star
75

pubsuboutput

GCP PubSub output for Elastic Filebeat
Go
1
star
76

simple-queue

Silly, simple local queue written in go. Inspired by beanstalkd using sqlite
Go
1
star
77

sops-wrap

Convenience wrapper for Mozilla sops
Go
1
star