Skip to content

Commit

Permalink
Merge pull request #17 from pradeepmvn/feature/multi-servers
Browse files Browse the repository at this point in the history
Feature/multi servers
  • Loading branch information
pradeepmvn authored Nov 17, 2022
2 parents a1663f7 + ff44ee7 commit bc5971b
Show file tree
Hide file tree
Showing 11 changed files with 432 additions and 18 deletions.
4 changes: 3 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func main() {

// Create a cache
var l log.CLog
cache := cache.NewSnapshotCache(true, cache.IDHash{}, l)
// ADS flag forces a delay in responding to streaming requests until all resources are explicitly named in the request.
// Making it to false to make it convinient for one control plane to send partial responses to clients.
cache := cache.NewSnapshotCache(false, cache.IDHash{}, l)

// Start the snapshot refresher..
sn := snapshot.NewSnapshot(cfg, cache)
Expand Down
31 changes: 29 additions & 2 deletions example/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,47 @@ To run example on a local cluster.,
docker build -t xds.example/xds-controller .
docker build -t xds.example/client -f example/Dockerfile --build-arg TYPE=client example
docker build -t xds.example/server -f example/Dockerfile --build-arg TYPE=server example
docker pull envoyproxy/envoy:v1.24.0
```

### Deployments
#### Pattern 1: CLient server communication using xds:look aside load balancing
```
### Deploy
kubectl create namespace xds-test
kubectl apply -f example/k8s/xds-controller.deployment.yaml -n xds-test
kubectl apply -f example/k8s/server.deployment.yaml -n xds-test
kubectl apply -f example/k8s/client.deployment.yaml -n xds-test
kubectl apply -f example/k8s/envoy.deployment.yaml -n xds-test
```
#### Pattern 2: Client with 2 servers communication using xds:look aside load balancing
```
kubectl create namespace xds-test
kubectl apply -f example/k8s/xds-controller.deployment.yaml -n xds-test
kubectl apply -f example/k8s/server.deployment.yaml -n xds-test
kubectl apply -f example/k8s/server.b.deployment.yaml -n xds-test
kubectl apply -f example/k8s/client.deployment.yaml -n xds-test
```

#### Pattern 3: External Client proxied via Envoy L7 Load balancer (No xds) using static dns
```
kubectl create namespace xds-test
kubectl apply -f example/k8s/server.deployment.yaml -n xds-test
kubectl apply -f example/k8s/envoy.deployment.yaml -n xds-test
```
#### Pattern 4: External Client proxied via Envoy L7 Load balancer. Evoy using xDS stream to discover server
```
kubectl create namespace xds-test
kubectl apply -f example/k8s/xds-controller.deployment.yaml -n xds-test
kubectl apply -f example/k8s/server.deployment.yaml -n xds-test
kubectl apply -f example/k8s/envoy.deployment.yaml -n xds-test
```


### Metrics
xds-controller exposes metrics via /metrics endpoint by default on 8082 port. Portforwarding can be used to hit localhost and see the metric details

```
// get pods
// get pods
kubectl get pods -n xds-test
kubectl port-forward {pod-name} 8082:8082 -n xds-test
curl localhost:8082/metrics
Expand Down
149 changes: 149 additions & 0 deletions example/k8s/envoy.deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: envoy-deployment
labels:
app: envoy
spec:
replicas: 1
selector:
matchLabels:
app: envoy
template:
metadata:
labels:
app: envoy
spec:
containers:
- name: envoy
command:
- envoy
args:
- "-c /etc/envoy/envoy.yaml"
- "--log-level info"
- "--log-format %L. envoy]%v"
- "--log-format-escaped"
- "--enable-fine-grain-logging"
- "--component-log-level upstream:debug,connection:debug"
image: envoyproxy/envoy:v1.24.0
imagePullPolicy: Never
# env:
# - name: "GRPC_GO_LOG_SEVERITY_LEVEL"
# value: info
ports:
- name: http
containerPort: 8082
resources:
requests:
cpu: 1
memory: 1G
limits:
cpu: 1
memory: 1G
volumeMounts:
- name: envoy-config
mountPath: /etc/envoy
volumes:
- name: envoy-config
configMap:
name: envoy-config-map-cewwcs4rfgfy
---
apiVersion: v1
kind: Service
metadata:
annotations:
note: envoy
name: envoy
spec:
ports:
- name: http
port: 8082
protocol: TCP
targetPort: 8082
- name: admin-http
protocol: TCP
port: 8081
targetPort: 8090
selector:
app: envoy
clusterIP: None
---
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
note: envoy-config-map
name: envoy-config-map-cewwcs4rfgfy
data:
envoy.yaml: |
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 8082
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: AUTO
common_http_protocol_options:
idle_timeout: 900s
stat_prefix: ingress_http
http2_protocol_options:
max_concurrent_streams: 100
access_log:
name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
typed_json_format:
duration: "%DURATION%"
request_duration: "%REQUEST_DURATION%"
response_duration: "%RESPONSE_DURATION%"
route_name: "%ROUTE_NAME%"
upstream_host: "%UPSTREAM_HOST%"
upstream_failure_reason: "%UPSTREAM_TRANSPORT_FAILURE_REASON%"
response_code: "%RESPONSE_CODE%"
response_flag: "%RESPONSE_FLAGS%"
grpc_status: "%GRPC_STATUS%"
response: "%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%"
envoy_path: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%"
fwd: "%REQ(X-FORWARDED-FOR)%"
route_config:
name: local_route
virtual_hosts:
- name: default
domains:
- "*"
routes:
- match:
prefix: "/hello.Person/"
route:
cluster: person_server
max_grpc_timeout: 100s
clusters:
- name: person_server
type: STRICT_DNS
# Comment out the following line to test on v6 networks
dns_lookup_family: V4_ONLY
lb_policy: ROUND_ROBIN
close_connections_on_host_health_failure: true
http2_protocol_options:
max_concurrent_streams: 1000000000
load_assignment:
cluster_name: person_server
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: server.xds-test.svc.cluster.local
port_value: 8080
admin:
access_log_path: "/dev/stdout"
address:
socket_address:
address: 0.0.0.0
port_value: 8090
126 changes: 126 additions & 0 deletions example/k8s/envoy.xds.deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: envoy-deployment
labels:
app: envoy
spec:
replicas: 1
selector:
matchLabels:
app: envoy
template:
metadata:
labels:
app: envoy
spec:
containers:
- name: envoy
command:
- envoy
args:
- "-c /etc/envoy/envoy.yaml"
- "--log-level info"
- "--log-format %L. envoy]%v"
- "--log-format-escaped"
- "--enable-fine-grain-logging"
- "--component-log-level upstream:debug,connection:debug"
image: envoyproxy/envoy:v1.19.0
imagePullPolicy: Never
# env:
# - name: "GRPC_GO_LOG_SEVERITY_LEVEL"
# value: info
ports:
- name: http
containerPort: 10000
resources:
requests:
cpu: 1
memory: 1G
limits:
cpu: 1
memory: 1G
volumeMounts:
- name: envoy-config
mountPath: /etc/envoy
volumes:
- name: envoy-config
configMap:
name: envoy-config-map-cewwcs4rfgfy
---
apiVersion: v1
kind: Service
metadata:
annotations:
note: envoy
name: envoy
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 10000
- name: admin-http
protocol: TCP
port: 8081
targetPort: 8090
selector:
app: envoy
clusterIP: None
---
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
note: envoy-config-map
name: envoy-config-map-cewwcs4rfgfy
data:
envoy.yaml: |
node:
id: THIS_IS_THE_SNAPSHOT_ID_THAT_MATCHES_TO_XDS_CONTROLLER
cluster: all_services
dynamic_resources:
lds_config:
resource_api_version: V3
ads: {}
cds_config:
resource_api_version: V3
ads: {}
ads_config:
# type of request
api_type: GRPC
transport_api_version: V3
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
static_resources:
clusters:
- name: xds_cluster
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
explicit_http_config:
http2_protocol_options:
# Configure an HTTP/2 keep-alive to detect connection issues and reconnect
# to the admin server if the connection is no longer responsive.
connection_keepalive:
interval: 30s
timeout: 5s
load_assignment:
cluster_name: xds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: xds-controller.xds-test.svc.cluster.local
port_value: 8080
admin:
access_log_path: "/dev/stdout"
address:
socket_address:
address: 0.0.0.0
port_value: 8090
52 changes: 52 additions & 0 deletions example/k8s/server.b.deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: server-b-deployment
labels:
app: server-b
spec:
replicas: 1
selector:
matchLabels:
app: server-b
template:
metadata:
labels:
app: server-b
spec:
containers:
- name: server-b
env:
- name: SERVER_PORT
value: "8080"
- name: RANDOM_NUM_LENGTH
value: "2"
image: xds.example/server:latest
imagePullPolicy: Never
ports:
- containerPort: 8080
name: grpc-port
protocol: TCP
resources:
requests:
cpu: 50m
memory: 50Mi
limits:
cpu: 100m
memory: 100Mi
---
apiVersion: v1
kind: Service
metadata:
annotations:
note: server-b
name: server-b
spec:
ports:
- name: grpc-port
port: 8080
protocol: TCP
targetPort: grpc-port
selector:
app: server-b
clusterIP: None
2 changes: 2 additions & 0 deletions example/k8s/server.deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ spec:
env:
- name: SERVER_PORT
value: "8080"
- name: RANDOM_NUM_LENGTH
value: "10"
image: xds.example/server:latest
imagePullPolicy: Never
ports:
Expand Down
Loading

0 comments on commit bc5971b

Please sign in to comment.