Tutorial: Federate clusters and isolate workloads for multitenancy
Use the Bookinfo sample app to try out multitenancy, federation, and isolation across multiple clusters.
- Multitenancy: Gloo workspaces let you delegate management and policy decisions to your teams. You create workspaces, and select the appropriate namespaces and clusters for the workspaces. Note that in multicluster setups, a workspace can even include namespaces across clusters. Afterwards, the rest of your teams access only the namespaces in the clusters that they need.
- Federation: With Gloo, you can federate trust so that services in different clusters can communicate with each other. In this example, Gloo handles the certificates for you, but you can optionally bring your own. Federation lets you easily reuse policies and other resources across your multi-mesh environment.
- Isolation: To enforce a zero trust model from the start, you can enable isolation for services. Isolated services cannot communicate with services outside the mesh or in another workspace, and mTLS is used for communication across services. Teams must set up their workspaces to import and export the services that they need.
The following figure depicts the multi-mesh architecture created by this guide.
Before you begin
- Install Gloo Mesh Enterpise and Istio in a multicluster environment.
- Install Bookinfo and other sample apps.
- Set up routing for the sample apps.
Set up multitenancy by creating workspaces for your workloads
Gloo introduces a new concept for Kubernetes-based multitenancy, the Workspace custom resource. A workspace consists of one or more Kubernetes namespaces that are in one or more clusters. Think of a workspace as the boundary of your team’s resources. To get started, you can create a workspace for each of your teams. Your teams might start with their apps in a couple Kubernetes namespaces in a single cluster. As your teams scale across namespaces and clusters, their workspaces scale with them. Note that for simplicity, you create all your Gloo custom resources only in the management cluster. For more information, see the Multitenancy concept.
Create a
bookinfoworkspace that spans across all your clusters, and includes only thebookinfonamespaces in each cluster. Note that you must create the workspace resource in thegloo-meshnamespace of the management cluster. For more information about setting up workspaces, see Create a workspace.kubectl apply --context ${MGMT_CONTEXT} -f- <<EOF apiVersion: admin.gloo.solo.io/v2 kind: Workspace metadata: name: bookinfo namespace: gloo-mesh spec: workloadClusters: - name: '*' namespaces: - name: bookinfo EOFConfigure settings for the
bookinfoworkspace, which include:- Enabled federation: Services in different clusters can communicate with each other. For example, even though the services in the
bookinfoworkspace are in different clusters, they are able to communicate with each other. In subsequent steps, you create routes in a route table to forward traffic between Bookinfo services across clusters. - Enabled service isolation: Services are isolated and cannot communicate with services outside the mesh or in another workspace by default. mTLS is used for communication across services.
- Exporting: Because service isolation is enabled, the resources in this workspace are exported to the
istio-systemworkspace. This setting enables the ingress gateway in theistio-systemworkspace to use the resources in thebookinfoworkspace.
kubectl apply --context ${MGMT_CONTEXT} -f- <<EOF apiVersion: admin.gloo.solo.io/v2 kind: WorkspaceSettings metadata: name: bookinfo-settings namespace: bookinfo spec: exportTo: - workspaces: - name: istio-system options: serviceIsolation: enabled: true federation: enabled: false serviceSelector: - {} hostSuffix: 'global' EOF- Enabled federation: Services in different clusters can communicate with each other. For example, even though the services in the
Create an
istio-systemworkspace that spans across clusters, and includes theistio-systemandistio-eastwestnamespaces in each cluster. This ensures that theistiodcontrol plane components as well as the gateways are included in the same workspace.kubectl apply --context ${MGMT_CONTEXT} -f- <<EOF apiVersion: admin.gloo.solo.io/v2 kind: Workspace metadata: name: istio-system namespace: gloo-mesh spec: workloadClusters: - name: '*' namespaces: - name: istio-system - name: istio-eastwest EOFConfigure settings for the
istio-systemworkspace. Resources are imported for use from thebookinfoworkspace.kubectl apply --context ${MGMT_CONTEXT} -f- <<EOF apiVersion: admin.gloo.solo.io/v2 kind: WorkspaceSettings metadata: name: istio-system-settings namespace: istio-system spec: importFrom: - workspaces: - name: bookinfo EOFModify the default workspace that you created in the quick-start guide to become a management-only workspace.
kubectl apply --context ${MGMT_CONTEXT} -f- <<EOF apiVersion: admin.gloo.solo.io/v2 kind: Workspace metadata: name: ${MGMT_CLUSTER} namespace: gloo-mesh spec: workloadClusters: - name: '${MGMT_CLUSTER}' namespaces: - name: 'gloo-mesh' EOF
As you create more workspaces, you can create global workspace settings in the management cluster that apply by default to each workspace in your Gloo Mesh environment. For more information, see Configure workspace settings.
Test service isolation by blocking access from services
In the previous section, you enabled service isolation for the Bookinfo workspace. When service isolation is enabled:
- Services in the mesh cannot communicate with services outside of the mesh.
- Communication between services within the mesh are permitted only when services are in the same workspace or when their workspaces have rules to import/export resources between them.
To verify that services within the workspace are isolated, deploy two demo apps to an isolation-test namespace in cluster1, which is not part of the bookinfo workspace. One version of the app is included in the Istio service mesh, and one version is not included in the mesh. Then, attempt to curl the Bookinfo services from the demo apps to test service isolation.
Create the
isolation-testnamespace oncluster1. Do not label this namespace for Istio injection.kubectl create ns isolation-test --context ${REMOTE_CONTEXT1}Create an app named
in-meshthat is part of the Istio service mesh.kubectl -n isolation-test apply -f https://raw.githubusercontent.com/solo-io/gloo-mesh-use-cases/main/policy-demo/httpbin-in-mesh-gloo.yaml --context ${REMOTE_CONTEXT1}Create another app named
not-in-meshthat is not part of the Istio service mesh.kubectl -n isolation-test apply -f https://raw.githubusercontent.com/solo-io/gloo-mesh-use-cases/main/policy-demo/httpbin-not-in-mesh.yaml --context ${REMOTE_CONTEXT1}Verify that the app pods have a status of running.
kubectl -n isolation-test get pods --context ${REMOTE_CONTEXT1}Curl the
reviewsservice from thein-meshservice. This curl returns a403response code because the sidecar of thereviewsservice blocks the request. Even though the services are both in the same Istio service mesh, they cannot communicate because they are not in the same workspace, and theisolation-testnamespace is not in a workspace with import/export rules for the Bookinfo workspace.pod=$(kubectl --context ${REMOTE_CONTEXT1} -n isolation-test get pods -l app=in-mesh -o jsonpath='{.items[0].metadata.name}') kubectl --context ${REMOTE_CONTEXT1} -n isolation-test debug -i ${pod} --image=curlimages/curl -- curl -s -o /dev/null -w "%{http_code}" http://reviews.bookinfo.svc.cluster.local:9080/reviews/0Curl the
reviewsservice from thenot-in-meshservice. This curl returns a000response code because communication cannot be established. Because the Bookinfo services are isolated, they cannot communicate with services outside of the same Istio service mesh.pod=$(kubectl --context ${REMOTE_CONTEXT1} -n isolation-test get pods -l app=not-in-mesh -o jsonpath='{.items[0].metadata.name}') kubectl --context ${REMOTE_CONTEXT1} -n isolation-test debug -i ${pod} --image=curlimages/curl -- curl -s -o /dev/null -w "%{http_code}" http://reviews.bookinfo.svc.cluster.local:9080/reviews/0Optional: For additional testing, you can change the Bookinfo workspace settings to disable service isolation. Then, when you repeat the commands in steps 5 - 6, the curl commands from both the
in-meshandnot-in-meshservices now receive200response codes. Services within the same mesh and outside of the mesh can access the Bookinfo services because they are no longer isolated.kubectl apply --context ${MGMT_CONTEXT} -f- <<EOF apiVersion: admin.gloo.solo.io/v2 kind: WorkspaceSettings metadata: name: bookinfo-settings namespace: bookinfo spec: exportTo: - workspaces: - name: 'istio-system' options: serviceIsolation: enabled: false federation: enabled: false serviceSelector: - {} hostSuffix: 'global' EOF
Cleanup
You can optionally remove the resources that you set up as part of this guide.
Remove the demo app components.
kubectl -n isolation-test delete -f in-mesh.yaml --context ${REMOTE_CONTEXT1} kubectl -n isolation-test delete -f https://raw.githubusercontent.com/solo-io/gloo-mesh-use-cases/main/policy-demo/httpbin-not-in-mesh.yaml --context ${REMOTE_CONTEXT1}Delete the
isolation-testnamespace.kubectl delete ns isolation-test --context ${REMOTE_CONTEXT1}To revert your workspace setup to the single default workspace:
- Modify the default workspace to select all clusters and namespaces again.
kubectl apply --context ${MGMT_CONTEXT} -f- <<EOF apiVersion: admin.gloo.solo.io/v2 kind: Workspace metadata: name: ${MGMT_CLUSTER} namespace: gloo-mesh spec: workloadClusters: - name: '*' namespaces: - name: '*' EOF - Delete the
bookinfoandistio-systemworkspaces and workspace settings.kubectl delete WorkspaceSettings istio-system-settings --context ${MGMT_CONTEXT} kubectl delete Workspace istio-system --context ${MGMT_CONTEXT} kubectl delete WorkspaceSettings bookinfo-settings --context ${MGMT_CONTEXT} kubectl delete Workspace bookinfo --context ${MGMT_CONTEXT}
- Modify the default workspace to select all clusters and namespaces again.
If you no longer need this quick-start Gloo Mesh environment, you can deregister workload clusters, uninstall management plane components from the management cluster, and uninstall Istio resources from the workload clusters by following the steps in Uninstalling Gloo Mesh and Istio.