Ambassador Integration with Consul Connect

In addition to enabling Kubernetes services to discover and securely connect to each other, Connect also can help route traffic into a Kubernetes cluster from outside, when paired with an ingress controller like DataWire’s Ambassador.

Ambassador is a popular Kubernetes-native service that acts as an ingress controller or API gateway. It supports an optional integration with Consul that allows it to route incoming traffic to the proxies for your Connect-enabled services.

This means you can have end-to-end encryption from the browser, to Ambassador, to your Kubernetes services.

Installation

Before you start, install Consul and enable Connect on the agents inside the cluster. Decide whether you will enable service sync or manually register your services with Consul.

Once you have tested and verified that everything is working, you can proceed with the Ambassador installation. Full instructions are available on the Ambassador site, but a summary of the steps is as follows:

If you are deploying to GKE, create a RoleBinding to grant you cluster admin rights:

  1. kubectl create clusterrolebinding my-cluster-admin-binding \
  2. --clusterrole=cluster-admin \
  3. --user=$(gcloud info --format="value(config.account)")

Install Ambassador and a LoadBalancer service for it:

  1. kubectl apply -f https://www.getambassador.io/yaml/ambassador/ambassador-rbac.yaml
  2. kubectl apply -f https://www.getambassador.io/yaml/ambassador/ambassador-service.yaml

Install the Ambassador Consul Connector:

  1. kubectl apply -f https://www.getambassador.io/yaml/consul/ambassador-consul-connector.yaml

Add TLSContext and Mapping annotations to your existing services, directing HTTPS traffic to port 20000, which is opened by the Connect proxy. Here is an example of doing this for the static-server example used in the documentation for the Connect sidecar:

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: static-service
  5. annotations:
  6. getambassador.io/config: |
  7. ---
  8. apiVersion: ambassador/v1
  9. kind: TLSContext
  10. name: ambassador-consul
  11. hosts: []
  12. secret: ambassador-consul-connect
  13. ---
  14. apiVersion: ambassador/v1
  15. kind: Mapping
  16. name: static-service_mapping
  17. prefix: /echo/
  18. tls: ambassador-consul
  19. service: https://static-server:443
  20. spec:
  21. type: NodePort
  22. selector:
  23. app: http-echo
  24. ports:
  25. - port: 443
  26. name: https-echo
  27. targetPort: 20000

Once Ambassador finishes deploying, you should have a new LoadBalancer service with a public-facing IP address. Connecting to the HTTP port on this address should display the output from the static service.

  1. kubectl describe service ambassador

Enabling end-to-end TLS

The Ambassador service definition provided in their documentation currently does not serve pages over HTTPS. To enable HTTPS for full end-to-end encryption, follow these steps.

First, upload your public SSL certificate and private key as a Kubernetes secret.

  1. kubectl create secret tls ambassador-certs --cert=fullchain.pem --key=privkey.pem

Download a copy of the ambassador-service.yaml file from Ambassador. Replace the metadata section with one that includes an Ambassador TLS configuration block, using the secret name you created in the previous step. Then add an entry for port 443 to the LoadBalancer spec. Here is a complete example:

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: ambassador
  5. annotations:
  6. getambassador.io/config: |
  7. ---
  8. apiVersion: ambassador/v1
  9. kind: Module
  10. name: tls
  11. config:
  12. server:
  13. enabled: True
  14. secret: ambassador-certs
  15. spec:
  16. type: LoadBalancer
  17. externalTrafficPolicy: Local
  18. ports:
  19. - port: 80
  20. targetPort: http
  21. protocol: TCP
  22. name: http
  23. - port: 443
  24. targetPort: https
  25. protocol: TCP
  26. name: https
  27. selector:
  28. service: ambassador

Update the service definition by applying it with kubectl:

  1. kubectl apply -f ambassador-service.yaml

You should now be able to test the SSL connection from your browser.

Troubleshooting

When Ambassador is unable to establish an authenticated connection to the Connect proxy servers, browser connections will display this message:

  1. upstream connect error or disconnect/reset before headers

This error can have a number of different causes. Here are some things to check and troubleshooting steps you can take.

Check intentions between Ambassador and your upstream service

If you followed the above installation guide, Consul should have registered a service called “ambassador”. Make sure you create an intention to allow it to connect to your own services.

To check whether Ambassador is allowed to connect, use the intention check subcommand.

  1. $ consul intention check ambassador http-echo
  2. Allowed

Confirm upstream proxy sidecar is running

First, find the name of the pod that contains your service.

  1. $ kubectl get pods -l app=http-echo,role=server
  2. NAME READY STATUS RESTARTS AGE
  3. http-echo-7fb79566d6-jmccp 2/2 Running 0 1d

Then describe the pod to make sure that the sidecar is present and running.

  1. $ kubectl describe pod http-echo-7fb79566d6-jmccp
  2. [...]
  3. Containers:
  4. consul-connect-envoy-sidecar:
  5. [...]
  6. State: Running
  7. Ready: True

Start up a downstream proxy and try connecting to it

Log into one of your Consul server pods (or any pod that has a Consul binary in it).

  1. $ kubectl exec -ti consul-server-0 -- /bin/sh

Once inside the pod, try starting a test proxy. Use the name of your service in place of http-echo.

  1. # consul connect proxy -service=ambassador -upstream http-echo:1234
  2. ==> Consul Connect proxy starting...
  3. Configuration mode: Flags
  4. Service: http-echo-client
  5. Upstream: http-echo => :1234
  6. Public listener: Disabled

If the proxy starts successfully, try connecting to it. Verify the output is as you expect.

  1. # curl localhost:1234
  2. "hello world"

Don’t forget to kill the test proxy when you’re done.

  1. # kill %1
  2. ==> Consul Connect proxy shutdown
  3. # exit

Check Ambassador Connect sidecar logs

Find the name of the Connect Integration pod and make sure it is running.

  1. $ kubectl get pods -l app=ambassador-pro,component=consul-connect
  2. NAME READY STATUS RESTARTS AGE
  3. ambassador-pro-consul-connect-integration-f88fcb99f-hxk75 1/1 Running 0 1d

Dump the logs from the integration pod. If the service is running correctly, there won’t be much in there.

  1. $ kubectl logs ambassador-pro-consul-connect-integration-f88fcb99f-hxk75
  2. time="2019-03-13T19:42:12Z" level=info msg="Starting Consul Connect Integration" consul_host=10.142.0.21 consul_port=8500 version=0.2.3
  3. 2019/03/13 19:42:12 Watching CA leaf for ambassador
  4. time="2019-03-13T19:42:12Z" level=debug msg="Computed kubectl command and arguments" args="[kubectl apply -f -]"
  5. time="2019-03-13T19:42:14Z" level=info msg="Updating TLS certificate secret" namespace= secret=ambassador-consul-connect

Check Ambassador logs

Make sure the Ambassador pod itself is running.

  1. $ kubectl get pods -l service=ambassador
  2. NAME READY STATUS RESTARTS AGE
  3. ambassador-655875b5d9-vpc2v 2/2 Running 0 1d

Finally, check the logs for the main Ambassador pod.

  1. $ kubectl logs ambassador-655875b5d9-vpc2v

Check Ambassador admin interface

Forward the admin port from the Ambassador pod to your local machine.

  1. $ kubectl port-forward pods/ambassador-655875b5d9-vpc2v 8877:8877

You should then be able to open http://localhost:8877/ambassador/v0/diag/ in your browser and view Ambassador’s routing table. The table lists each URL mapping that has been set up. Service names will appear in green if Ambassador believes they are healthy, and red otherwise.

From this interface, you can also enable debug logging via the yellow “Set Debug On” button, which might give you a better idea of what’s happening when requests fail.

Getting support

If you have tried the above troubleshooting steps and are still stuck, DataWire provides support for Ambassador via the popular Slack chat app. You can request access and then join the #ambassador room to get help.