Deploy your first app to Cloud Foundry on Microsoft Azure
Cloud Foundry is a popular open-source application platform available on Microsoft Azure. In this article, we show how to deploy and manage an application on Cloud Foundry in an Azure environment.
Create a Cloud Foundry environment
There are several options for creating a Cloud Foundry environment on Azure:
- Use the Pivotal Cloud Foundry offer in the Azure Marketplace to create a standard environment that includes PCF Ops Manager and the Azure Service Broker. You can find complete instructions for deploying the marketplace offer in the Pivotal documentation.
- Create a customized environment by deploying Pivotal Cloud Foundry manually.
- Deploy the open-source Cloud Foundry packages directly by setting up a BOSH director, a VM that coordinates the deployment of the Cloud Foundry environment.
If you are deploying PCF from the Azure Marketplace, make a note of the SYSTEMDOMAINURL and the admin credentials required to access the Pivotal Apps Manager, both of which are described in the marketplace deployment guide. They are needed to complete this tutorial. For marketplace deployments, the SYSTEMDOMAINURL is in the form
Connect to the Cloud Controller
The Cloud Controller is the primary entry point to a Cloud Foundry environment for deploying and managing applications. The core Cloud Controller API (CCAPI) is a REST API, but it is accessible through various tools. In this case, we interact with it through the Cloud Foundry CLI. You can install the CLI on Linux, macOS, or Windows, but if you'd prefer not to install it at all, it is available pre-installed in the Azure Cloud Shell.
To log in, prepend
api to the SYSTEMDOMAINURL that you obtained from the marketplace deployment. Since the default deployment uses a self-signed certificate, you should also include the
cf login -a https://api.SYSTEMDOMAINURL --skip-ssl-validation
You are prompted to log in to the Cloud Controller. Use the admin account credentials that you acquired from the marketplace deployment steps.
Cloud Foundry provides orgs and spaces as namespaces to isolate the teams and environments within a shared deployment. The PCF marketplace deployment includes the default system org and a set of spaces created to contain the base components, like the autoscaling service and the Azure service broker. For now, choose the system space.
Create an org and space
If you type
cf apps, you see a set of system applications that have been deployed in the system space within the system org.
You should keep the system org reserved for system applications, so create an org and space to house our sample application.
cf create-org myorg cf create-space dev -o myorg
Use the target command to switch to the new org and space:
cf target -o testorg -s dev
Now, when you deploy an application, it is automatically created in the new org and space. To confirm that there are currently no apps in the new org/space, type
cf apps again.
For more information about orgs and spaces and how they can be used for Cloud Foundry role-based access control (Cloud Foundry RBAC), see the Cloud Foundry documentation.
Deploy an application
Clone the Hello Spring Cloud repository
The Hello Spring Cloud sample application is available on GitHub. Clone it to your environment and change into the new directory:
git clone https://github.com/cloudfoundry-samples/hello-spring-cloud cd hello-spring-cloud
Build the application
Build the app using Apache Maven.
mvn clean package
Deploy the application with cf push
You can deploy most applications to Cloud Foundry using the
When you push an application, Cloud Foundry detects the type of application (in this case, a Java app) and identifies its dependencies (in this case, the Spring framework). It then packages everything required to run your code into a standalone container image, known as a droplet. Finally, Cloud Foundry schedules the application on one of the available machines in your environment and creates a URL where you can reach it, which is available in the output of the command.
To see the hello-spring-cloud application, open the provided URL in your browser:
To learn more about what happens during
cf push, see How Applications Are Staged in the Cloud Foundry documentation.
View application logs
You can use the Cloud Foundry CLI to view logs for an application by its name:
cf logs hello-spring-cloud
By default, the logs command uses tail, which shows new logs as they are written. To see new logs appear, refresh the hello-spring-cloud app in the browser.
To view logs that have already been written, add the
cf logs --recent hello-spring-cloud
Scale the application
cf push only creates a single instance of your application. To ensure high availability and enable scale out for higher throughput, you generally want to run more than one instance of your applications. You can easily scale out already deployed applications using the
cf scale -i 2 hello-spring-cloud
cf app command on the application shows that Cloud Foundry is creating another instance of the application. Once the application has started, Cloud Foundry automatically starts load balancing traffic to it.