---
layout: docs
page_title: Discover services with Pivotal Application Service (PAS)
description: >-
  Use Consul DNS with Pivotal Application Service to discover external services.
---

# Discover services with Pivotal Application Service (PAS)

This page describes the process to discover services external to your datacenter using the Pivotal Application Service (PAS).

## Overview

Pivotal Application Service (PAS) is a cloud-agnostic platform for running
applications. It abstracts away the complexity of running your own
infrastructure and networking for an application and gives developers the
ability to focus on writing code. It has many features, including its own
internal service discovery. In hybrid environments, where workloads can run on
multiple platforms or clouds, applications running on PAS may need to discover
services external to the platform.

Consul’s DNS interface is one of its primary querying interfaces for discovering
external services. This introductory tutorial describes the basics on how to
configure your PAS installation to delegate DNS lookups for Consul-specific
domains to the Consul servers.

## Prerequisites

This tutorial assumes basic familiarity with Consul,
[PAS](https://pivotal.io/platform/pivotal-application-service), as well as its
tools, like [BOSH](https://bosh.io/docs/) and [Ops
Manager](https://pivotal.io/platform/pcf-components/pcf-ops-manager). You will
be able complete this tutorial without production experience.

Here is what you will need for this tutorial:

- A running installation of PAS
- Ability to make and apply changes in Pivotal Ops Manager
- Ability to push applications to PAS
- IPs or DNS name(s) of the Consul servers that you will be connecting to

You will also need to ensure that the container host VMs (aka Diego VMs) have
network connectivity to the Consul servers.

![Consul DNS and PCF](/img/architecture/consul-pcf-arch.png 'Service discovery with Consul DNS')

## Configure PAS to use Consul DNS

Log in to your Pivotal Ops Manager instance, use [Pivotal
documentation](https://docs.pivotal.io/platform/ops-manager/2-7/) for
instructions specific to your installation.

From your installation dashboard navigate to the “BOSH DNS Config Page” within
the BOSH Director tile.

Add the following configuration to the `Handlers` field, setting `recursors` to
the IPs or DNS names of your Consul servers.

```json
[
  {
    "cache": {
      "enabled": true
    },
    "domain": "consul.",
    "source": {
      "recursors": ["10.52.0.63:8600", "10.52.0.55:8600", "10.52.0.43:8600"],
      "type": "dns"
    }
  }
]
```

This configuration sets the Consul server running on `10.52.0.63` and the
default DNS port `8600`.

If the Consul server is configured with a [different
domain](/consul/docs/reference/agent/configuration-file/dns#domain), make sure to
change the `domain` property above to reflect that.

Your resulting page should include the configuration in the `Handlers` field.

![PCF UI](/img/pcf-ui.png 'Configure PCF UI')

When ready, click "Save". Note that you will need to review and apply pending
changes in Ops Manager to apply the configuration.

## Discover a service with Consul DNS

Now that you have configured Consul’s DNS as a query interface, you can test
that it works by deploying a [simple demo
application](https://github.com/cloudfoundry-samples/cf-sample-app-spring.git).
From the demo application container, you will be able to query Consul DNS.

First, log in to PAS.

```shell-session
$ cf login -a api.sys.example.com
```

Create an organization.

```shell-session
$ cf create-org hashicorp
```

Create a space.

```shell-session
$ cf create-space -o hashicorp consul-demo
```

Target an organization and a space.

```shell-session
$ cf target -o hashicorp -s consul-demo
```

Next, download the demo application.

```shell-session
$ git clone https://github.com/cloudfoundry-samples/cf-sample-app-spring.git
```

Move into the directory for the downloaded app.

```shell-session
$ cd cf-sample-app-spring
```

Deploy the demo application.

```shell-session
$ cf push
```

The demo application is maintained by Cloud Foundry.

Finally, SSH into the demo application container and use `dig` to discover all
running instances of the Consul service.

```shell-session
$ cf ssh cf-demo -c 'dig consul.service.consul'
```

```plaintext
; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> consul.service.consul
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62872
;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 4
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;consul.service.consul.   	 IN    A

;; ANSWER SECTION:
consul.service.consul.    5    IN    A    10.52.0.63
consul.service.consul.    5    IN    A    10.52.0.55
consul.service.consul.    5    IN    A    10.52.0.43

;; ADDITIONAL SECTION:
consul.service.consul.    5    IN    TXT    "consul-network-segment="
consul.service.consul.    5    IN    TXT    "consul-network-segment="
consul.service.consul.    5    IN    TXT    "consul-network-segment="

;; Query time: 2 msec
;; SERVER: 169.254.0.2#53(169.254.0.2)
;; WHEN: Thu Dec 05 07:04:34 UTC 2019
;; MSG SIZE  rcvd: 332
```

## Next steps

In this tutorial you learned how to configure Pivotal Application Service (PAS)
to use Consul’s DNS interface for service discovery of external services. If you
have services deployed in hybrid environments, such as VMs or Kubernetes, you
will now be able to discover them using Consul’s DNS interface.

Learn more about [Consul service discovery and
registration](/consul/tutorials/get-started-vms/virtual-machine-gs-service-discovery) and
[Consul’s DNS interface](/consul/docs/discover/dns).
