# Service Directory: Qwik Start - GSP732

## **Overview**

[Service Directory](https://cloud.google.com/service-directory) helps reduce the complexity of management and operations by providing a single place to publish, discover, and connect services. It is a managed service that enhances service inventory management at scale so you don’t have to. Service Directory provides real-time service information, whether you have a few service endpoints or thousands. This helps ensure that your applications only resolve the most updated information of their resources, increasing the reachability of your services.

With Service Directory, you can easily understand all your services across multi-cloud environments. This includes workloads running in Compute Engine VMs, Google Kubernetes Engine (GKE), as well as external services running on-prem and third-party clouds. It improves application reachability by maintaining the endpoint information for all your services.

Service Directory solves the following problems:

1.  **Interoperability**: Service Directory is a universal naming service that works across Google Cloud, multi-cloud, and on-premises. You can migrate services between these environments and still use the same service name to register and resolve endpoints.
    
2.  **Service management**: Service Directory is a managed service. Your organization doesn't have to worry about the high availability, redundancy, scaling, or maintenance concerns of maintaining your own service registry.
    
3.  **Access Control**: With Service Directory, you can control who can register and resolve your services using IAM. Assign Service Directory roles to teams, service accounts, and organizations.
    
4.  **Limitations of pure DNS**: DNS resolvers can be unreliable in terms of respecting TTLs and caching, cannot handle larger record sizes, and do not offer an easy way to serve metadata to users. In addition to DNS support, Service Directory offers HTTP and gRPC APIs to query and resolve services.
    

### What you'll learn

In this lab, you will:

*   Configure Service Directory, with a namespace, service, and endpoint
    
*   Configure a Service Directory DNS zone
    
*   Use Cloud Logging with Service Directory
    

## **Setup and requirements**

### Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click **Start Lab**, shows how long Google Cloud resources are made available to you.

This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

*   Access to a standard internet browser (Chrome browser recommended).
    

**Note:** Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.

*   Time to complete the lab—remember, once you start, you cannot pause a lab.
    

**Note:** Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.

### How to start your lab and sign in to the Google Cloud console

1.  Click the **Start Lab** button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
    
    *   The Open Google Cloud console button
        
    *   Time remaining
        
    *   The temporary credentials that you must use for this lab
        
    *   Other information, if needed, to step through this lab
        
2.  Click **Open Google Cloud console** (or right-click and select **Open Link in Incognito Window** if you are running the Chrome browser).
    
    The lab spins up resources, and then opens another tab that shows the Sign in page.
    
    ***Tip:*** Arrange the tabs in separate windows, side-by-side.
    
    **Note:** If you see the **Choose an account** dialog, click **Use Another Account**.
    
3.  If necessary, copy the **Username** below and paste it into the **Sign in** dialog.
    
    ```apache
    student-04-f91304fe7f1d@qwiklabs.net
    ```
    
    You can also find the Username in the Lab Details pane.
    
4.  Click **Next**.
    
5.  Copy the **Password** below and paste it into the **Welcome** dialog.
    
    ```apache
    RwCSKCzd8eIQ
    ```
    
    You can also find the Password in the Lab Details pane.
    
6.  Click **Next**.
    
    **Important:** You must use the credentials the lab provides you. Do not use your Google Cloud account credentials.
    
    **Note:** Using your own Google Cloud account for this lab may incur extra charges.
    
7.  Click through the subsequent pages:
    
    *   Accept the terms and conditions.
        
    *   Do not add recovery options or two-factor authentication (because this is a temporary account).
        
    *   Do not sign up for free trials.
        

After a few moments, the Google Cloud console opens in this tab.

**Note:** To access Google Cloud products and services, click the **Navigation menu** or type the service or product name in the **Search** field.

![Navigation menu icon and Search field](https://cdn.qwiklabs.com/9Fk8NYFp3quE9mF%2FilWF6%2FlXY9OUBi3UWtb2Ne4uXNU%3D align="left")

## **Task 1. Configuring Service Directory**

This section shows how to set up a Service Directory namespace, add a service to the namespace, and add endpoints to a service.

1.  In the Console, search for "network services", then select **Network Services**.
    
2.  From the **Network Services** menu, select **Service Directory**.
    
3.  Click **Enable** to enable the Service Directory API.
    

### Configure a namespace

1.  In the Service Directory page, click **+REGISTER SERVICE**.
    
2.  On the Register service page select **Standard** for Service type.
    
3.  Click **Next**.
    
4.  In the **Region** pull-down menu, select a region for your namespace. For this lab, use `us-east4`.
    
5.  In the **Namespace** field, select **CREATE NAMESPACE**.
    
6.  In the **Namespace name** field give your namespace a name. For this lab, you can use `example-namespace`. Click **Create**.
    
7.  Enter a **Service name**. For this lab use `example-service`.
    
8.  Click **Create**.
    

### Configuring an endpoint

Once the service is registered, add some endpoints. An endpoint consists of a unique name and the optional fields of address, port, and key/value metadata. The address, if specified, must be valid IPv4 or IPv6.

1.  In the Service Directory page, click the service you just created.
    
2.  Click **+Add Endpoint**.
    
3.  Provide an **Endpoint name**. For this example, you can use `example-endpoint`.
    
4.  Enter an IPv4 or IPv6 **IP address**. For this example, you can use `0.0.0.0`.
    
5.  Enter a **Port number**. For this example, you can use `80`.
    
6.  Click **Create**.
    

Click *Check my progress* to verify the objective.

Configuring Service Directory

Check my progress

## **Task 2. Configuring a Service Directory DNS zone**

You can create a Service Directory zone that allows your Google Cloud-based services to query your Service Directory namespace via DNS.

1.  From the **Network Services** menu, select **Cloud DNS**.
    
2.  Click **Create zone**.
    
3.  In the Zone type section, select **Private**.
    
4.  Give the zone a name. For this example, you can use: `example-zone-name`.
    
5.  Give the zone a DNS name. For this example, you can use: `myzone.example.com`.
    
6.  Under **Options**, select `Use a service directory namespace`.
    
7.  Under **Networks**, select one or more networks that can use the Service Directory zone. You should use the `default` network here, then click **OK**.
    
8.  Select the **Region** where the namespace you want to link lives. Start typing `us-east4` then select it.
    
9.  Select the **Namespace** you want to link. This should be the namespace you created earlier `example-namespace`.
    
10.  Click **Create**.
     

**Note:** You can associate only one Service Directory zone with a given namespace, and you cannot associate a given zone with multiple namespaces. You must create the Cloud DNS zone and the Service Directory namespace in the same project.

Click *Check my progress* to verify the objective.

Configuring a Service Directory DNS zone

Check my progress

## **Task 3. Securing Service Directory in a service perimeter**

[VPC Service Controls](https://cloud.google.com/vpc-service-controls/docs/overview) improves your ability to mitigate the risk of data exfiltration from Google Cloud services. With VPC Service Controls, you can configure security perimeters around the resources and data of services that you explicitly specify.

**Note:** This lab does **not** cover creating a service perimeter, but for general instructions to add Service Directory to a service perimeter, refer to [Creating a service perimeter](https://cloud.google.com/vpc-service-controls/docs/create-service-perimeters).

## **Task 4. Querying using DNS**

This section covers DNS querying, but there are no tasks you need to complete.

DNS queries for the following record types are supported:

*   **A/AAAA/SRV** records for a service or an endpoint
    
*   **SOA/NS** records for the private zone origin
    

**A/AAAA** queries must observe the following format:

```apache
service-name.zone-domain-name
```

Optionally:

```apache
endpoint-name.service-name.zone-domain-name
```

**SRV** queries must observe the following format:

```apache
_service-name._tcp.service-name.zone-domain-name
```

Optionally:

```apache
_service-name._tcp.endpoint-name.service-name.zone-domain-name
```

**Note: service-name** appears twice in the query name and the first label is preceded by a literal underscore character.

## **Task 5. Logging and Monitoring**

You can use [Cloud Monitoring](https://cloud.google.com/monitoring) and [Cloud Logging](https://cloud.google.com/logging) with Service Directory.

### Logging

Service Directory produces audit logs that can be viewed through Logging.

#### **Audit logs**

[Audit logs](https://cloud.google.com/logging/docs/audit) can help you answer the questions "Who did what, where, and when?". Service Directory writes two types of audit logs: **admin activity** and **data access**. Admin activity logs are always enabled and apply to the following Service Directory operations:

*   CreateNamespace
    
*   UpdateNamespace
    
*   DeleteNamespace
    
*   SetIamPolicy
    

All other Service Directory operations are considered data access logs and are not enabled by default. Data access logs are also subject to Logging pricing and quota, whereas neither applies to admin activity logs. To enable data access logging, see [Configuring Data Access logs](https://cloud.google.com/logging/docs/audit/configure-data-access#config-console).

1.  To see these logs in [Logging](https://cloud.google.com/logging/docs/view/overview#getting_started), in the Cloud Console, search for "logging" then select **Logging**. You'll be on the **Logs Explorer** page.
    
2.  From the **All resources** dropdown, select **Service Directory Namespace** > `us-east4` > namespace you created earlier. Then click **Apply**.
    
3.  Select `activity` from the **All log names** dropdown and click \_\_Apply. You should see one `CreateNamespace` log.
    
4.  In the Cloud Console return to **Network Services** and select **Service Directory**.
    
5.  For the namespace you created, click the three dots on the right side of the row. Click **Delete**, then **Delete** again.
    
6.  Now go back to **Logging** and go to the **Logs Explorer** page.
    
7.  You should now see a `DeleteNamespace` log.
    

### Monitoring

Monitoring allows you to create dashboards or set up alerts and can be accessed by visiting Monitoring in Cloud Console.

To view basic monitoring metrics (request count, size and latency), you can go to the Metrics Explorer and filter by `resource_type:consumed_api` and `service:servicedirectory.googleapis.com`.

* * *

## Solution of Lab

<iframe type="youtube" src="https://www.youtube.com/watch?v=A5EqPaJVXlc&amp;ab_channel=QUICKGCPLAB" data-node-type="hn-embed"></iframe>

```apache
curl -LO raw.githubusercontent.com/ePlus-DEV/storage/refs/heads/main/labs/GSP732/lab.sh
source lab.sh
```

**Script Alternative**

```apache
export LOCATION=
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739952350907/fa606f18-59fd-43bd-b0fd-863a813288a1.png align="center")

```apache
curl -LO raw.githubusercontent.com/QUICK-GCP-LAB/2-Minutes-Labs-Solutions/main/Service%20Directory%20Qwik%20Start/gsp732.sh
sudo chmod +x gsp732.sh
./gsp732.sh
```
