diff --git a/README.md b/README.md index 7b26726..d3c2b45 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # edge-envoy An edge envoy proxy configuration for kubernetes + +## Setup Instructions + +``` bash + + kubectl create ns edge-envoy + + cd k8s-deployment + + ./deploy-config.sh + + kubectl apply -f edge-envoy-deployment.yaml + + ``` \ No newline at end of file diff --git a/envoy/envoy-traffic-campaign-header.json b/envoy/envoy-traffic-campaign-header.json new file mode 100644 index 0000000..015e872 --- /dev/null +++ b/envoy/envoy-traffic-campaign-header.json @@ -0,0 +1,82 @@ +{ + "listeners": [ + { + "name": "http-ingress", + "address": "tcp://0.0.0.0:80", + "filters": [ + { + "type": "read", + "name": "http_connection_manager", + "config": { + "codec_type": "auto", + "stat_prefix": "ingress-http", + "route_config": { + "virtual_hosts": [ + { + "name": "node-app-latest-hosts", + "domains": [ "*" ], + "routes": [ + { + "timeout_ms": 0, + "prefix": "/", + "cluster": "node-app-campaign", + "headers":[ + { + "name": "X-Campaign", + "value": "true" + } + ] + }, + { + "timeout_ms": 0, + "prefix": "/", + "cluster": "node-app-latest" + } + ] + } + ] + }, + "filters": [ + { + "type": "decoder", + "name": "router", + "config": {} + } + ] + } + } + ] + } + ], + "admin": { + "access_log_path": "/var/log/envoy/admin-access.log", + "address": "tcp://127.0.0.1:9999" + }, + "cluster_manager": { + "clusters": [ + { + "name": "node-app-latest", + "connect_timeout_ms": 250, + "type": "logical_dns", + "lb_type": "round_robin", + "hosts": [ + { + "url": "tcp://node-app-latest.envoy-testing.svc.cluster.local:80" + } + ] + }, + { + "name": "node-app-campaign", + "connect_timeout_ms": 250, + "type": "logical_dns", + "lb_type": "round_robin", + "hosts": [ + { + "url": "tcp://node-app-campaign.envoy-testing.svc.cluster.local:80" + } + ] + } + ] + } +} + \ No newline at end of file diff --git a/envoy/envoy-traffic-shift-10-90.json b/envoy/envoy-traffic-shift-10-90.json new file mode 100644 index 0000000..922ded8 --- /dev/null +++ b/envoy/envoy-traffic-shift-10-90.json @@ -0,0 +1,84 @@ +{ + "listeners": [ + { + "name": "http-ingress", + "address": "tcp://0.0.0.0:80", + "filters": [ + { + "type": "read", + "name": "http_connection_manager", + "config": { + "codec_type": "auto", + "stat_prefix": "ingress-http", + "route_config": { + "virtual_hosts": [ + { + "name": "node-app-latest-hosts", + "domains": [ "*" ], + "routes": [ + { + "timeout_ms": 0, + "prefix": "/", + "cluster": "node-app-latest", + "runtime": { + "key": "routing.ts.node-app.latest", + "default": 100 + } + }, + { + "timeout_ms": 0, + "prefix": "/", + "cluster": "node-app-campaign" + } + ] + } + ] + }, + "filters": [ + { + "type": "decoder", + "name": "router", + "config": {} + } + ] + } + } + ] + } + ], + "admin": { + "access_log_path": "/var/log/envoy/admin-access.log", + "address": "tcp://127.0.0.1:9999" + }, + "runtime": { + "symlink_root": "/srv/runtime", + "subdirectory": "envoy" + }, + "cluster_manager": { + "clusters": [ + { + "name": "node-app-latest", + "connect_timeout_ms": 250, + "type": "logical_dns", + "lb_type": "round_robin", + "hosts": [ + { + "url": "tcp://node-app-latest.envoy-testing.svc.cluster.local:80" + } + ] + }, + { + "name": "node-app-campaign", + "connect_timeout_ms": 250, + "type": "logical_dns", + "lb_type": "round_robin", + "hosts": [ + { + "url": "tcp://node-app-campaign.envoy-testing.svc.cluster.local:80" + } + ] + } + ] + } +} + \ No newline at end of file diff --git a/envoy/envoy.json b/envoy/envoy.json new file mode 100644 index 0000000..ab16528 --- /dev/null +++ b/envoy/envoy.json @@ -0,0 +1,60 @@ +{ + "listeners": [ + { + "name": "http-ingress", + "address": "tcp://0.0.0.0:80", + "filters": [ + { + "type": "read", + "name": "http_connection_manager", + "config": { + "codec_type": "auto", + "stat_prefix": "ingress-http", + "route_config": { + "virtual_hosts": [ + { + "name": "node-app-latest-hosts", + "domains": [ "*" ], + "routes": [ + { + "timeout_ms": 0, + "prefix": "/", + "cluster": "node-app-latest" + } + ] + } + ] + }, + "filters": [ + { + "type": "decoder", + "name": "router", + "config": {} + } + ] + } + } + ] + } + ], + "admin": { + "access_log_path": "/var/log/envoy/admin-access.log", + "address": "tcp://127.0.0.1:9999" + }, + "cluster_manager": { + "clusters": [ + { + "name": "node-app-latest", + "connect_timeout_ms": 250, + "type": "logical_dns", + "lb_type": "round_robin", + "hosts": [ + { + "url": "tcp://node-app-latest.envoy-testing.svc.cluster.local:80" + } + ] + } + ] + } +} + \ No newline at end of file diff --git a/envoy/runtime/routing_ts_node-app_latest b/envoy/runtime/routing_ts_node-app_latest new file mode 100644 index 0000000..c5b431b --- /dev/null +++ b/envoy/runtime/routing_ts_node-app_latest @@ -0,0 +1 @@ +50 \ No newline at end of file diff --git a/k8s-deployment/deploy-config.sh b/k8s-deployment/deploy-config.sh new file mode 100755 index 0000000..4ea070c --- /dev/null +++ b/k8s-deployment/deploy-config.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ "$#" -ne 1 ] ; then + echo "Usage: $0 " >&2 + echo "assuming the traffic configuration is \"simple load balancing\"" + config_file="../envoy/envoy.json" + else + config_file=$1 +fi + +rt_config_file="../envoy/runtime/routing_ts_node-app_latest" + +kubectl create configmap edge-envoy-config --from-file=envoy.json=$config_file --namespace edge-envoy -o yaml --dry-run | kubectl apply -f - +kubectl create configmap edge-envoy-rt-config --from-file=latest=$rt_config_file --namespace edge-envoy -o yaml --dry-run | kubectl apply -f - \ No newline at end of file diff --git a/k8s-deployment/edge-envoy-deployment.yaml b/k8s-deployment/edge-envoy-deployment.yaml new file mode 100644 index 0000000..4fc0d16 --- /dev/null +++ b/k8s-deployment/edge-envoy-deployment.yaml @@ -0,0 +1,62 @@ +apiVersion: v1 +kind: Service +metadata: + name: edge-envoy + #annotations: + # service.beta.kubernetes.io/azure-load-balancer-internal: "true" +spec: + selector: + run: edge-envoy + type: LoadBalancer + ports: + - name: http + port: 80 + targetPort: 80 +--- +#apiVersion: apps/v1 #v1.9.x +apiVersion: extensions/v1beta1 #v1.8.x +kind: Deployment +metadata: + name: edge-envoy + labels: + run: edge-envoy +spec: + replicas: 1 + selector: + matchLabels: + run: edge-envoy + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + template: + metadata: + labels: + run: edge-envoy + spec: + containers: + # Edge Envoy Proxy Container + - image: envoyproxy/envoy-alpine:latest + command: + - "/usr/local/bin/envoy" + args: + - "--config-path /etc/envoy/envoy.json" + - "--mode serve" + imagePullPolicy: Always + name: edge-envoy + ports: + - containerPort: 80 + protocol: TCP + volumeMounts: + - name: edge-envoy-config + mountPath: /etc/envoy + - name: edge-envoy-rt-config + mountPath: /srv/runtime/envoy/routing/ts/node-app + volumes: + - name: edge-envoy-config + configMap: + name: edge-envoy-config + - name: edge-envoy-rt-config + configMap: + name: edge-envoy-rt-config \ No newline at end of file