github.com/projectcontour/contour@v1.28.2/site/content/docs/1.23/architecture.md (about) 1 # Contour Architecture 2 3 The Contour Ingress controller is a collaboration between: 4 5 * Envoy, which provides the high performance reverse proxy. 6 * Contour, which acts as a management server for Envoy and provides it with configuration. 7 8 These containers are deployed separately, Contour as a Deployment and Envoy as a Kubernetes Daemonset or Deployment, although other configurations are possible. 9 10 In the Envoy Pods, Contour runs as an initcontainer in `bootstrap` mode and writes an Envoy bootstrap configuration to a temporary volume. 11 This volume is passed to the Envoy container and directs Envoy to treat Contour as its [management server][1]. 12 13 After initialization is complete, the Envoy container starts, retrieves the bootstrap configuration written by Contour's `bootstrap` mode, and establishes a GRPC session with Contour to receive configuration. 14 15 Envoy will gracefully retry if the management server is unavailable, which removes any container startup ordering issues. 16 17 Contour is a client of the Kubernetes API. 18 Contour watches Ingress, HTTPProxy, Gateway API, Secret, Service, and Endpoint objects, and acts as the management server for its Envoy sibling by translating its cache of objects into the relevant JSON stanzas: Service objects for CDS, Ingress for RDS, Endpoint objects for EDS, and so on). 19 20 The transfer of information from Kubernetes to Contour is by watching the Kubernetes API utilizing [controller-runtime][4] primitives. 21 22 Kubernetes readiness probes are configured to check whether Envoy is ready to accept connections. 23 The Envoy readiness probe sends GET requests to `/ready` in Envoy's administration endpoint. 24 25 For Contour, a liveness probe checks the `/healthz` running on the Pod's metrics port. 26 Readiness probe is a check that Contour can access the Kubernetes API. 27 28 ## Architectural Overview 29 Below are a couple of high level architectural diagrams of how Contour works inside a Kubernetes cluster as well as showing the data path of a request to a backend pod. 30 31 A request to `projectcontour.io/blog` gets routed via a load balancer to an instance of an Envoy proxy which then sends the request to a pod. 32 33 ![architectural overview][2] 34 35 Following is a diagram of how Contour and Envoy are deployed in a Kubernetes cluster. 36 37 ### Kubernetes API Server 38 39 The following API objects are watched: 40 - Services 41 - Endpoints 42 - Secrets 43 - Ingress 44 - HTTPProxy 45 - Gateway API (Optional) 46 47 ### Contour Deployment 48 49 Contour is deployed in the cluster using a Kubernetes Deployment. 50 It has built-in leader election which is responsible for updating httproxy/ingress/gateway api resources via Kube API server. 51 All instances are able to serve xDS configuration to any Envoy instance, but only the leader can write status back to the API server. 52 53 The data being served from contour instances are eventually consistent in an HA based deployment. 54 However HA mode is operationally scalable when you have high request rate from envoy to contour as requests are loadbalanced among contour instances. 55 This also helps availability zone /data center degradation events as your service continue to function. 56 57 ### Envoy Deployment 58 59 Envoy can be deployed in two different models, as a Kubernetes Daemonset or as a Kubernetes Deployment. 60 61 Daemonset is the standard deployment model where a single instance of Envoy is deployed per Kubernetes Node. 62 This allows for simple Envoy pod distribution across the cluster as well as being able to expose Envoy using `hostPorts` to improve network performance. 63 One potential downside of this deployment model is when a node is removed from the cluster (e.g. on a cluster scale down, etc) then the configured `preStop` hooks are not available so connections can be dropped. 64 This is a limitation that applies to any Daemonset in Kubernetes. 65 66 An alternative Envoy deployment model is utilizing a Kubernetes Deployment with a configured `podAntiAffinity` which attempts to mirror the Daemonset deployment model. 67 A benefit of this model compared to the Daemonset version is when a node is removed from the cluster, the proper shutdown events are available so connections can be cleanly drained from Envoy before terminating. 68 69 ![architectural overview 2][3] 70 71 [1]: https://www.envoyproxy.io/docs/envoy/v1.13.0/api-docs/xds_protocol 72 [2]: ../img/archoverview.png 73 [3]: ../img/contour_deployment_in_k8s.png 74 [4]: https://github.com/kubernetes-sigs/controller-runtime