Skip to content

Files

Latest commit

85778f8 · Apr 14, 2022

History

History
154 lines (101 loc) · 7.48 KB

cloudfoundry-deploy-your-first-app.md

File metadata and controls

154 lines (101 loc) · 7.48 KB

title: Deploy your first app to Cloud Foundry on Microsoft Azure description: Deploy an application to Cloud Foundry on Azure author: seanmck ms.service: virtual-machines ms.subservice: workloads ms.topic: article ms.date: 06/14/2017 ms.author: seanmck

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:

Important

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 https://system.*ip-address*.cf.pcfazure.com.

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 skip-ssl-validation switch.

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.

Note

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

Let's use a sample Cloud Foundry application called Hello Spring Cloud, which is written in Java and based on the Spring Framework and Spring Boot.

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 push command:

cf push

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.

Output from cf push command

To see the hello-spring-cloud application, open the provided URL in your browser:

Default UI for Hello Spring Cloud

Note

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 recent switch:

cf logs --recent hello-spring-cloud

Scale the application

By default, 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 scale command:

cf scale -i 2 hello-spring-cloud

Running the 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.

Next steps