Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Edge router for Deis Workflow

License

NotificationsYou must be signed in to change notification settings

deis/router

Repository files navigation

Deis Workflow is no longer maintained.
Pleaseread the announcement for more detail.
09/07/2017Deis Workflowv2.18 final release before entering maintenance mode
03/01/2018End of Workflow maintenance: critical patches no longer merged
Hephy is a fork of Workflow that is actively developed and accepts code contributions.

Build Statuscodecov.ioGo Report CardDocker Repository on Quay

Deis (pronounced DAY-iss) Workflow is an open source Platform as a Service (PaaS) that adds a developer-friendly layer to anyKubernetes cluster, making it easy to deploy and manage applications on your own servers.

We welcome your input! If you have feedback, please submit anissue. If you'd like to participate in development, please read the "Development" section below and submit apull request.

About

The Deis router handles ingress and routing of HTTP/S traffic bound for the Deis Workflow controller (API) and for your own applications. This component is 100% Kubernetes native and, while it's intended for use with the Deis WorkflowPaaS, it's flexible enough to be used standalone inside any Kubernetes cluster.

Development

The Deis project welcomes contributions from all developers. The high level process for development matches many other open source projects. See below for an outline.

  • Fork this repository
  • Make your changes
  • Submit apull request (PR) to this repository with your changes, and unit tests whenever possible.
    • If your PR fixes anyissues, make sure you write Fixes #1234 in your PR description (where #1234 is the number of the issue you're closing)
  • The Deis core contributors will review your code. After each of them sign off on your code, they'll label your PR withLGTM1 andLGTM2 (respectively). Once that happens, they'll merge it.

Installation

This section documents simple procedures for installing the Deis Router for evaluation or use. Those wishing to contribute to Deis Router development might consider the more developer-oriented instructions in theHacking Router section.

Deis Router can be installed with or without the rest of the Deis Workflow platform. In either case, begin with a healthy Kubernetes cluster. Kubernetes getting started documentation is availablehere.

Next, install theHelm package manager, then use the commands below to initialize that tool and install all of Deis Workflow or the Deis Router by itself.

$ helm init

To install all of Deis Workflow:

$ helm repo add workflow https://charts.deis.com/workflow$ helm install workflow/workflow --namespace deis

Or to install the Deis Router by itself:

$ helm repo add router https://charts.deis.com/router$ helm install router/router --namespace deis

For next steps, skip ahead to theHow it Works andConfiguration Guide sections.

Hacking Router

The only dependencies for hacking on / contributing to this component are:

  • git
  • make
  • docker
  • kubectl, properly configured to manipulate a healthy Kubernetes cluster that you presumably use for development
  • Your favorite text editor

Although the router is written in Go, you donot need Go or any other development tools installed. Any parts of the developer workflow requiring tools not listed above are delegated to a containerized Go development environment.

Registry

The following sections setup, build, deploy, and test the Deis Router. You'll need a configured Docker registry to push changed images to so that they can be deployed to your Kubernetes cluster. You can easily make use of a public registry such ashub.docker.com, provided you have an account. To do so:

$ export DEIS_REGISTRY=registry.hub.docker.com/$ export IMAGE_PREFIX=your-username

If I canmake it there, I'llmake it anywhere...

The entire developer workflow for anyone hacking on the router is implemented as a set ofmake targets. They are simple and easy to use, and collectively provide a workflow that should feel familiar to anyone who has hacked on Deis v1.x in the past.

Setup:

To "bootstrap" the development environment:

$ make bootstrap

In router's case, this step carries out some extensive dependency management using glide within the containerized development environment. Because the router leverages the Kubernetes API, which in turn has in excess of one hundred dependencies, this step can take quite some time.Be patient, and allow up to 20 minutes. You generally only ever have to do this once.

To build:

$ make build

Make sure to have defined the variableDEIS_REGISTRY previous to this step, as your image tags will be prefixed according to this.

To deploy:

$ make deploy

The deploy target will implicitly build first, then push the built image to your development registry (i.e. that specified byDEIS_REGISTRY). The router'sexisting KubernetesDeployment (installed via Helm) will be updated to use the newly built image.

To see that the router is running, you can look for its pod(s):

$ kubectl get pods --namespace=deis

Trying it Out

To deploy some sample routable applications:

$ helm install charts/examples --namespace router-examples

This will deploy Nginx and Apache to your Kubernetes cluster as if they were user applications.

To test, first modify your/etc/hosts such that the following four hostnames are resolvable to the IP of the Kubernetes node that is hosting the router:

  • nginx.example.com
  • apache.example.com
  • httpd.example.com
  • unknown.example.com

By requesting the following three URLs from your browser, you should find that one is routed to a pod running Nginx, while the other two are routed to a pod running Apache:

Requestinghttp://unknown.example.com should result in a 404 from the router since no route exists for that domain name.

How it Works

The router is implemented as a simple Go program that manages Nginx and Nginx configuration. It regularly queries the Kubernetes API for services labeled withrouter.deis.io/routable: "true". Such services are compared to known services resident in memory. If there are differences, new Nginx configuration is generated and Nginx is reloaded.

Routable services must expose port 80. The target port in underlying pods may be anything, but the service itself must expose port 80. For example:

apiVersion: v1kind: Servicemetadata:  name: foo  labels:  router.deis.io/routable: "true"  namespace: router-examples  annotations:    router.deis.io/domains: www.foobar.com  spec:    selector:      app: foo    ports:    - port: 80      targetPort: 3000# ...

When generating configuration, the program reads all annotations of each service prefixed withrouter.deis.io. These annotations describe all the configuration options that allow the program to dynamically construct Nginx configuration, including virtual hosts for all the domain names associated with each routable application.

Similarly, the router watches the annotations on itsown deployment object to dynamically construct global Nginx configuration.

Configuration Guide

Environment variables

Router configuration is driven almost entirely by annotations on the router's deployment object and the services of all routable applications-- those labeled withrouter.deis.io/routable: "true".

One exception to this, however, is that in order for the router to discover its own annotations, the router must be configured via environment variable with some awareness of its own namespace. (It cannot query the API for information about itself without knowing this.)

ThePOD_NAMESPACE environment variable is required by the router and it should be configured to match the Kubernetes namespace that the router is deployed into. If no value is provided, the router will assume a value ofdefault.

For example, consider the following Kubernetes manifest. Given a manifest containing the following metadata:

apiVersion: extensions/v1beta1kind: Deploymentmetadata:  name: deis-router  namespace: deis# ...

The corresponding template must inject aPOD_NAMESPACE=deis environment variable into router containers. The most elegant way to achieve this is by means of the Kubernetes "downward API," as in this snippet from the same manifest:

# ...spec:  # ...  template:    # ...    spec:      containers:      - name: deis-router        # ...        env:        - name: POD_NAMESPACE          valueFrom:            fieldRef:              fieldPath: metadata.namespace# ...

Altering the value of thePOD_NAMESPACE environment variable requires the router to be restarted for changes to take effect.

Annotations

All remaining options are configured through annotations. Any of the following three Kubernetes resources can be configured:

ResourceNotes
  • deis-router deployment object
  • deis-builder service (if in use)
All of these configuration options are specific tothis implementation of the router (as indicated by the inclusion of the tokennginx in the annotations' names). Customized and alternative router implementations are possible. Such routers are under no obligation to honor these annotations, as many or all of these may not be applicable in such scenarios. Customized and alternative implementationsshould document their own configuration options.
  • routable application services
These are services labeled withrouter.deis.io/routable: "true". In the context of the broader Deis Workflow PaaS, these annotations arewritten by the Deis Workflow controller component (the API). These annotations, therefore, represent the contract orinterface between that component and the router. As such, any customized or alternative router implementations that wishes to remain compatible with deis-controller must honor (or ignore) these annotations, but maynot alter their names or redefine their meanings.

The table below details the configuration options that are available for each of the above.

Note that Kubernetes annotation maps are all of Go typemap[string]string. As such, all configuration values must also be strings. To avoid Kubernetes attempting to populate themap[string]string with non-string values, all numeric and boolean configuration values should be enclosed in double quotes to help avoid confusion.

ComponentResource TypeAnnotationDefault ValueDescription
deis-routerdeploymentrouter.deis.io/nginx.workerProcesses"auto" (number of CPU cores)Number of worker processes to start.
deis-routerdeploymentrouter.deis.io/nginx.maxWorkerConnections"768"Maximum number of simultaneous connections that can be opened by a worker process.
deis-routerdeploymentrouter.deis.io/nginx.trafficStatusZoneSize"1m"Size of a shared memory zone for storing stats collected by the NginxVTS module expressed in bytes (no suffix), kilobytes (suffixesk andK), or megabytes (suffixesm andM).
deis-routerdeploymentrouter.deis.io/nginx.defaultTimeout"1300s"Default timeout value expressed in unitsms,s,m,h,d,w,M, ory. Should be longer than the front-facing load balancer's idle timeout.
deis-routerdeploymentrouter.deis.io/nginx.serverNameHashMaxSize"512"nginxserver_names_hash_max_size setting expressed in bytes (no suffix), kilobytes (suffixesk andK), or megabytes (suffixesm andM).
deis-routerdeploymentrouter.deis.io/nginx.serverNameHashBucketSize"64"nginxserver_names_hash_bucket_size setting expressed in bytes (no suffix), kilobytes (suffixesk andK), or megabytes (suffixesm andM).
deis-routerdeploymentrouter.deis.io/nginx.requestIDs"false"Whether to add X-Request-Id and X-Correlation-Id headers.
deis-routerdeploymentrouter.deis.io/nginx.gzip.enabled"true"Whether to enable gzip compression.
deis-routerdeploymentrouter.deis.io/nginx.gzip.compLevel"5"nginxgzip_comp_level setting.
deis-routerdeploymentrouter.deis.io/nginx.gzip.disable"msie6"nginxgzip_disable setting.
deis-routerdeploymentrouter.deis.io/nginx.gzip.httpVersion"1.1"nginxgzip_http_version setting.
deis-routerdeploymentrouter.deis.io/nginx.gzip.minLength"256"nginxgzip_min_length setting.
deis-routerdeploymentrouter.deis.io/nginx.gzip.proxied"any"nginxgzip_proxied setting.
deis-routerdeploymentrouter.deis.io/nginx.gzip.types"application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component"nginxgzip_types setting.
deis-routerdeploymentrouter.deis.io/nginx.gzip.vary"on"nginxgzip_vary setting.
deis-routerdeploymentrouter.deis.io/nginx.bodySize"1m"nginxclient_max_body_size setting expressed in bytes (no suffix), kilobytes (suffixesk andK), or megabytes (suffixesm andM).
deis-routerdeploymentrouter.deis.io/nginx.proxyRealIpCidrs"10.0.0.0/8"Comma-delimited list of IP/CIDRs that define trusted addresses that are known to send correct replacement addresses. These map to multiple nginxset_real_ip_from directives.
deis-routerdeploymentrouter.deis.io/nginx.errorLogLevel"error"Log level used in the nginxerror_log setting (valid values are:debug,info,notice,warn,error,crit,alert, andemerg).
deis-routerdeploymentrouter.deis.io/nginx.platformDomainN/AThis defines the router's platform domain. Any domains added to a routable applicationnot containing the. character will be assumed to be subdomains of this platform domain. Thus, for example, a platform domain ofexample.com coupled with a routable app countingfoo among its domains will result in router configuration that routes traffic forfoo.example.com to that application.
deis-routerdeploymentrouter.deis.io/nginx.useProxyProtocol"false"PROXY is a simple protocol supported by nginx, HAProxy, Amazon ELB, and others. It provides a method to obtain information about a request's originating IP address from an external (to Kubernetes) load balancer in front of the router. Enabling this option allows the router to select the originating IP from the HTTPX-Forwarded-For header.
deis-routerdeploymentrouter.deis.io/nginx.disableServerTokens"false"Enables or disables emitting nginx version in error messages and in the “Server” response header field.
deis-routerdeploymentrouter.deis.io/nginx.enforceWhitelists"false"Whether torequire application-level whitelists that explicitly enumerate allowed clients by IP / CIDR range. With this enabled, each app will dropall requests unless a whitelist has been defined.
deis-routerdeploymentrouter.deis.io/nginx.defaultWhitelistN/AA default (router-wide) whitelist expressed as a comma-delimited list of addresses (using IP or CIDR notation). Application-specific whitelists can either extend or override this default.
deis-routerdeploymentrouter.deis.io/nginx.whitelistMode"extend"Whether application-specific whitelists should extend or override the router-wide default whitelist (if defined). Valid values are"extend" and"override".
deis-routerdeploymentrouter.deis.io/nginx.defaultServiceEnabled"false"Enables default back-end service for traffic hitting /. In order to work correctly bothdefaultServiceIP andDefaultAppName MUST also be set.
deis-routerdeploymentrouter.deis.io/nginx.DefaultAppName""Default back-end application name for traffic hitting router on /. In order to work correctly bothdefaultServiceIP andDefaultServiceEnabled MUST also be set.
deis-routerdeploymentrouter.deis.io/nginx.defaultServiceIP""Default back-end service ip for traffic hitting router on /. In order to work correctly bothDefaultAppName andDefaultServiceEnabled MUST also be set.
deis-routerdeploymentrouter.deis.io/nginx.http2Enabled"true"Whether to enable HTTP2 for apps on the SSL ports.
deis-routerdeploymentrouter.deis.io/nginx.logFormat"[$time_iso8601] - $app_name - $remote_addr - $remote_user - $status - "$request" - $bytes_sent - "$http_referer" - "$http_user_agent" - "$server_name" - $upstream_addr - $http_host - $upstream_response_time - $request_time"Nginx access log format.Warning: if you change this to a non-default value, log parsing in monitoring subsystem will be broken. Use this parameter if you completely understand what you're doing.
deis-routerdeploymentrouter.deis.io/nginx.ssl.enforce"false"Whether to respond with a 301 for all HTTP requests with a permanent redirect to the HTTPS equivalent address.
deis-routerdeploymentrouter.deis.io/nginx.ssl.protocols"TLSv1 TLSv1.1 TLSv1.2"nginxssl_protocols setting.
deis-routerdeploymentrouter.deis.io/nginx.ssl.ciphers"ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS"nginxssl_ciphers. The default ciphers are taken from the intermediate compatibility section in theMozilla Wiki on Security/Server Side TLS. If the value is set to the empty string, OpenSSL's default ciphers are used. Inall cases, server side cipher preferences (order matters) are used.
deis-routerdeploymentrouter.deis.io/nginx.ssl.sessionCache""nginxssl_session_cache setting.
deis-routerdeploymentrouter.deis.io/nginx.ssl.sessionTimeout"10m"nginxssl_session_timeout expressed in unitsms,s,m,h,d,w,M, ory.
deis-routerdeploymentrouter.deis.io/nginx.ssl.useSessionTickets"true"Whether to useTLS session tickets for session resumption without server-side state.
deis-routerdeploymentrouter.deis.io/nginx.ssl.bufferSize"4k"nginxssl_buffer_size setting expressed in bytes (no suffix), kilobytes (suffixesk andK), or megabytes (suffixesm andM).
deis-routerdeploymentrouter.deis.io/nginx.ssl.hsts.enabled"false"Whether to use HTTP Strict Transport Security.
deis-routerdeploymentrouter.deis.io/nginx.ssl.hsts.maxAge"10886400"Maximum number of seconds user agents should observe HSTS rewrites.
deis-routerdeploymentrouter.deis.io/nginx.ssl.hsts.includeSubDomains"false"Whether to enforce HSTS for subsequent requests to all subdomains of the original request.
deis-routerdeploymentrouter.deis.io/nginx.ssl.hsts.preload"false"Whether to allow the domain to be included in the HSTS preload list.
deis-routerdeploymentrouter.deis.io/nginx.proxyBuffers.enabled"false"Whether to enabled proxy buffering for all applications (this can be overridden on an application basis).
deis-routerdeploymentrouter.deis.io/nginx.proxyBuffers.number"8"number argument to the nginxproxy_buffers directive for all applications (this can be overridden on an application basis).
deis-routerdeploymentrouter.deis.io/nginx.proxyBuffers.size"4k"size argument to the nginxproxy_buffers directive expressed in bytes (no suffix), kilobytes (suffixesk andK), or megabytes (suffixesm andM). This setting applies to all applications, but can be overridden on an application basis.
deis-routerdeploymentrouter.deis.io/nginx.proxyBuffers.busySize"8k"nginxproxy_busy_buffers_size expressed in bytes (no suffix), kilobytes (suffixesk andK), or megabytes (suffixesm andM). This setting applies to all applications, but can be overridden on an application basis.
deis-builderservicerouter.deis.io/nginx.connectTimeout"10s"nginxproxy_connect_timeout setting expressed in unitsms,s,m,h,d,w,M, ory.
deis-builderservicerouter.deis.io/nginx.tcpTimeout"1200s"nginxproxy_timeout setting expressed in unitsms,s,m,h,d,w,M, ory.
routable applicationservicerouter.deis.io/domainsN/AComma-delimited list of domains for which traffic should be routed to the application. These may be fully qualified (e.g.foo.example.com) or, if not containing any. character, will be considered subdomains of the router's domain, if that is defined.
routable applicationservicerouter.deis.io/certificatesN/AComma delimited list of mappings between domain names (seerouter.deis.io/domains) and the certificate to be used for each. The domain name and certificate name must be separated by a colon. See theSSL section below for further details.
routable applicationservicerouter.deis.io/whitelistN/AComma-delimited list of addresses permitted to access the application (using IP or CIDR notation). These may either extend or override the router-wide default whitelist (if defined). Requests from all other addresses are denied.
routable applicationservicerouter.deis.io/connectTimeout"30s"nginxproxy_connect_timeout setting expressed in unitsms,s,m,h,d,w,M, ory.
routable applicationservicerouter.deis.io/tcpTimeoutrouter'sdefaultTimeoutnginxproxy_send_timeout andproxy_read_timeout settings expressed in unitsms,s,m,h,d,w,M, ory.
routable applicationservicerouter.deis.io/maintenance"false"Whether the app is under maintenance so that all traffic for this app is redirected to a static maintenance page with an error code of503.
routable applicationservicerouter.deis.io/ssl.enforce"false"Whether to respond with a 301 for all HTTP requests with a permanent redirect to the HTTPS equivalent address.
routable applicationservicerouter.deis.io/nginx.proxyBuffers.enabled"false"Whether to enabled proxy buffering. This can be used to override the same option set globally on the router.
routable applicationservicerouter.deis.io/nginx.proxyBuffers.number"8"number argument to the nginxproxy_buffers directive. This can be used to override the same option set globally on the router.
routable applicationservicerouter.deis.io/nginx.proxyBuffers.size"4k"size argument to the nginxproxy_buffers directive expressed in bytes (no suffix), kilobytes (suffixesk andK), or megabytes (suffixesm andM). This can be used to override the same option set globally on the router.
routable applicationservicerouter.deis.io/nginx.proxyBuffers.busySize"8k"nginxproxy_busy_buffers_size expressed in bytes (no suffix), kilobytes (suffixesk andK), or megabytes (suffixesm andM). This can be used to override the same option set globally on the router.

Annotations by example

router deployment object:
apiVersion: extensions/v1beta1kind: Deploymentmetadata:  name: deis-router  namespace: deis  # ...  annotations:    router.deis.io/nginx.platformDomain: example.com    router.deis.io/nginx.useProxyProtocol: "true"# ...
builder service:
apiVersion: v1kind: Servicemetadata:  name: deis-builder  namespace: deis  # ...  annotations:    router.deis.io/nginx.connectTimeout: "20000"    router.deis.io/nginx.tcpTimeout: "2400000"# ...
routable service:
apiVersion: v1kind: Servicemetadata:  name: foo  labels:  router.deis.io/routable: "true"  namespace: router-examples  # ...  annotations:    router.deis.io/domains: foo,bar,www.foobar.com# ...

SSL

Router has support for HTTPS with the ability to perform SSL termination using certificates supplied via Kubernetes secrets. Just as router utilizes the Kubernetes API to discover routable services, router also uses the API to discover cert-bearing secrets. This allows the router to dynamically refresh and reload configuration whenever such a certificate is added, updated, or removed. There is never a need to explicitly restart the router.

A certificate may be supplied in the manner described above and can be used to provide a secure virtual host (in addition to the insecure virtual host) for anyfully-qualified domain name associated with a routable service.

SSL example

Here is an example of a Kubernetes secret bearing a certificate for use with a specific fully-qualified domain name. The following criteria must be met:

  • Secret name must be for the form<arbitrary name>-cert
  • Must be in the same namespace as the routable service
  • Certificate must be supplied as the value of the keytls.crt
  • Certificate private key must be supplied as the value of the keytls.key
  • Both the certificate and private key must be base64 encoded

For example, assuming a routable service exists in the namespacecheery-yardbird and is configured withwww.example.com among its domains, like so:

apiVersion: v1kind: Servicemetadata:  namespace: cheery-yardbird  annotations:    router.deis.io/domains: cheery-yardbird,www.example.com    router.deis.io/certificates: www.example.com:www-example-com"# ...

The corresponding cert-bearing secret would appear as follows:

apiVersion: v1kind: Secretmetadata:  name: www-example-com-cert  namespace: cheery-yardbirdtype: Opaquedata:  tls.crt: MT1...uDh==  tls.key: MT1...MRp=

Platform certificate

A wildcard certificate may be supplied in a manner similar to that described above and can be used as a platform certificate to provide a secure virtual host (in addition to the insecure virtual host) forevery "domain" of a routable service that is not a fully-qualified domain name.

For instance, if a routable service exists having a "domain"frozen-wookie and the router's platform domain isexample.com, a supplied wildcard certificate for*.example.com will be used to secure afrozen-wookie.example.com virtual host. Similarly, if no platform domain is defined, the supplied wildcard certificate will be used to secure a virtual host matching the expression~^frozen-wookie\.(?<domain>.+)$. (The latter is almost certainly guaranteed to result in certificate warnings in an end user's browser, so it is advisable to always define the router's platform domain.)

If the same routable service also had a domainwww.frozen-wookie.com, the*.example.com wildcard certificate plays no role in securing thewww.frozen-wookie.com virtual host.

Platform certificate example

Here is an example of a Kubernetes secret bearing a wildcard certificate for use by the router. The following criteria must be met:

  • Namespace must be the same namespace as the router
  • Namemust bedeis-router-platform-cert
  • Certificate must be supplied as the value of the keytls.crt
  • Certificate private key must be supplied as the value of the keytls.key
  • Both the certificate and private key must be base64 encoded

For example:

apiVersion: v1kind: Secretmetadata:  name: deis-router-platform-cert  namespace: deistype: Opaquedata:  tls.crt: LS0...tCg==  tls.key: LS0...LQo=

SSL options

When combined with a good certificate, the router'sdefault SSL options are sufficient to earn an A grade fromQualys SSL Labs.

Earning an A+ is as easy as simply enabling HTTP Strict Transport Security (see therouter.deis.io/nginx.ssl.hsts.enabled option), but be aware that this will implicitly trigger therouter.deis.io/nginx.ssl.enforce option and cause your applications to permanently use HTTPS forall requests.

Front-facing load balancer

Depending on what distribution of Kubernetes you use and where you host it, installation of the routermay automatically include an external (to Kubernetes) load balancer or similar mechanism for routing inbound traffic from beyond the cluster into the cluster to the router(s). For example,kube-aws andGoogle Container Engine both do this. On some other platforms-- Vagrant or bare metal, for instance-- this must either be accomplished manually or does not apply at all.

Idle connection timeouts

If a load balancer such as the one described above does exist (whether created automatically or manually)and if you intend on handling any long-running requests, the load balancer (or similar)may require some manual configuration to increase the idle connection timeout. Typically, this is most applicable to AWS and Elastic Load Balancers, but may apply in other cases as well. It doesnot apply to Google Container Engine, as the idle connection timeout cannot be configured there, but also works fine as-is.

If, for instance, router were installed on kube-aws, in conjunction with the rest of the Deis Workflow platform, this timeout should be increased to a recommended value of 1200 seconds. This will ensure the load balancer does not hang up on the client during long-running operations like an application deployment. Directions for this can be foundhere.

Manually configuring a load balancer

If using a Kubernetes distribution or underlying infrastructure that does not support the automated provisioning of a front-facing load balancer, operators will wish to manually configure a load balancer (or use other tricks) to route inbound traffic from beyond the clusterinto the cluster to the platform's own router(s). There are many ways to accomplish this. The remainder of this section discusses three general options for accomplishing this.

Option 1

This manually replicates the configuration that would be achieved automatically with some distributions on some infrastructure providers, as discussed above.

First, determine the "node ports" for thedeis-router service:

$ kubectl describe service deis-router --namespace=deis

This will yield output similar to the following:

...Port:http80/TCPNodePort:http32477/TCPEndpoints:10.2.80.11:80Port:https443/TCPNodePort:https32389/TCPEndpoints:10.2.80.11:443Port:builder2222/TCPNodePort:builder30729/TCPEndpoints:10.2.80.11:2222Port:healthz9090/TCPNodePort:healthz31061/TCPEndpoints:10.2.80.11:9090...

The node ports shown above are high-numbered ports that are allocated onevery Kubernetes worker node for use by the router service. The kube-proxy component onevery Kubernetes node will listen on these ports and proxy traffic through to the corresponding port within an "endpoint--" that is, a pod running the Deis router.

If manually creating a load balancer, configure the load balancer to haveall Kubernetes worker nodes in the back-end pool, and listen on ports 80, 443, and 2222 (port 9090 can be ignored). Each of these listeners should proxy inbound traffic to the corresponding node ports on the worker nodes. Ports 80 and 443 may use either HTTP/S or TCP as protocols. Port 2222 must use TCP.

With this configuration, the path a request takes from the end-user to an application pod is as follows:

user agent (browser) --> front-facing load balancer --> kube-proxy on _any_ Kubernetes worker node --> _any_ Deis router pod --> kube-proxy on that same node --> _any_ application pod
Option 2

Option 2 differs only slightly from option 1, but is more efficient. As such, even operators who had a front-facing load balancer automatically provisioned on their infrastructure by Kubernetes might consider manually reconfiguring that load balancer as follows.

Deis router pods will listen onhost ports 80, 443, 2222, and 9090 wherever they run. (They will not run on any worker nodes where all of these four ports are not available.) Taking advantage of this, an operator may completely dismiss the node ports discussed in option 1. The load balancer can be configured to haveall Kubernetes worker nodes in the back-end pool, and listen on ports 80, 443, and 2222. Each of these listeners should proxy inbound traffic to thesame ports on the worker nodes. Ports 80 and 443 may use either HTTP/S or TCP as protocols. Port 2222 must use TCP.

Additionally, a health checkmust be configured using the HTTP protocol, port 9090, and the/healthz endpoint. With such a health check in place,only nodes that are actually hosting a router pods will pass and be included in the load balancer's pool of active back end instances.

With this configuration, the path a request takes from the end-user to an application pod is as follows:

user agent (browser) --> front-facing load balancer --> a Deis router pod --> kube-proxy on that same node --> _any_ application pod
Option 3

Option 3 is similar to option 2, but does not actually utilize a load balancer at all. Instead, a DNS A record may be created that lists the public IP addresses ofall Kubernetes worker nodes. This will leverage DNS round-robining to direct requests to all nodes. To guaranteeall nodes can adequately route incoming traffic, the Deis router component should be scaled out by increasing the number of replicas specified in the deployment object to match the number of worker nodes. Anti-affinity should ensure exactly one router pod runs per worker node.

This configuration is not suitable for production. The primary use case for this configuration is demonstrating or evaluating Deis Workflow on bare metal Kubernetes clusters without incurring the effort to configure anactual front-facing load balancer.

Production Considerations

Customizing the charts

The Helmchart available for installing router (either with or without the rest of Deis Workflow) is intended to get users up and running as quickly as possible. As such, the chart does not strictly require any editing prior to installation in order to successfully bootstrap a cluster. However, there are some useful customizations that should be applied for use in production environments:

  • Specify aplatform domain. Without a platform domain specified, any routable service specifying one or more non-fully-qualified domain names (not containing any. character) among itsrouter.deis.io/domains will be matched using a regular expression of the form^{{ $domain }}\.(?<domain>.+)$ where{{ $domain }} resolves to the non-fully-qualified domain name. By way of example, the idiosyncrasy that this exposes is that traffic bound for thefoo subdomain ofany domain would be routed to an application that lists the non-fully-qualified domain namefoo among itsrouter.deis.io/domains. While this behavior is not innately wrong, it may not be desirable. To circumvent this, specify aplatform domain. This will cause routable services specifying one or more non-fully-qualified domain names to be matched, explicitly, as subdomains of the platform domain. Apart from remediating this minor idiosyncrasy, this is required in order to properly utilize a wildcard SSL certificate and may also result in a very modest performance improvement.

  • Do you need to use SSL tosecure the platform domain?

  • If using SSL, generate and provide your own dhparam. A dhparam is a secret key used inDiffie Hellman key exchange during the SSL handshake in order to help ensureperfect forward secrecy. The Helmchart available for installing router (either with or without the rest of Deis Workflow) already includes a dhparam, but recall that dhparams are intended to be secret. The dhparam included in the chart is marginally preferable to using Nginx's default dhparam only because it is lesser-known, but it isstill publicly available in thechart. As such, users wishing to run the router in productionand use SSL are best off generating their own dhparam. After being generated, it should be base64 encoded and included as the value of thedhparam key in a Kubernetes secret nameddeis-router-dhparam in the same namespace as the router itself.

    For example, to generate and base64 encode the dhparam on a Mac:

    $ openssl dhparam -out dhparam.pem 1024$ base64 dhparam.pem

    To generate an even stronger key, use 2048 bits, but note that generating such a key will take a very long time-- possibly hours.

    Include the base64 encoded dhparam in a secret:

    apiVersion: v1kind: Secretmetadata:    name: deis-router-dhparam    namespace: deis    labels:      heritage: deistype: Opaquedata:    dhparam: <base64 encoded dhparam>
  • If using SSL, do you need toenforce the use of SSL?

  • If using SSL, do you need toenable strict transport security?

  • If using SSL, what grade doesQualys SSL Labs give you?

  • Should your routerdefine and enforce a default whitelist? This may be advisable for routers governing ingress to a cluster that hosts applications intended for a limited audience-- e.g. applications for internal use within an organization.

  • Do you need to scale the router? For greater availability, it's desirable to run more than one instance of the router.How many can only be informed by stress/performance testing the applications in your cluster. To increase the number of router instances from the default of one, increase the number of replicas specified by thedeis-router deployment object. Do not specify a number of replicas greater than the number of worker nodes in your Kubernetes cluster.


[8]ページ先頭

©2009-2025 Movatter.jp