Skip to content

Commit

Permalink
service mesh with envoy and docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
dnivra26 committed Nov 4, 2018
0 parents commit b8cd2ef
Show file tree
Hide file tree
Showing 13 changed files with 466 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Readme.md
@@ -0,0 +1,8 @@
## Serice Mesh with Envoy
![setup](https://raw.githubusercontent.com/dnivra26/envoy_servicemesh/master/envoy_servicemesh.png)


### Run:
1. `docker-compose build`
2. `docker-compose up`
3. Hit http://localhost:8080
50 changes: 50 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,50 @@
version: '3'
services:
front-envoy:
image: envoyproxy/envoy-alpine:v1.7.0
volumes:
- ./front_envoy/envoy-config.yaml:/etc/envoy-config.yaml
ports:
- "8080:80"
- "9901:9901"
command: "/usr/local/bin/envoy -c /etc/envoy-config.yaml --v2-config-only -l info --service-cluster 'front-envoy' --service-node 'front-envoy' --log-format '[METADATA][%Y-%m-%d %T.%e][%t][%l][%n] %v'"

service_a_envoy:
image: envoyproxy/envoy-alpine:v1.7.0
volumes:
- ./service_a/envoy-config.yaml:/etc/envoy-config.yaml
ports:
- "8786:8786"
- "8788:8788"
command: "/usr/local/bin/envoy -c /etc/envoy-config.yaml --v2-config-only -l info --service-cluster 'service-a' --service-node 'service-a' --log-format '[METADATA][%Y-%m-%d %T.%e][%t][%l][%n] %v'"

service_a:
build: service_a/
ports:
- "8081:8081"

service_b_envoy:
image: envoyproxy/envoy-alpine:v1.7.0
volumes:
- ./service_b/envoy-config.yaml:/etc/envoy-config.yaml
ports:
- "8789:8789"
command: "/usr/local/bin/envoy -c /etc/envoy-config.yaml --v2-config-only -l info --service-cluster 'service-b' --service-node 'service-b' --log-format '[METADATA][%Y-%m-%d %T.%e][%t][%l][%n] %v'"

service_b:
build: service_b/
ports:
- "8082:8082"

service_c_envoy:
image: envoyproxy/envoy-alpine:v1.7.0
volumes:
- ./service_c/envoy-config.yaml:/etc/envoy-config.yaml
ports:
- "8790:8790"
command: "/usr/local/bin/envoy -c /etc/envoy-config.yaml --v2-config-only -l info --service-cluster 'service-c' --service-node 'service-c' --log-format '[METADATA][%Y-%m-%d %T.%e][%t][%l][%n] %v'"

service_c:
build: service_c/
ports:
- "8083:8083"
Binary file added envoy_servicemesh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions front_envoy/envoy-config.yaml
@@ -0,0 +1,51 @@
---
admin:
access_log_path: "/tmp/admin_access.log"
address:
socket_address:
address: "127.0.0.1"
port_value: 9901
static_resources:
listeners:
-
name: "http_listener"
address:
socket_address:
address: "0.0.0.0"
port_value: 80
filter_chains:
filters:
-
name: "envoy.http_connection_manager"
config:
stat_prefix: "ingress"
codec_type: "AUTO"
generate_request_id: true
route_config:
name: "local_route"
virtual_hosts:
-
name: "http-route"
domains:
- "*"
routes:
-
match:
prefix: "/"
route:
cluster: "service_a"
http_filters:
-
name: "envoy.router"
clusters:
-
name: "service_a"
connect_timeout: "0.25s"
type: "strict_dns"
lb_policy: "ROUND_ROBIN"
hosts:
-
socket_address:
address: "service_a_envoy"
port_value: 8786

4 changes: 4 additions & 0 deletions service_a/Dockerfile
@@ -0,0 +1,4 @@
FROM golang:alpine
COPY main.go main.go

CMD go run main.go
132 changes: 132 additions & 0 deletions service_a/envoy-config.yaml
@@ -0,0 +1,132 @@
admin:
access_log_path: "/tmp/admin_access.log"
address:
socket_address:
address: "127.0.0.1"
port_value: 9901
static_resources:
listeners:

-
name: "service-a-svc-http-listener"
address:
socket_address:
address: "0.0.0.0"
port_value: 8786
filter_chains:
-
filters:
-
name: "envoy.http_connection_manager"
config:
stat_prefix: "ingress"
codec_type: "AUTO"
route_config:
name: "service-a-svc-http-route"
virtual_hosts:
-
name: "service-a-svc-http-route"
domains:
- "*"
routes:
-
match:
prefix: "/"
route:
cluster: "service_a"
http_filters:
-
name: "envoy.router"
-
name: "service-b-svc-http-listener"
address:
socket_address:
address: "0.0.0.0"
port_value: 8788
filter_chains:
-
filters:
-
name: "envoy.http_connection_manager"
config:
stat_prefix: "egress"
codec_type: "AUTO"
route_config:
name: "service-b-svc-http-route"
virtual_hosts:
-
name: "service-b-svc-http-route"
domains:
- "*"
routes:
-
match:
prefix: "/"
route:
cluster: "service_b"
http_filters:
-
name: "envoy.router"

-
name: "service-c-svc-http-listener"
address:
socket_address:
address: "0.0.0.0"
port_value: 8791
filter_chains:
-
filters:
-
name: "envoy.http_connection_manager"
config:
stat_prefix: "egress"
codec_type: "AUTO"
route_config:
name: "service-b-svc-http-route"
virtual_hosts:
-
name: "service-b-svc-http-route"
domains:
- "*"
routes:
-
match:
prefix: "/"
route:
cluster: "service_c"
http_filters:
-
name: "envoy.router"
clusters:
-
name: "service_a"
connect_timeout: "0.25s"
type: "strict_dns"
lb_policy: "ROUND_ROBIN"
hosts:
-
socket_address:
address: "service_a"
port_value: 8081
-
name: "service_b"
connect_timeout: "0.25s"
type: "strict_dns"
lb_policy: "ROUND_ROBIN"
hosts:
-
socket_address:
address: "service_b_envoy"
port_value: 8789

-
name: "service_c"
connect_timeout: "0.25s"
type: "strict_dns"
lb_policy: "ROUND_ROBIN"
hosts:
-
socket_address:
address: "service_c_envoy"
port_value: 8790
75 changes: 75 additions & 0 deletions service_a/main.go
@@ -0,0 +1,75 @@
package main

import (
"fmt"
"io/ioutil"
"log"

"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {

fmt.Fprintf(w, "Calling Service B")

req, err := http.NewRequest("GET", "http://service_a_envoy:8788/", nil)
if err != nil {
fmt.Printf("%s", err)
}

req.Header.Add("x-request-id", r.Header.Get("x-request-id"))
req.Header.Add("x-b3-traceid", r.Header.Get("x-b3-traceid"))
req.Header.Add("x-b3-spanid", r.Header.Get("x-b3-spanid"))
req.Header.Add("x-b3-parentspanid", r.Header.Get("x-b3-parentspanid"))
req.Header.Add("x-b3-sampled", r.Header.Get("x-b3-sampled"))
req.Header.Add("x-b3-flags", r.Header.Get("x-b3-flags"))
req.Header.Add("x-ot-span-context", r.Header.Get("x-ot-span-context"))

client := &http.Client{}
resp, err := client.Do(req)

if err != nil {
fmt.Printf("%s", err)
}

defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("%s", err)
}
fmt.Fprintf(w, string(body))
fmt.Fprintf(w, "Hello from service A")

req, err = http.NewRequest("GET", "http://service_a_envoy:8791/", nil)
if err != nil {
fmt.Printf("%s", err)
}

req.Header.Add("x-request-id", r.Header.Get("x-request-id"))
req.Header.Add("x-b3-traceid", r.Header.Get("x-b3-traceid"))
req.Header.Add("x-b3-spanid", r.Header.Get("x-b3-spanid"))
req.Header.Add("x-b3-parentspanid", r.Header.Get("x-b3-parentspanid"))
req.Header.Add("x-b3-sampled", r.Header.Get("x-b3-sampled"))
req.Header.Add("x-b3-flags", r.Header.Get("x-b3-flags"))
req.Header.Add("x-ot-span-context", r.Header.Get("x-ot-span-context"))

client = &http.Client{}
resp, err = client.Do(req)

if err != nil {
fmt.Printf("%s", err)
}

defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("%s", err)
}

fmt.Fprintf(w, string(body))
}

func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8081", nil))
}
4 changes: 4 additions & 0 deletions service_b/Dockerfile
@@ -0,0 +1,4 @@
FROM golang:alpine
COPY main.go main.go

CMD go run main.go
51 changes: 51 additions & 0 deletions service_b/envoy-config.yaml
@@ -0,0 +1,51 @@
admin:
access_log_path: "/tmp/admin_access.log"
address:
socket_address:
address: "127.0.0.1"
port_value: 9901
static_resources:
listeners:

-
name: "service-b-svc-http-listener"
address:
socket_address:
address: "0.0.0.0"
port_value: 8789
filter_chains:
-
filters:
-
name: "envoy.http_connection_manager"
config:
stat_prefix: "ingress"
codec_type: "AUTO"
route_config:
name: "service-b-svc-http-route"
virtual_hosts:
-
name: "service-b-svc-http-route"
domains:
- "*"
routes:
-
match:
prefix: "/"
route:
cluster: "service_b"
http_filters:
-
name: "envoy.router"

clusters:
-
name: "service_b"
connect_timeout: "0.25s"
type: "strict_dns"
lb_policy: "ROUND_ROBIN"
hosts:
-
socket_address:
address: "service_b"
port_value: 8082

0 comments on commit b8cd2ef

Please sign in to comment.