Deploy Service to Grey Matter on Kubernetes
Last updated
Was this helpful?
Last updated
Was this helpful?
This guide is a step by step walkthrough on deploying a new service into . This guide is for a SPIFFE/SPIRE enabled deployment. For a walkthrough on deploying a service into a non-SPIFFE/SPIRE Grey Matter setup, follow the .
If you are looking for a quick service deployment and/or configuration guide, check out the .
An existing Grey Matter deployment running on Kubernetes ()
kubectl
or oc
setup with access to the cluster
greymatter
cli with access to the deployment
Launch pod with the service and sidecar
Create Fabric configuration for the sidecar to talk to the service
Create Fabric configuration for the Edge to talk to the sidecar
Add entry in Catalog service to display in the Intelligence 360 Applications
The service we'll launch is a simple Fibonacci service. It has one route: /fibonacci
that calculates the fibonacci sequence of any integer supplied.
Note the spire-specific configurations to the deployment - the volume and volume mount spire-socket
and the environment variable SPIRE_PATH
. These are the additions that will need to be made to any deployment for a service you wish to add to the mesh with SPIFFE/SPIRE.
Save the above deployment file as deployment.yaml
and launch the pod:
The next steps are to create objects in the Fabric API. These objects will create all the configuration for the Sidecar to handle requests on behalf of the deployed service.
For each Grey Matter object created, create the local file and send them to the API with: greymatter create <object> < <file_name.json>
.
The first object to create is a Grey Matter Domain the ingress domain for the fibonacci sidecar. This object does virtual host identification, but for this service we'll accept any hosts ("name": "*") that come in on the port 10080 (the port with name proxy
-or value of Grey Matter Control environment variable GM_CONTROL_KUBERNETES_PORT_NAME
-in the sidecar container). Note that force_https
is set to true, requiring any incoming connection be https
.
Save this file as domain.json
and apply it with
The next object is the ingress listener. This is the physical binding of the Sidecar to a host interface and port and is linked in the field domain_keys
to a specific domain. The listener and domain configurations determine where the sidecar
should listen for incoming connections on and what kind of connections it should accept.
Save this file as listener.json
and apply it with
The proxy object links a sidecar deployment to it's Grey Matter objects. The name
field must match the label on the deployment (in this case greymatter.io/control
) that Grey Matter Control is looking for in it's environment variable GM_CONTROL_KUBERNETES_CLUSTER_LABEL
. It takes a list of domain_keys
and listener_keys
to link to the deployment with cluster label matching name
.
Save this file as proxy.json
and apply it with
The next object to create is a local cluster. The cluster is in charge of the egress connection from a sidecar to whatever service is located at its configured instances
, and can set things like circuit breakers, health checks, and load balancing policies.
This "local" cluster will tell the sidecar where to find the fibonacci
container to send requests. From the deployment above, we configured the fibonacci
container at port 8080
. Since the sidecar
and fibonacci
containers are running in the same pod, they can communicate over localhost
.
Save this file as fibonacci-local-cluster.json
and apply it with
Save this file as fibonacci-local-rules.json
and apply it with
Save this file as fibonacci-local-route.json
and apply it with
The sidecar
will now be configured to properly accept requests and route to the fibonacci
service. The next step will configure the Edge proxy to route to the sidecar.
Now that the Sidecar-to-Service routing has been configured, we will set up the Edge-to-Sidecar routing because we want this service to be available to external users.
The process will take similar steps to what was done before, but we only need to create a cluster, a shared_rules object pointing at that cluster, and two routes.
This cluster has a secret
set on it, and require_tls
is true. This is because the edge proxy and the fibonacci sidecar
are running in different pods so they can't connect over localhost and must use their SPIFFE SVIDs for communication.
Save this file as edge-to-fibonacci-cluster.json
and apply it with
Save this file as edge-to-fibonacci-rules.json
and apply it with
They are nearly identical, but one provides for the case that the path
on the request to send to the fibonacci service ends in a slash, and one for the case that it doesn't.
This route looks for the path
on a request into the edge proxy /services/fibonacci
with no trailing slash, replaces that path
with /
, and sends the request to the cluster (edge-to-fibonacci-cluster
) being pointed to by the edge-to-fibonacci-rules
.
This route looks for the path
on a request into the edge proxy /services/fibonacci/
this time with a trailing slash, replaces that path
with /
, and sends the request to the same cluster.
Save these files as edge-to-fibonacci-route.json
and edge-to-fibonacci-route-slash.json
and apply them with
Once these routes are applied, the service is fully configured in the mesh! You should be able to access the service at https://{your-gm-ingress-url}:{your-gm-ingress-port}/services/fibonacci/
with response Alive
. To send a request for a specific fibonacci number, https:///{your-gm-ingress-url}:{your-gm-ingress-port}/services/fibonacci/fibonacci/<number>
.
and copy the EXTERNAL-IP
and port (by default the port will be 10808).
The last step in deploying a service is to add the expected service entry to the Grey Matter Catalog service. This will interface with the control plane, and provide information to the Intelligence 360 Application for display.
Save this file as fibonacci-catalog.json
and using the quickstart certificates from the helm chart repository at ./certs, make the following post request to the catalog service:
You'll see the following response if the addition was successful.
And the service will display in the Intelligence 360 Application.
This step creates and configures the Grey Matter objects necessary to allow the sidecar
container in the deployment to route to the fibonacci
container (the service itself). We will refer to this as "local" routing. The will configure the Edge proxy to route to the fibonacci sidecar
, thus fully wiring the new service into the mesh for routing.
NOTE: This guide goes over deploying a new service and configuring it for ingress routing. To configure a service for both ingress and egress routing within the mesh, see the .
See the for more information.
The listener object is also the place to configure . See the for more information.
Note the secret
field. This field is required for service to service communication in a SPIFFE/SPIRE setup. This secret tells the sidecar to fetch its SVID (with ID spiffe://quickstart.greymatter.io/fibonacci
) from Envoy and present it to incoming connections. It also will set a with match subject alternative names specifies to only accept incoming requests with SAN spiffe://quickstart.greymatter.io/edge
. See the for specifics. The listener secret
configuration will be important for the .
See the for more information.
See the for more information.
The shared rules object is used to match to . They can do some features of routes like setting retry_policies and appending response data, but they also can perform traffic splitting between clusters for operations like blue/green deployments.
This local shared rules object will be used to link the in the next step to the that we just created.
See the for more information.
match against requests by things like URI path, headers, cookies, or metadata and map to shared_rules. Since this service only needs to forward everything it receives to the local microservice, the setup is fairly simple.
This "local" route will link the (fibonacci-domain
) to the (fibonacci-local-rules
) that we just created. We know that the fibonacci-local-rules
object is used to link routes to the fibonacci-cluster
, thus with this route object applied, the fibonacci sidecar
will be configured to accept requests and route to the fibonacci
service.
See the for more information.
The path
indicates that any request coming into the sidecar
with path /
should be routed to the fibonacci
service. We will see in the next step when configuring that all requests from the Edge proxy to the fibonacci service will come in at this path
.
This will handle traffic from the Edge to the Fibonacci Sidecar. The Edge has existing domain
(with domain key edge
), listener
, and proxy
much like the ones we just created for the fibonacci service. The first step to configure the Edge to fibonacci service is to create a cluster to tell it where to find the fibonacci sidecar.
NOTE that there are several differences between this cluster and the created above:
The instances
field is left as an empty string, whereas the fibonacci-local-cluster
instances were configured. This is because Grey Matter Control will discover the fibonacci deployment and the instances array will be automatically populated from this service discovery: the instances will go up and down whenever the service scales or changes. To do this, (in the same way as described in creating the object above) the name
field must match the cluster label on the deployment.
The secret
here mirrors the one set on the . As stated , the cluster is in charge of the egress connection from a sidecar to whatever service is located at its instances
.
In this case, the secret
is telling the Edge proxy to fetch its SVID (with ID spiffe://quickstart.greymatter.io/edge) from Envoy SDS and present it on its outgoing connections. It will also only accept connections that present a certificate with SAN spiffe://quickstart.greymatter.io/fibonacci
. See the for specifics.
As described in the secret
configuration on the , these are opposites. The request from this cluster will be accepted by the fibonacci sidecar
and vice versa.
The edge to fibonacci will be used to link the to the edge-to-fibonacci-cluster
.
There are two that need to be created to send requests through the Edge proxy to the fibonacci service. In the same way that the was connected to the fibonacci-domain
, these routes will be connected to the edge
domain, and will configure how the edge
sidecar sends routes.
If you don't know your gm ingress url and you followed the guide, run