---
name: databases-for-mongodb-connecting-ibmcloud-app
title: Connecting an IBM Cloud application
description: Applications running in IBM Cloud can be bound to your IBM Cloud&reg; Databases for MongoDB deployment.
last-updated: 2024-09-16
---

> ## Documentation Index
> The table of contents for this documentation set is at https://cloud.ibm.com/docs/databases-for-mongodb?format=markdown
> The index for all IBM Cloud docs is at: https://cloud.ibm.com/docs/llms.txt
> Use these files to discover more information as needed.

# Connecting an IBM Cloud application
{: #mongodb-connecting-ibmcloud-app}

Applications running in IBM Cloud can be bound to your IBM Cloud&reg; Databases for MongoDB deployment. 

## Connecting a Kubernetes Service application
{: #mongodb-connecting-kubernetes-app}

There are two steps to connecting a Cloud databases deployment to a Kubernetes Service application. First, your deployment needs a to be bound to your cluster and its connection strings stored in a secret. The second step is configuring your application to use the connection strings.

The sample app in the [Connecting a Kubernetes Service Tutorial](https://cloud.ibm.com/docs/databases-for-mongodb?topic=databases-for-mongodb-tutorial-k8s-app&format=markdown) provides a sample application that uses Node.js and demonstrates how to bind the sample application to a Cloud Databases deployment.
{: .tip}

Before connecting your Kubernetes Service application to a deployment, make sure that the deployment and cluster are both in the same region and resource group.

### Binding your deployment
{: #mongodb-binding-deployment}

1. **Public or private endpoints**

  - **Public endpoints** - If you are using the default public service endpoint to connect to your deployment, you can run the `cluster service bind` command with your cluster name, the resource group, and your instance name or CRN.

    ```sh
    ibmcloud ks cluster service bind <YOUR_CLUSTER_NAME> <RESOURCE_GROUP> <INSTANCE_NAME_OR_CRN>
    ```
  - **Private endpoints** - If you want to use a private endpoint (if one is enabled on your deployment), then first you need to create a service key for your database. Kubernetes uses it when binding to the database.

    ```sh
    ibmcloud resource service-key-create <YOUR-PRIVATE-KEY> --instance-name <INSTANCE_NAME_OR_CRN> --service-endpoint private  
    ```
    The private service endpoint is selected with `--service-endpoint private`. After that, you bind the database to the Kubernetes cluster through the private endpoint with the `cluster service bind` command.

    ```sh
    ibmcloud ks cluster service bind <YOUR_CLUSTER_NAME> <RESOURCE_GROUP> <INSTANCE_NAME_OR_CRN> --key <YOUR-PRIVATE-KEY>
    ```

2. **Verify** - Verify that the Kubernetes secret was created in your cluster namespace. Running the following command, you get the API key for accessing the instance of your deployment in your account.

    ```sh
    kubectl get secrets --namespace=default
    ```
    More information on binding services is found in the [Kubernetes Service documentation](https://cloud.ibm.com/docs/containers?topic=containers-service-binding&format=markdown#bind-services).

### Configuring in your Kubernetes app 
{: #mongodb-configuring-kubernetes-app}

When you bind your application to Kubernetes Service, it creates an environment variable from the cluster's secrets. Your deployment's connection information lives in `BINDING` as a JSON object. Load and parse the JSON object into your application to retrieve the information your application's driver needs to make a connection to the database. 

The [Getting connection strings](https://cloud.ibm.com/docs/databases-for-mongodb?topic=databases-for-mongodb-connection-strings&format=markdown#connection-string-breakdown) page contains a reference of the JSON fields.

For more information, see the [Kubernetes Service documentation](https://cloud.ibm.com/docs/containers?topic=containers-service-binding&format=markdown#reference_secret).