The core Ambassador Edge Stack resource used to manage cluster ingress is the
Mapping resource routes a URL path (or prefix) to a service (either a Kubernetes service or other web service).
Mapping would route requests to
https://<hostname>/webapp/ to the
webapp-svc Service. This is not a
complete example on its own; see below.
---apiVersion: getambassador.io/v3alpha1kind: Mappingmetadata:name: webapp-mappingspec:prefix: /webapp/service: webapp-svc
|String||Identifies the Mapping.|
|String||The URL prefix identifying your resource. See below on how Ambassador Edge Stack handles resources.|
|String||The service handling the resource. If a Kubernetes service, it must include the namespace (in the format |
Here's another example using a web service that maps requests to
http://httpbin.org (again, this is not a
complete example on its own; see below):
---apiVersion: getambassador.io/v3alpha1kind: Mappingmetadata:name: httpbin-mappingspec:prefix: /httpbin/service: http://httpbin.orghostname: '*'
For demonstration purposes, here's a possible way of combining a
Host, and both
Mappings above that is complete and functional:
- it will accept HTTP or HTTPS on port 8443;
- Ambassador Edge Stack is terminating TLS;
- HTTPS to
foo.example.comwill be routed as above;
- HTTP to
foo.example.comwill be redirected to HTTPS;
- HTTP or HTTPS to other hostnames will be rejected; and
- the associations between the
Host, and the
---apiVersion: v1kind: Secrettype: kubernetes.io/tlsmetadata:name: foo-example-secretdata:tls.crt: -certificate PEM-tls.key: -secret key PEM----apiVersion: getambassador.io/v3alpha1kind: Listenermetadata:name: listener-8443spec:port: 8443protocol: HTTPSsecurityModel: XFPhostBinding:selector:matchLabels:exampleName: basic-https---apiVersion: getambassador.io/v3alpha1kind: Hostmetadata:name: foo-hostlabels:exampleName: basic-httpsspec:hostname: "foo.example.com"tlsSecret:name: foo-example-secretselector:matchLabels:exampleName: basic-https---apiVersion: getambassador.io/v3alpha1kind: Mappingmetadata:name: webapp-mappinglabels:exampleName: basic-httpsspec:prefix: /webapp/service: webapp-svchostname: 'foo.example.com'---apiVersion: getambassador.io/v3alpha1kind: Mappingmetadata:name: httpbin-mappinglabels:exampleName: basic-httpsspec:prefix: /httpbin/service: http://httpbin.orghostname: 'foo.example.com'
Note the addition of
selectors to explicitly specify which resources should associate in this example.
A Mapping resource can be managed using the same workflow as any other Kubernetes resources (like a Service or Deployment). For example, if the above Mapping is saved into a file called
httpbin-mapping.yaml, the following command will apply the configuration directly to Ambassador Edge Stack:
kubectl apply -f httpbin-mapping.yaml
To Ambassador Edge Stack, a resource is a group of one or more URLs that all share a common prefix in the URL path. For example, these URLs all share the
/resource1/ path prefix, so
/resource1/ can be considered a single resource:
On the other hand, these URLs share only the prefix
/ -- you could tell Ambassador Edge Stack to treat them as a single resource, but it's probably not terribly useful.
Note that the length of the prefix doesn't matter; a prefix like
/v1/this/is/my/very/long/resource/name/ is valid.
Also note that Ambassador Edge Stack does not actually require the prefix to start and end with
/ -- however, in practice, it's a good idea. Specifying a prefix of
/man would match all of the following, which probably is not what was intended:
Ambassador Edge Stack routes traffic to a service. A service is defined as
[scheme://]service[.namespace][:port]. Everything except for the service is optional.
schemecan be either
https; if not present, the default is
serviceis the name of a service (typically the service name in Kubernetes or Consul); it is not allowed to contain the
namespaceis the namespace in which the service is running. Starting with Ambassador Edge Stack 1.0.0, if not supplied, it defaults to the namespace in which the Mapping resource is defined. The default behavior can be configured using the Module resource. When using a Consul resolver,
namespaceis not allowed.
portis the port to which a request should be sent. If not specified, it defaults to
80when the scheme is
443when the scheme is
https. Note that the resolver may return a port in which case the
portsetting is ignored.
Mapping resources support a rich set of annotations to customize the specific routing behavior. Here's an example service for implementing the CQRS pattern (using HTTP):
---apiVersion: getambassador.io/v3alpha1kind: Mappingmetadata:name: cqrs-getspec:prefix: /cqrs/method: GETservice: getcqrshostname: '*'---apiVersion: getambassador.io/v3alpha1kind: Mappingmetadata:name: cqrs-putspec:prefix: /cqrs/method: PUTservice: putcqrshostname: '*'
Ambassador Edge Stack's configuration is assembled from multiple YAML blocks which are managed by independent application teams. This implies that certain best practices should be followed.
While you can always read back the Ambassador Edge Stack's configuration from Kubernetes or its diagnostic service, the Ambassador Edge Stack will not do versioning for you.
Gross errors will result in the Ambassador Edge Stack refusing to start, in which case
kubectl logs will be helpful. However, it's always possible to map a resource to the wrong service, or use the wrong
rewrite rules. Ambassador Edge Stack can't detect that on its own, although its diagnostic service can help you figure it out.
If two different developers try to map
/myservice/ to something, this can lead to unexpected behavior. Ambassador Edge Stack's canary deployment logic means that it's more likely that traffic will be split between them than that it will throw an error -- again, the diagnostic service can help you here.