////
This module included in the following assemblies:
* service_mesh/v2x/ossm-federation.adoc
////

[id="ossm-federation-config-export_{context}"]
= Exporting a service from a federated mesh

Exporting services allows a mesh to share one or more of its services with another member of the federated mesh.

image::ossm-federation-export-service.png[Service Mesh federation exporting service illustration]

You use an `ExportedServiceSet` resource to declare the services from one mesh that you are making available to another peer in the federated mesh. You must explicitly declare each service to be shared with a peer.

* You can select services by namespace or name.
* You can use wildcards to select services; for example, to export all the services in a namespace.
* You can export services using an alias. For example, you can export the `foo/bar` service as `custom-ns/bar`.
// Need non foo/bar example above
* You can only export services that are visible to the mesh’s system namespace. For example, a service in another namespace with a `networking.istio.io/exportTo` label set to ‘.’ would not be a candidate for export.
* For exported services, their target services will only see traffic from the ingress gateway, not the original requestor (that is, they won’t see the client ID of either the other mesh’s egress gateway or the workload originating the request)

The following example is for services that `red-mesh` is exporting to `green-mesh`.

.Example ExportedServiceSet resource
[source,yaml]
----
kind: ExportedServiceSet
apiVersion: federation.maistra.io/v1
metadata:
  name: green-mesh
  namespace: red-mesh-system
spec:
  exportRules:
  # export ratings.mesh-x-bookinfo as ratings.bookinfo
  - type: NameSelector
    nameSelector:
      namespace: red-mesh-bookinfo
      name: red-ratings
      alias:
        namespace: bookinfo
        name: ratings
  # export any service in red-mesh-bookinfo namespace with label export-service=true
  - type: LabelSelector
    labelSelector:
      namespace: red-mesh-bookinfo
      selector:
        matchLabels:
          export-service: "true"
      aliases: # export all matching services as if they were in the bookinfo namespace
      - namespace: "*"
        name: "*"
        alias:
          namespace: bookinfo
----

.ExportedServiceSet parameters
[options="header"]
[cols="l, a, a"]
|===
|Parameter |Description |Values
|metadata:
  name:
|Name of the ServiceMeshPeer you are exposing this service to.
|Must match the `name` value for the mesh in the `ServiceMeshPeer` resource.

|metadata:
  namespace:
|Name of the project/namespace containing this resource (should be the system namespace for the mesh) .
|

|spec:
  exportRules:
  - type:
|Type of rule that will govern the export for this service. The first matching rule found for the service will be used for the export.
|`NameSelector`, `LabelSelector`

|spec:
  exportRules:
  - type: NameSelector
    nameSelector:
      namespace:
      name:
|To create a `NameSelector` rule, specify the `namespace` of the service and the `name` of the service as defined in the `Service` resource.
|

|spec:
  exportRules:
  - type: NameSelector
    nameSelector:
      alias:
        namespace:
        name:
|To create a `NameSelector` rule that uses an alias for the service, after specifying the `namespace` and `name` for the service, then specify the alias for the `namespace` and the alias to be used for `name` of the service.
|

|spec:
  exportRules:
  - type: LabelSelector
    labelSelector:
      namespace: <exportingMesh>
      selector:
        matchLabels:
          <labelKey>: <labelValue>
|To create a `LabelSelector` rule, specify the `namespace` of the service and specify the `label` defined in the `Service` resource. In the example above, the label is `export-service`.
|

|spec:
  exportRules:
  - type: LabelSelector
    labelSelector:
      namespace: <exportingMesh>
      selector:
        matchLabels:
          <labelKey>: <labelValue>
      aliases:
      - namespace:
        name:
        alias:
          namespace:
          name:
|To create a `LabelSelector` rule that uses aliases for the services, after specifying the `selector`, specify the aliases to be used for `name` or `namespace` of the service. In the example above, the namespace alias is `bookinfo` for all matching services.
|
|===



.Export services with the name "ratings" from all namespaces in the red-mesh to blue-mesh.
[source,yaml]
----
kind: ExportedServiceSet
apiVersion: federation.maistra.io/v1
metadata:
  name: blue-mesh
  namespace: red-mesh-system
spec:
  exportRules:
  - type: NameSelector
    nameSelector:
      namespace: "*"
      name: ratings
----

.Export all services from the west-data-center namespace to green-mesh
[source,yaml]
----
kind: ExportedServiceSet
apiVersion: federation.maistra.io/v1
metadata:
  name: green-mesh
  namespace: red-mesh-system
spec:
  exportRules:
  - type: NameSelector
    nameSelector:
      namespace: west-data-center
      name: "*"
----
