Taxonomy Icon

Cloud

Cloud Foundry is the industry-standard open source cloud application platform for developing and deploying enterprise cloud applications, and if you use the Cloud Foundry command-line interface (CLI) you can install plugins that can increase your productivity by allowing you to:

  • Develop cloud apps locally
  • Show live statistics of your Cloud Foundry distribution
  • Save time normally required to copy and paste cloud app URLs
  • Display app user information
  • Display a list of the issues that currently exist in your cloud environment

Although cf CLI is a powerful tool all by itself, plugins can make a developer’s job even easier … You can also write your own plugins that can be hosted internally or added to the CF community.

In this article, I’ll demonstrate how to use these Cloud Foundry plugins to perform the tasks listed above:

  • PCF Dev, a distribution of Cloud Foundry designed to run on a developer’s laptop or workstation
  • top, an interactive interface that shows top statistics similar to the UNIX top command
  • Open, for opening app URLs in the browser
  • whoami, which shows you the name of the currently logged in user
  • doctor, which scans your deployed applications, routes, and services for anomalies and reports any issues

You can find many other plugins at Cloud Foundry Community cf CLI Plugins or create your own, all without having any vendor lock-in issues.

Before we begin by installing the CLI, let’s take a quick look at the Cloud Foundry platform.

About Cloud Foundry

Cloud Foundry—which is language- and infrastructure-agnostic—automates, scales, and manages a cloud app throughout its lifecycle. You can develop applications in almost any language and use any cloud provider you choose.

The project started in 2009 and became open source in 2015 with the creation of the Cloud Foundry Foundation. Cloud Foundry supports Ruby, Java, Python, PHP, Golang, and Node; this covers most major languages and frameworks, which is one of the reasons it is so popular with developers. Since Cloud Foundry is open source and can be deployed on multiple cloud platforms like AWS, Azure, and even OpenStack, this avoids the vendor lock-in issue that scares off many developers and startups.

Developers also have an option to deploy applications on managed Cloud Foundry solutions and certified platforms like IBM Cloud, Atos Cloud Foundry, Pivotal Cloud Foundry, SAP Cloud Platform, Huawei FusionStage, and Swisscom Application Cloud. Some alternatives to Cloud Foundry are Heroku, OpenShift, and Google App Engine.

If you are absolutely new to Cloud Foundry, see the Resources listed at the right for tutorials on how to get started and use the platform.

Next, I’ll explain how to install the CLI.

CLI, one key to productivity

The Cloud Foundry CLI is the certified command-line client that enables developers to interact with the platform and its services. It is maintained by the Cloud Foundry Foundation.

You can download and install Cloud Foundry CLI on Linux, Mac OSX, and Windows platforms.

Although Cloud Foundry has a nice management dashboard, nothing beats the command line when it comes to productivity and automation. Many of the most serious users prefer the CLI over GUI applications.

Installing the CLI

You will need to install the Cloud Foundry CLI to be able to use the plugins, so go ahead and hook it up. The easiest way is via the package manager:


#For Mac OSX
$ brew install cloudfoundry/tap/cf‑cli

#For Ubuntu and other Debian‑based distros

$ wget ‑q ‑O ‑ 
https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo
apt‑key add ‑
$ echo "deb http://packages.cloudfoundry.org/debian stable main" | sudo
tee /etc/apt/sources.list.d/cloudfoundry‑cli.list
#...then, update your local package index, then finally install the cf
CLI
$ sudo apt‑get update
$ sudo apt‑get install cf‑cli

#For Fedora and other RedHat based systems

#Configure the Cloud Foundry Foundation package repository
sudo wget ‑O /etc/yum.repos.d/cloudfoundry‑cli.repo
https://packages.cloudfoundry.org/fedora/cloudfoundry‑cli.repo
#...then, install the cf CLI (which will also download and add the
public key to your system)
sudo yum install cf‑cli

You can also download binaries for your operating system.

Plugins, the stars of the show

The Cloud Foundry Command Line Interface (cf CLI) includes plugin functionality that enables developers to add custom commands to cf CLI.

Now I’ll detail the plugins—how to install and use them.

PCF Dev

PCF Dev is a small-footprint distribution that’s provided by the Pivotal team and designed to run inside a single virtual machine on your local machine, giving you the full Cloud Foundry experience and a full-featured development environment in an easy-to-install package.

In other words, it allows you to develop your cloud apps locally. PCF Dev is also a good way to evaluate and learn Cloud Foundry.

For all practical purposes, PCF Dev behaves like a plugin. For example, to uninstall it you use the command cf uninstall-plugin pcfdev.

To run PCF Dev, you must have at least 4GB of memory and 20GB of free disk space on your machine. All of the examples in this article work fine with PCF Dev.

Install the plugin

Download the plugin binary for your OS:

  • GitHub allows you to build an open source version of PCF Dev that only contains the Elastic Runtime and the CF MySQL Broker.
  • Pivotal Network allows you to build a version that contains other PCF components such as Redis and RabbitMQ.

For the full version, you might have to login before you can download the plugin.

Once you have the plugin .zip file, extract it in a folder and execute the binary file that it contains. I have downloaded the Mac OSX version of the plugin, but of course you should download the version that corresponds to your operating system.


kn330@local‑osx $ ls
pcfdev‑v0.26.0+PCF1.10.0‑osx.zip

kn330@local‑osx $ unzip pcfdev‑v0.26.0+PCF1.10.0‑osx.zip
Archive:  pcfdev‑v0.26.0+PCF1.10.0‑osx.zip
inflating: pcfdev‑v0.26.0+PCF1.10.0‑osx

kn330@local‑osx $ ./pcfdev‑v0.26.0+PCF1.10.0‑osx
Plugin successfully upgraded. Current version: 0.26.0. For more info
run: cf dev help

If the plugin is successfully installed, you will see the success message as the output.

If you are using Linux, then you might not have the unzip utility pre-installed. You can download and install it by using the following command:


$ sudo apt‑get install unzip

Using the plugin

PCF Dev is the easiest way to spin up a local distribution on Cloud Foundry, and you can do that with the cf dev start command:

cf dev start
Downloading VM...
Progress: |====================>| 100%
VM downloaded
Importing VM...
Starting VM...
Provisioning VM...
Waiting for services to start...
40 out of 40 running
_______  _______  _______    ______   _______  __   __
|       ||       ||       |  |      | |       ||  | |  |
|    _  ||       ||    ___|  |  _    ||    ___||  |_|  |
|   |_| ||       ||   |___   | | |   ||   |___ |       |
|    ___||      _||    ___|  | |_|   ||    ___||       |
|   |    |     |_ |   |      |       ||   |___  |     |
|___|    |_______||___|      |______| |_______|  |___|

is now running.
To begin using PCF Dev, please run:
cf login ‑a https://api.local.pcfdev.io ‑‑skip‑ssl‑validation
Admin user => Email: admin / Password: admin
Regular user => Email: user / Password: pass

It may take several minutes for the PCF Dev machines and services to start.

The output also echoes the credentials that can be used to login to Cloud Foundry Dev.

You can verify the status of your development environment with the cf dev status command:

kn330@local-osx $ cf dev status
Running
CLI Login: cf login -a https://api.local.pcfdev.io --skip-ssl-validation
Apps Manager URL: https://local.pcfdev.io
Admin user => Email: admin / Password: admin
Regular user => Email: user / Password: pass

Now run a demo application on your local Cloud Foundry environment.

First, clone the demo spring-music app, which is written in Java™ on the Spring Framework.

kn330@local-osx $ git clone https://github.com/cloudfoundry-
samples/spring-music

Assemble the app using gradle:

kn330@local-osx $ cd ./spring-music
kn330@local-osx $ ./gradlew assemble

Login to PCF Dev with username admin and password admin:

kn330@local-osx $ cf login -a api.local.pcfdev.io --skip-ssl-validation
API endpoint: api.local.pcfdev.io
...
API endpoint:   https://api.local.pcfdev.io (API version: 2.75.0)
User:           admin
Org:            pcfdev-org
Space:          pcfdev-space

Push the application:

kn330@local-osx $ cf push --hostname spring-music
Using manifest file /../spring-music/manifest.yml
...
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running
...
requested state: started
instances: 1/1
usage: 1G x 1 instances
urls: spring-music.local.pcfdev.io

You can verify the deployed application by visiting the URL http://spring-music.local.pcfdev.io with your browser.

The admin panel for the local PCF Dev environment is accessible on http://apps.local.pcf.dev. If you are visiting for the first time, you must also run the command cf dev trust. You have to do this because the admin dashboard runs on https and PCF Dev uses a self-signed certificate that needs to be added to your local machine’s trusted keychain.

To get more information about PCF Dev, type cf dev help.

top

The top plugin is an interactive Cloud Foundry CLI tool that displays live statistics about your Cloud Foundry distribution, including application and route metrics, system resource utilization per application, and other important values. Think of top as a Cloud Foundry alternative to the Linux top command. The primary source of information that the top plugin typically uses is by monitoring the Cloud Foundry Firehose plugin.

top runs in either privileged or non-privileged mode depending on what permissions have been granted to the user.

Install the top plugin

You can easily install the plugin as follows:

kn330@local-osx $ cf install-plugin -r CF-Community "top"

Using the top plugin

To start using the plugin, you just enter the following:

kn330@local-osx $ cf top

As you can see in Figure 1, the spring-music application that was deployed on the PCF Dev environment is showing up along with two other system applications.

Figure 1. Cloud Foundry live statistics using the top plugin
Cloud Foundry live statistics using the top plugin

The system applications are visible because we are logged in as the admin. To get more information on an application, select the application with arrow keys and press Enter.

Figure 2. Getting app details using the top plugin
Getting app details using the top plugin

Open

This one is one of my favorite plugins because it saves me a lot of time normally required to copy and paste the application URLs. Once you have this plugin installed, you can open any application by using the command cf open app-name.

Install the Open plugin

kn330@local-osx $ cf install-plugin -r CF-Community "Open"
Searching CF-Community for plugin Open...
Plugin Open 1.1.0 found in: CF-Community
7.63 MiB / 7.63 MiB [===================================] 100.00% 6s
Plugin open 1.1.0 successfully installed.

Using the Open plugin

This will open the spring-music application in the browser.

cf open spring-music

whoami

The whoami plugin does exactly what its name implies—it displays information about the user. This plugin can be very handy if you have multiple Cloud Foundry distributions and have to keep switching between them.

Install the whoami plugin

kn330@local-osx $ cf install-plugin -r CF-Community "whoami-plugin"
Searching CF-Community for plugin whoami-plugin...
Plugin whoami-plugin 0.2.0 found in: CF-Community
9.22 MiB / 9.22 MiB [===========================================]
100.00% 7s
Plugin Whoami Plugin 0.2.0 successfully installed.

Using the whoami plugin

kn330@local-osx $ cf whoami
You are logged in as admin at https://api.local.pcfdev.io
You are targeting the pcfdev-space space in the pcfdev-org org

doctor

The doctor plugin is inspired by brew doctor and will show you a list of issues that currently exist in your environment. Homebrew is an open source package manager for Mac OS X. If you are an Ubuntu user, then brew doctor is similar to the command apt-get -f install.

Install the doctor plugin

kn330@local-osx $ cf install-plugin -r CF-Community "doctor"

Using the doctor plugin

Imagine that you have a dangling route that has no application associated with it:

kn330@local-osx $ cf doctor
doctor: time to triage cloudfoundry

Following routes do not have any app bound to them:
Host: springer2 <--->  Domain: local.pcfdev.io

Total Number of Apps: 1
Total Number of Running Apps: 1

To fix this issue, you can delete the route with the following command:

kn330@local-osx $ cf delete-route local.pcfdev.io --hostname springer2

Really delete the route springer2.local.pcfdev.io?> y
Deleting route springer2.local.pcfdev.io...

Now if you run cf doctor again, everything should be OK.

kn330@local-osx $ cf doctor

doctor: time to triage cloudfoundry

doctor: Everything looks OK!

Conclusion

Although cf CLI is a powerful tool all by itself, plugins can make a developer’s job even easier. Other community plugins provide the capabilities to:

  • Obtain a heap- or thread-dump
  • Shift between CF environments with a single command
  • Inspect, dump, and restore your MySQL database
  • Manage application network policies
  • Copy apps and services to another CF target
  • Sync a local folder to a remote one to make changes on the fly
  • Show which apps are using an installed buildpack
  • Run the same command on all the apps in a space, org, or globally

The list goes on and on.

You can also write your own plugins that can be hosted internally or added to the CF community.

Don’t fall behind other programmers in the cloud appdev productivity race. Start using plugins with Cloud Foundry today!