Cloud Foundry – PCF Dev on MacBook & Sample App Deployment

1. Brief Introduction – PCF Dev

pivotalcloudfoundry-logo-horizontal-onlight

PCF Dev is a new distribution of Cloud Foundry designed to run on a developer’s laptop or workstation. PCF Dev gives application developers the full Cloud Foundry experience in a lightweight, easy to install package. PCF Dev is intended for application developers who wish to develop and debug their application locally on a full-featured Cloud Foundry. PCF Dev is also an excellent getting started environment for developers interested in learning and exploring Cloud Foundry.

Official website: https://pivotal.io/pcf-dev

2. Installation Steps

Environment

  • Operating System: macOS Sierra
  • Processor: 4 GHz Intel Core i7
  • Memory: 32 GB 1600 MHz DDR3
  • Storage: 256 GB SSD

Prerequisite Tools

Install Cloud Foundry Command Line Interface through Homebrew

PCF Dev uses the Cloud Foundry Command Line Interface (CF CLI) to push and scale apps.

$ brew tap cloudfoundry/tap
$ brew install cf-cli
$ cf help
cf version 6.23.0+c7866be18-2016-12-22, Cloud Foundry command line tool
Usage: cf [global options] command [arguments...] [command options]

Before getting started:
 config login,l target,t
 help,h logout,lo

Application lifecycle:
 apps,a logs set-env,se
 push,p ssh create-app-manifest
 start,st app
 stop,sp env,e
 restart,rs scale
 restage,rg events

Services integration:
 marketplace,m create-user-provided-service,cups
 services,s update-user-provided-service,uups
 create-service,cs create-service-key,csk
 update-service delete-service-key,dsk
 delete-service,ds service-keys,sk
 service service-key
 bind-service,bs bind-route-service,brs
 unbind-service,us unbind-route-service,urs

Route and domain management:
 routes,r delete-route create-domain
 domains map-route
 create-route unmap-route

Space management:
 spaces create-space set-space-role
 space-users delete-space unset-space-role

Org management:
 orgs,o set-org-role
 org-users unset-org-role

CLI plugin management:
 plugins add-plugin-repo repo-plugins
 install-plugin list-plugin-repos

Commands offered by installed plugins:

Global options:
 --help, -h Show help
 -v Print API request diagnostics to stdout

'cf help -a' lists all commands with short descriptions. See 'cf help ' to read about a specific command.

Install PCF Dev

  • Download the latest version of PCF Dev CLI plugin from Pivotal Network.
  • Unzip downloaded zip file and install the PCF Dev Plugin
  • Download and start CF Dev virtual machine
$ unzip pcfdev-v0.23.0+PCF1.9.0-osx.zip && ./pcfdev-v0.23.0+PCF1.9.0-osx
Archive: pcfdev-v0.23.0+PCF1.9.0-osx.zip
 inflating: pcfdev-v0.23.0+PCF1.9.0-osx
Plugin successfully installed. Current version: 0.23.0. For more info run: cf dev help
$ cf dev start
Please sign in with your Pivotal Network account.
Need an account? Join Pivotal Network: https://network.pivotal.io

Email> xxxxxxx@gmail.com

Password>
Downloading VM...
Progress: |====================>| 100%
VM downloaded.
Allocating 4096 MB out of 32768 MB total system memory (15023 MB free).
Importing VM...
Starting VM...
Provisioning VM...
Waiting for services to start...
...
is now running.
To begin using PCF Dev, please run:
 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

Log into PCF Dev

PCF Dev provides two roles:

  • Admin user => Email: admin / Password: admin
  • Regular user => Email: user / Password: pass

Here we log in as a regular user

QiJuns-iMac:spring-music Qi$ cf login -a https://api.local.pcfdev.io --skip-ssl-validation
API endpoint: https://api.local.pcfdev.io

Email> user

Password>
Authenticating...
OK

Targeted org pcfdev-org

Targeted space pcfdev-space

API endpoint: https://api.local.pcfdev.io (API version: 2.65.0)
User: user
Org: pcfdev-org
Space: pcfdev-space

3. Deploy a sample app

Spring Music is a sample application for using database services on Cloud Foundry with the Spring Framework and Spring Boot.

Download  the source code and use Gradle to assemble the app locally

$ git clone https://github.com/cloudfoundry-samples/spring-music
Cloning into 'spring-music'...
remote: Counting objects: 1021, done.
remote: Total 1021 (delta 0), reused 0 (delta 0), pack-reused 1021
Receiving objects: 100% (1021/1021), 692.39 KiB | 0 bytes/s, done.
Resolving deltas: 100% (358/358), done.
$ cd ./spring-music
$ ./gradlew assemble
BUILD SUCCESSFUL

Total time: 35.779 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.14/userguide/gradle_daemon.html

Push the app

$ cf push --hostname spring-music
Using manifest file /Users/JuneAzure/Documents/Azure/Workspace/Cloud Foundry/spring-music/manifest.yml

Creating app spring-music in org pcfdev-org / space pcfdev-space as user...
OK

Creating route spring-music.local.pcfdev.io...
OK

Binding spring-music.local.pcfdev.io to spring-music...
OK

Uploading spring-music...
Uploading app files from: /var/folders/fm/qy7ft97x0gb0mbrwcyt6jz3m0000gn/T/unzipped-app179295168
Uploading 30.2M, 203 files
Done uploading
OK

Starting app spring-music in org pcfdev-org / space pcfdev-space as user...
...
Staging complete
Uploading droplet, build artifacts cache...
Uploading build artifacts cache...
Uploading droplet...
Uploaded build artifacts cache (109B)
Uploaded droplet (75.2M)
Uploading complete
Destroying container
Successfully destroyed container

0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running

App started

OK

App spring-music was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.2_RELEASE -memorySizes=metaspace:64m..,stack:228k.. -memoryWeights=heap:65,metaspace:10,native:15,stack:10 -memoryInitials=heap:100%,metaspace:100% -stackThreads=300 -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/. org.springframework.boot.loader.JarLauncher`

Showing health and status for app spring-music in org pcfdev-org / space pcfdev-space as user...
OK
...
   state   since                  cpu  memory       disk           details
#0 running 2016-12-30 09:58:39 PM 0.0% 469.6M of 1G 155.8M of 512M

View the app in browser

In the output above we can find that the URL of the deployed sample app is
http://spring-music.local.pcfdev.io

Screen Shot 2016-12-30 at 10.08.46 PM.png

4. Connect to a MySQL Database

If a database isn’t available, the sample app uses a temporary in-memory database. This app supports MySQL, Postgres, Redis, and MongoDB.

You can see what type of database this app is using by clicking the info icon in the upper right corner of your app.

screen-shot-2016-12-30-at-10-32-24-pm

Now let’s check what services are available in PCF Dev

$ cf marketplace
Getting services from marketplace in org pcfdev-org / space pcfdev-space as user...
OK

service         plans              description
local-volume    free-local-disk    Local service docs: https://github.com/cloudfoundry-incubator/local-volume-release/
p-mysql         512mb, 1gb         MySQL databases on demand
p-rabbitmq      standard           RabbitMQ is a robust and scalable high-performance multi-protocol messaging broker.
p-redis         shared-vm          Redis service to provide a key-value store

TIP: Use 'cf marketplace -s SERVICE' to view descriptions of individual plans of a given service.

Create a MySQL service instance with 512MB plan

$ cf create-service p-mysql 512mb my-spring-db
Creating service instance my-spring-db in org pcfdev-org / space pcfdev-space as user...
OK

Bind the newly created service to the sample app

$ cf bind-service spring-music my-spring-db
Binding service my-spring-db to app spring-music in org pcfdev-org / space pcfdev-space as user...
OK
TIP: Use 'cf restage spring-music' to ensure your env variable changes take effect

Once a service is bound to an app, environment variables are stored that allow the app to connect to the service after a push, restage, or restart command.

Restart the app and verify the new service is bind to the app

This can be done either through command line or web page

$ cf restart spring-music 
$ cf services
Getting services in org pcfdev-org / space pcfdev-space as user...
OK

name         service plan  bound apps   last operation
my-spring-db p-mysql 512mb spring-music create succeeded

screen-shot-2016-12-30-at-10-34-29-pm

5. Scale the app

$ cf scale spring-music --help
NAME:
 scale - Change or view the instance count, disk space limit, and memory limit for an app

USAGE:
 cf scale APP_NAME [-i INSTANCES] [-k DISK] [-m MEMORY] [-f]

OPTIONS:
 -f Force restart of app without prompt
 -i Number of instances
 -k Disk limit (e.g. 256M, 1024M, 1G)
 -m Memory limit (e.g. 256M, 1024M, 1G)

SEE ALSO:
 push

Horizontal scaling

Increase the number of app instances from one to two

$ cf scale spring-music -i 2
Scaling app spring-music in org pcfdev-org / space pcfdev-space as user...
OK
QiJuns-iMac:spring-music Qi$ cf app spring-music
Showing health and status for app spring-music in org pcfdev-org / space pcfdev-space as user...
OK
...
   state   since                  cpu  memory       disk           details
#0 running 2016-12-30 10:33:03 PM 0.6% 461.4M of 1G 155.8M of 512M
#1 running 2016-12-30 10:48:47 PM 0.0% 206M of 1G   155.8M of 512M

Vertical scaling

Increase the memory limit for each app instance

$ cf scale spring-music -m 1G

Increase the disk limit for each app instance

$ cf scale spring-music -k 512M
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s