In a previous post, we explained how the team at Kong thinks of the term “service mesh.” In this post, we’ll start digging into the workings of Kong deployed as a mesh. We’ll talk about a hypothetical example of the smallest possible deployment of a mesh, with two services talking to each other via two Kong instances – one local to each service.
When deployed in a mesh, we refer to local instances of Kong as “paired proxies.” This is because the service mesh, broken down into its smallest atomic parts, is made of individual network transactions between two proxies that are “aware” of each other. Although any two proxies in the mesh can communicate with each other in this way, when you think about it from the standpoint of a single transaction, there is no service mesh.
Kong’s service mesh deployment – and all service meshes – are made of proxies that form pairs at connection time. Via those paired connections, the proxies provide security, reliability and observability for distributed application architectures. In other words, all service meshes are really collections of paired proxies.
Because the whole mesh is made of paired proxies, our example will be simple. We start out with service A and service B, which exchange requests and responses over insecure, non-TLS (Transport Layer Security) network connections. We’ll assume we have root level access to the hosts running A
and B
, and that there are security, reliability and observability issues with those connections. Let’s start solving those problems with a pair of Kong proxies.
Symbols and Terminology
We’ll establish some symbols and terminology that we’ll use through the remainder of this and in many other documents about Kong’s service mesh deployment architectures:
Service and Kong Instances
A
,B
, etc. represent single instances of services (also known as “applications”)A
is a service that makes requests toB
B
is a service that responds to requests fromA
.B
does not initiate any requests, nor does it get requested by any service other thanA
.- Both services send and receive non-TLS traffic only – they cannot establish or terminate TLS connections. Both services communicate via HTTP.
K
represents a Kong node that is not “affiliated” with any particular serviceKA
,KB
, etc. represent Kong nodes that proxy all traffic coming in to and going out fromA
,B
, etc.- Unlike Kong nodes deployed at the “edge” of your computing environment as API gateways, these
KA
,KB
, etc. nodes are deployed local to the services they are proxying as node proxies or sidecars.
- Unlike Kong nodes deployed at the “edge” of your computing environment as API gateways, these
Connections Between Services and Proxies
Though the arrows in this section point only one way for simplicity, it represents both the request and the response traffic. This same convention of “arrow on one end only, for clarity” applies throughout this example.
->
represents a non-TLS local connection--->
represents a non-TLS network connection>>>>
represents a TLS/HTTPS network connection===>
represents a Kong mutual TLS (KmTLS) network connection between Kong nodes
Kong Configurations
- Kong Routes are used to configure the “incoming” side of a Kong proxy. A Route must be associated to one Service.
- Kong Services are used to configure the “outgoing” or upstream side of a Kong proxy. A Service is associated with one or more Routes.
Deployment and Configuration
Here is an architectural walkthrough of how to deploy Kong as a service mesh, which will highlight some of the advantages of this pattern and where they come from. For a full tutorial with code snippets, please see the Streams and Service Mesh documentation.
- Start with Service A making HTTP requests to Service B across the network:
A--->B
. This connection is unsecured and unobservable, and the traffic is traveling over a network, which is inherently unreliable. - Deploy an instance of Kong
K
and its required datastore to start your Kong cluster. This Kong node can be configured as a Control Plane node only – we’ll be using it only for configuring Kong, not for proxying traffic. - Connect to the Kong Admin API and configure a Service that sends traffic to
B
via HTTPS and a matching Route that accepts incoming requests forB
via both HTTP and HTTPS. (Note that if we started using this Service+Route immediately, we’d get an error becauseB
cannot terminate TLS connections.) - Deploy a Kong proxy
KB
local toB
and configureorigins
,transparent
andiptables
. You now have a Kong proxy in front ofB
proxying all inbound requests and outbound response traffic, and you’ve made no changes toB
.- Although Service B cannot terminate TLS connections, the
origins
configKONG_ORIGINS="https://B:443=http://B:80
causes traffic that KB would normally send via HTTPS to port 8443 to instead be sent via HTTP to port 80. - Kong “blocks by default,” which means that given this configuration,
B
can’t initiate any requests becauseKB
is now intercepting all outbound requests, and there is not yet a Kong Service+Route forKB
to send such requests. - We aren’t yet benefiting from the Kong proxy – while
KB
is in the request/response path, it isn’t doing anything helpful. - The current situation looks like this:
A--->KB->B
.- If we had a new Service X that sent HTTPS requests to
B
, we could also haveX>>>KB->B.
- If we had a new Service X that sent HTTPS requests to
- Although Service B cannot terminate TLS connections, the
A
is sending requests toB
via unencrypted HTTP. An HTTPS connection betweenA
andB
with mTLS would make communication more secure and is one of the capabilities that Kong can provide when deployed as a mesh.A
doesn’t initiate HTTPS connections, and we can’t make changes toA
. To get the security improvement we seek, first deploy another Kong proxyKA
, local toA
, configured withorigins
,transparent
andiptables
. Let’s examine in detail what happens now:A
initiates an HTTP connection toB
as usual. The configuration oftransparent
andiptables
causesKA
to intercept this request.A->KA
KA
uses the Service+Route configured in step #3 of this example to accept the incoming request via HTTP, then send it across the network toB
via HTTPS.A->KA>>>
- The configuration of
transparent
andiptables
onKB
causesKB
to intercept the HTTPS request fromKA
rather than having the request reachB
directly – which is necessary because unlikeB
,KB
is able to terminate TLS connections.A->KA>>>KB
KA
andKB
automatically upgrade the TLS connection to mutual TLS (mTLS) using Kong-generated certificates. We call mTLS with Kong certs a `KmTLS` connection. We now have a paired proxy.A->KA===>KB
KB
terminates the TLS connection and forwards the request toB
via a local HTTP connection. The configuration of origins onKB
causesKB
to send traffic toB
locally rather than across the network asKA
did.A->KA===>KB->B
- The response flows “in reverse:” When
B
responds via HTTP,KB
receives the response and sends it over the KmTLS connection toKA
.KA
terminates TLS and forwards the response toA
via a local HTTP connection.A<-KA<===KB<-B
- In step #3, we configured the Route for
B
to accept both HTTP and HTTPS traffic. As long as there are applications that might callB
over HTTP, we need to leave this configuration. However, if we can assert “starting now, all communications withB
must be secured with TLS,” then we canPATCH
the configuration of the Route forB
to accept only HTTPS requests. In our example above, the only service callingB
isA
, and it is now doing so via TLS (which is initiated byKA
) – thus, to ensure that our cross-network traffic is always encrypted, you can make this PATCH change now. - Now that we’ve got a paired proxy between
A
andB
, we can start applying Kong plugins that run only onKA
(like authentication), only onKB
(like rate limiting with a local counter), or on both (like Zipkin tracing).
Stay tuned for the next blog posts in our series, in which we’ll examine how to use paired proxies to solve observability, security and reliability problems in distributed application architectures.
The post Steps to Deploying Kong as a Service Mesh appeared first on KongHQ.