> [!WARNING]
>
> **Preview**
>
>
> This product or feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section
> of the [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA products and features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

Service Directory for Google Kubernetes Engine (GKE) provides a single view of all
services across all of your GKE deployments and beyond.
You can add various types of GKE services, annotate them,
and then
see those services in Service Directory.

Service Directory for GKE offers the following features:

- It lets you discover services through gRPC and HTTP, and resolve services over DNS using Service Directory DNS zones. The Service Directory and Cloud DNS integration lets you [configure a Service Directory DNS
  zone](https://docs.cloud.google.com/service-directory/docs/configuring-service-directory-zone).
- Service Directory registers services outside of GKE, allowing GKE and non-GKE services to easily discover each other.
- Service Directory enforces IAM permission and VPC Service Controls checks to ensure proper security and privacy of customer data.
- You can configure Service Directory for GKE with Autopilot GKE clusters or Standard GKE clusters. For information about the two modes, see [Choose a GKE mode of operation](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/choose-cluster-mode.md.txt).

To learn about how to configure Service Directory to automatically register
your GKE services with Service Directory, see
[Configuring Service Directory for
GKE](https://docs.cloud.google.com/service-directory/docs/configuring-sd-for-gke).

## Service mapping

When you register a service with Service Directory, a service is created in the
[Google Cloud fleet](https://docs.cloud.google.com/anthos/multicluster-management/fleets) project using
the name of the Kubernetes namespace and
region of the GKE cluster. The following table describes
how the properties on the GKE service are mapped to the
properties on the created service in Service Directory for all
GKE service types.

### Top level properties

|---|---|
| **Service Directory property** | **GKE property** |
| Project | Fleet project |
| Region | Region of the cluster |
| Namespace | Kubernetes namespace |

### `LoadBalancer` service type

The following example shows how a GKE `LoadBalancer` service
is mapped to Service Directory. The Service Directory service exists in a
namespace with the same name as the Kubernetes namespace in the
fleet project and region of the GKE cluster.

|---|---|
| **Service Directory property** | **GKE property** |
| Service name | Service name |
| Endpoint name | Auto-generated by Service Directory Controller |
| Endpoint IP address | LoadBalancer ingress |
| Endpoint port | LoadBalancer service port |
| Endpoint network | VPC network of the cluster |

The following is an example of a GKE `LoadBalancer` service:

```
apiVersion: v1
kind: Service
metadata:
  name: hello-app
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
  labels:
    app: hello-app
    sd-import: "true"
spec:
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
  selector:
    app: hello-app
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 10.140.0.5
```

The following is an example of a Service Directory service:

```
service:
  endpoints:
  - address: 10.140.0.5
    metadata:
       cloud.google.com/load-balancer-type: "Internal"
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app/endpoints/gke-hello-cluster-12345
    port: 80
    network: projects/my-project/locations/global/networks/default
  name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app
```

### `NodePort` service type

The following example shows how a GKE NodePort Service is
mapped to Service Directory. The Service Directory service exists in a namespace
with the same name as the Kubernetes namespace in the project of
the hub and region of the GKE cluster.

|---|---|
| **Service Directory property** | **GKE property** |
| Service name | Service name |
| Endpoint name | Auto-generated by Service Directory Controller |
| Endpoint IP address | Node internal IP address for each node that runs a pod for the service |
| Endpoint port | Static node port |
| Endpoint network | VPC network of the cluster |

The following is an example of a GKE `NodePort` service:

```
apiVersion: v1
kind: Service
metadata:
  name: hello-app
  annotations:
    key1: "value1"
spec:
  ports:
  - nodePort: 30007
    port: 80
    targetPort: 8080
    protocol: TCP
  selector:
    app: hello-app
  type: NodePort
  
```

The following is an example of GKE nodes:

```
apiVersion: v1
items:
- apiVersion: v1
  kind: Node
  metadata:
    name: gke-hello-cluster-default-pool-a40cbab6-d2rr
  status:
    addresses:
    - address: 10.142.0.27
      type: InternalIP
    - address: 34.73.248.170
- apiVersion: v1
  kind: Node
  metadata:
    name: gke-hello-cluster-default-pool-a40cbab6-kb38
  status:
    addresses:
    - address: 10.142.0.29
      type: InternalIP
    - address: 35.196.219.215
      type: ExternalIP
- apiVersion: v1
  kind: Node
  metadata:
    name: gke-hello-cluster-default-pool-a40cbab6-x34q
  status:
    addresses:
    - address: 10.142.0.28
      type: InternalIP
    - address: 34.75.202.26
      type: ExternalIP
    
```

The following is an example of a Service Directory service:

```
service:
  endpoints:
  - address: 10.142.0.27
    metadata:
      key1: value1
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app/endpoints/gke-hello-cluster-12345
    port: 30007
    network: projects/my-project/locations/global/networks/default
  - address: 10.142.0.28
    metadata:
      key1: value1
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app/endpoints/gke-hello-cluster-23456
    port: 30007
    network: projects/my-project/locations/global/networks/default
  - address: 10.142.0.29
    metadata:
      key1: value1
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app/endpoints/gke-hello-cluster-34567
    port: 30007
    network: projects/my-project/locations/global/networks/default
  name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app
  
```

### `ClusterIP` service

The following example shows how a GKE `ClusterIP` service
is mapped to Service Directory. The Service Directory service exists in a
namespace with the same name as the Kubernetes namespace in
the fleet project and region of the GKE cluster.

|---|---|
| **Service Directory property** | **GKE property** |
| Service name | Service name |
| Endpoint name | Auto-generated by Service Directory Controller |
| Endpoint IP address | ClusterIP |
| Endpoint port | Service port |
| Endpoint network | VPC network of the cluster |

The following is an example of a GKE ClusterIP service:

```
apiVersion: v1
kind: Service
metadata:
  name: hello-app
  annotations:
    key1: "value1"
  labels:
    app: hello-app
    sd-import: "true"
spec:
  clusterIP: 10.15.254.17
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
  selector:
    app: hello-app
  type: ClusterIP
  
```

The following is an example of a Service Directory service:

```
service:
  endpoints:
  - address: 10.15.254.17
    metadata:
      key1: value1
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app/endpoints/gke-hello-cluster-12345
    port: 80
    network: projects/my-project/locations/global/networks/default
  name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app
  
```

## What's next

- To get an overview of Service Directory, see the [Service Directory overview](https://docs.cloud.google.com/service-directory/docs/overview.md.txt).
- To find solutions for common issues that you might encounter when using Service Directory, see [Troubleshooting](https://docs.cloud.google.com/service-directory/docs/troubleshooting.md.txt).