This page explains how to configure and run an instance of the Extensible Service Proxy (ESP) on a local machine, on another cloud provider, such as Amazon Web Services (AWS), or on a Kubernetes cluster that isn't on Google Cloud Platform (GCP).
Try out ESP before deploying it to a production platform.
Verify that security settings are configured and working properly, and that metrics and logs appear on the Endpoints > Services page as expected.
Note: We recommend that you use separate GCP projects for development and production. This setup avoids mixing production and development logs and metrics.
You have installed Docker, if you're deploying the ESP container locally or to a VM. See Install Docker for more information.
You have deployed an API locally or on a host that is reachable to the host where you run ESP.
You have configured Cloud Endpoints and deployed the configuration to create a managed service for your API.
If you need an API for testing with ESP, you can configure and deploy the sample code in the Optional: Using a sample API section. If you have already configured and deployed your API, skip to Creating a service account.
This section walks you through configuring and deploying the Python version of the getting-started for Endpoints sample locally. Do the steps in this section only if you don't have an API for testing with ESP.
The Cloud Endpoints getting-started sample is available in other languages. See the Samples page for the GitHub location of the getting-started sample in your preferred language. Follow the instructions in the sample's README.md file for running locally, and then follow the instructions in this section to configure Endpoints and to deploy the Endpoints configuration.
In the sample code directory, open the openapi.yaml configuration file.
In the host field, replace YOUR-PROJECT-ID with your own GCP project ID.
Important: This must be the same project that you select in Creating the service account.
To deploy the Endpoints configuration, you use the gcloud endpoints services deploy command. This command uses Service Management to create a managed service.
In the new browser tab that opens, select an account.
Replace YOUR-PROJECT-ID with the project ID of the GCP project that you specified in the openapi.yaml file.
Service Management uses the text that you specified in the host field in the openapi.yaml file to create a new Endpoints service with the name echo-api.endpoints.YOUR-PROJECT-ID.cloud.goog (if it doesn't exist), and then configures the service according to your OpenAPI configuration file.
In the preceding example, 2017-02-13r0 is the service configuration ID, and echo-api.endpoints.example-project-12345.cloud.goog is the service name.
Create a virtualenv, activate it, and install the application dependencies.
To provide management for your API, ESP requires the services in Service Infrastructure. To call these services, ESP must use access tokens. When you deploy ESP to GCP environments, such as GKE, Compute Engine, or the App Engine flexible environment, ESP obtains access tokens for you through the GCP metadata service.
When you deploy ESP to a non-GCP environment, such as your local desktop, an on-premises Kubernetes cluster, or another cloud provider, you must provide ESP with a service account JSON file that contains a private key. ESP uses the service account to generate access tokens to call the services that it needs to manage your API.
In the GCP Console, open the Service Accounts page .
Select the project that your API was created in and click Open.
In the Service account name field, enter the name for your service account.
Click Select a role and select Service Management > Service Controller.
Click + Add another role.
Click Select a role and select Cloud Trace > Cloud Trace Agent.
In the right-side panel, for the Key type, use the default type, JSON.
In the dialog, click Close.
This creates the service account and downloads its private key to a JSON file.
Important: You must create the service account in the same project that your API is in.
If you have more than one account, make sure to choose the account that is in the GCP project that the API is in. If you run gcloud auth list, the account that you selected is shown as the active account for the project.
This email address is required in the subsequent commands.
See gcloud iam service-accounts for more information about the commands.
Rename the JSON file that contains the private key for the service account to service-account-creds.json and copy it to $HOME/Downloads/ if it was downloaded to a different directory. This way, the full path name matches the value for the --service_account_key in the following docker run command.
In the following docker run command, replace YOUR_SERVICE_NAME with the name of your service.
The Docker --net="host" option doesn't work on macOS. Instead, you must do explicit port mapping from the host to container replacing --net="host" with --publish 8082:8082. You also need to replace localhost with the special macOS-only DNS name docker.for.mac.localhost. See Use cases and workarounds in the Docker documentation for more information.
The following table describes the Docker options used in the preceding commands. For information about the ESP options used in the example, see ESP startup options.
--detach This Docker option starts the container in detached mode, so it runs in the background.
--net="host" This Docker option indicates that the Docker container uses the same network configuration as the host machine, allowing it to make calls to localhost on the host machine. This option doesn't work to run ESP locally on macOS.
--publish=8082:8082 For macOS when you want to run ESP locally, use this Docker option instead of --net="host" to do explicit port mapping from the host to container.
$HOME/Downloads:/esp This Docker option maps your local $HOME/Downloads directory to the /esp directory in the container. This mapping is used by the --service_account_key ESP option.
This section describes how to deploy ESP to a Kubernetes cluster that isn't on GCP.
To have your API managed by Endpoints, deploy the ESP container to the same Kubernetes pod as your API container. The set of pods running ESP and your API are grouped under a Kubernetes service by using a label selector, such as app: my-api. The Kubernetes service specifies the access policy to load balance the client requests to the proxy port.
Rename the JSON file that contains the private key for the service account to service-account-creds.json and copy it to $HOME/Downloads/ if it was downloaded to a different directory. This way, the full path name matches the command in the next step.
Run the following command to create a Kubernetes secret and mount the secret as a Kubernetes volume.
In your Kubernetes configuration file, add the following, replacing YOUR_APP_NAME with the name of your API and YOUR_SERVICE_NAME with the name of your service.
For information about the ESP options used in the example, see ESP startup options.
Deploy ESP to Kubernetes. Replace YOUR_CONFIGURATION_FILE with the name of your Kubernetes configuration file.
The following examples send requests to the sample API. If you aren't using the sample API, we recommend that you run similar tests.
Create an API key on the API credentials page.
If you want to clean up the deployed service configuration, see Deleting an API and API instances.