Beruflich Dokumente
Kultur Dokumente
Get Started »
Learn more: stackato.com/refcard
207
Cloud Foundry
Get More Refcardz! Visit Refcardz.com
» Supported Technologies
CON T EN T S » Your First Cloud Foundry App
» Advanced Usage
» Deploying Cloud Foundry
» Getting Help By Jeremy Voorhis, Revised and Updated by Billy Tat
» cf CLI Cheat Sheet...and more!
•• Writing apps for and deploying to Cloud Foundry Ruby Ruby, Rack, Rails or Sinatra Ruby source
•• Scaling and managing apps in the cloud If your application uses a language or framework that Cloud
Foundry buildpacks do not support, you can try the following:
•• Finding help within the community
•• Customize an existing buildpack
•• Using the cf Command Line Interface (CLI)
•• Write your own buildpack
Whether you are a cloud veteran, or new to PaaS, this Refcard
will help you build, deploy, and manage applications on •• Use a Cloud Foundry Community Buildpack
Cloud Foundry with ease. •• Use a Heroku Third-Party Buildpack
Services
S u p p o rt e d T e c h n o lo g i e s Services are hosted software that Cloud Foundry users can
provision and bind to their applications. Most of these
Base OS
services are database systems such as MySQL, PostgreSQL,
Cloud Foundry is officially supported on Canonical’s Ubuntu and MongoDB; but RabbitMQ, an AMQP message broker,
10.04 LTS running on X86-64 cores. Applications that are
Enterprise Edition 7
© D Z one , I nc. | dz o ne .c o m
2 Cloud Foundry
© DZo ne, I nc . | dz o ne .c o m
3 Cloud Foundry
Adding a Service Assuming you created the Redis service in the previous section,
Now that you can deploy an app, let’s add a service to make and the redis-cli command is available, you can connect to your
it more useful. To see the list of available services and their service like so:
associated plans, run the following command:
$ GET counter
Let’s create a Redis service named hello-redis using the free 25mb
plan. “88”
Connecting to Your Service Locally Notice that we’ve also added the express, winston and winston-
For development and administration, developers may want express, and errorhandler libraries. Let’s add them to our
to connect to their services within Cloud Foundry from their package.json file so it looks like this:
workstations. You can do this using the service’s credentials and
the appropriate client for the server. The service’s credentials are
available in the service dashboard. The dashboard’s address can
be found by running the cf service command:
$ cf service hello-redis
© DZo ne, I nc . | dz o ne .c o m
4 Cloud Foundry
© DZo ne, I nc . | dz o ne .c o m
5 Cloud Foundry
Using APIs internally has the unfortunate effect that app app.get(‘/’, function(req, rep) {
instances cannot talk directly to each other, and requests will var subscriber = redis.createClient(creds.port, creds.
hostname, {no_ready_check: true});
need to pass through the SSL terminator and load balancer. var publisher = redis.createClient(creds.port, creds.
hostname, {no_ready_check: true});
It is also possible to connect two apps by using a service. By subscriber.auth(creds.password);
connecting two apps to a message queue such as RabbitMQ or publisher.auth(creds.password);
Redis, Cloud Foundry’s service bindings handle the details of
publisher.incr(“rtt:counter”, function(err, counter) {
authentication for you, making your apps’ configuration more subscriber.on(“message”, function(channel, message) {
secure and less fragile. var lat = Date.now() - parseInt(message);
rep.end(“ Latency is “ + lat + “ms”);
Both RabbitMQ and Redis offer pub/sub messaging, which subscriber.unsubscribe(channel);
allows producers to post messages to the service, and consumers subscriber.end();
});
to subscribe to messages that interest them. Using pub/sub subscriber.subscribe(“client:” + counter);
messaging, it is possible to implement the most common publisher.publish(“server:” + counter, Date.now());
messaging patterns. Let’s look at a native request/reply example publisher.end();
});
that measures round trip latency via Redis’s pub/sub API. });
First, create a Redis service and name it redis-rtt. Then create app.listen(process.env.VCAP_APP_PORT);
a standalone (non-web) app with the following code and a
corresponding package.json file. Bind it to your newly created // package.json
// index.js
D e p loy i n g C lo u d F o u n d ry
var vcap_services = process.env.VCAP_SERVICES;
var rediscloud_service = JSON.parse(vcap_services)
[“rediscloud”][0]; BOSH
var creds = rediscloud_service.credentials; Cloud Foundry is a distributed system with dozens of
var redis = require(‘redis’);
interconnected components, so it is non-trivial to deploy. If you
var express = require(‘express’);
var app = express(); want to deploy Cloud Foundry yourself, VMware recommends
BOSH. The top-level construct of BOSH is the release, and the
© DZo ne, I nc . | dz o ne .c o m
6 Cloud Foundry
A BOSH release is a collection of jobs that cooperate to support Push a new app or sync changes to an
cf push APP_NAME
the service described by a release. Each VM created by a BOSH existing app.
deployment will run a single job, which is supervised by Monit. Change or view the instance count,
cf scale APP_NAME disk space limit, and memory limit for
A BOSH job references a collection of packages. A BOSH package
an app.
describes how to download, build, and archive a software package
such as Nginx, the JVM, or NFS, so that it can be delivered onto a cf delete APP_NAME Delete an app.
BOSH deployment as part of a distributed system.
cf rename APP_NAME Rename an app.
You can learn more about BOSH at https://github.com/ NEW_APP_NAME
cloudfoundry/bosh.
cf start APP_NAME Start an app.
BOSH Lite cf stop APP_NAME Stop an app.
If you don’t want or need a full-fledged BOSH-managed
cf restart APP_NAME Restart an app.
deployment, e.g. for development, evaluation, or small
deployments, you can use BOSH Lite. BOSH Lite utilizes Vagrant cf restage APP_NAME Restage an app.
and a Warden BOSH CPI to create an instance of Cloud Foundry on
Terminate the running application
a single virtual machine. Vagrant creates the initial VM and BOSH cf restart-app-
instance at the given index and
deploys each Cloud Foundry component into their own Warden instance APP_NAME
instantiate a new instance of the
container. INDEX
application with the same index.
For more information about BOSH Lite visit https://github.com/
cf events APP_NAME Show recent app events.
cloudfoundry/bosh-lite.
cf files APP_NAME Print out a list of files in a directory or
[PATH] the contents of a specific file.
G e tt i n g H e l p
cf logs APP_NAME Tail or show recent logs for an app.
If you have a problem and you haven’t found the answer in this cf env APP_NAME Show all env variables for an app.
Refcard, you can find help within the Cloud Foundry community.
cf set-env APP_NAME Set an env variable for an app.
Resources ENV_VAR_NAME
•• Official Docs: http://docs.cloudfoundry.org/ ENV_VAR_VALUE
© DZo ne, I nc . | dz o ne .c o m
7 Cloud Foundry
Routes (v2)
cf service SERVICE_ Show service instance info.
INSTANCE cf routes List all routes in the current space.
cf create-service Create a service instance. cf create-route SPACE Create a URL route in a space for later
SERVICE PLAN DOMAIN use.
SERVICE_INSTANCE
Perform a simple check to determine
cf check-route HOST
cf update-service Update a service instance. whether a route currently exists or
DOMAIN
SERVICE_INSTANCE not.
cf delete-service Delete a service instance. cf map-route APP_ Add a URL route to an app.
SERVICE_INSTANCE NAME DOMAIN
cf rename-service Rename a service instance. cf unmap-route APP_ Remove a URL route from an app.
SERVICE_INSTANCE NAME DOMAIN
NEW_SERVICE_
cf delete-route Delete a route.
INSTANCE
DOMAIN
cf bind-service APP_ Bind a service instance to an app.
cf delete-orphaned- Delete all orphaned routes (e.g.: those
NAME SERVICE_
routes that are not mapped to an app).
INSTANCE
cf org ORG Show org info. cf create-user USERNAME Create a new user.
PASSWORD
cf create-org ORG Create an org.
cf delete-user USERNAME Delete a user.
cf delete-org ORG Delete an org.
cf org-users ORG Show org users by role.
cf rename-org ORG NEW_ORG Rename an org.
cf set-org-role USERNAME Assign an org role to a user.
Spaces (v2) ORG ROLE
cf spaces List all spaces in an org. cf unset-org-role USERNAME Remove an org role from a
ORG ROLE user.
cf space SPACE Show space info.
cf space-users ORG SPACE Show space users by role.
cf create-space SPACE Create a space.
cf set-space-role USERNAME Assign a space role to a user.
cf delete-space SPACE Delete a space.
ORG SPACE ROLE
cf rename-space Rename a space.
cf unset-space-role USERNAME Remove a space role from a
SPACE NEW_SPACE
ORG SPACE ROLE user.
Domains (v2)
Org Admin
cf domains List domains in the target org.
cf create-domain ORG Create a domain in an org for later cf quotas List available usage quotas.
DOMAIN use. cf quota QUOTA Show quota info
cf delete-domain Delete a domain. cf set-quota ORG QUOTA Assign a quota to an org.
DOMAIN
cf create-quota QUOTA Define a new resource quota.
cf create-shared- Create a domain that can be used by
cf delete-quota QUOTA Delete a quota.
domain DOMAIN all orgs (admin-only).
© DZo ne, I nc . | dz o ne .c o m
8 Cloud Foundry
cf set-space-quota SPACE_ Assign a space quota cf bind-security-group Bind a security group to a space.
NAME SPACE_QUOTA_NAME definition to a space. SECURITY_GROUP ORG
SPACE
cf unset-space-quota SPACE Unassign a quota from a
QUOTA space. cf unbind-security-group Unbind a security group from
SECURITY_GROUP ORG a space.
Service Admin SPACE
cf service-auth-tokens List service auth tokens. Bind a security group to the list
cf bind-staging-security-
of security groups to be used for
cf create-service-auth- Create a service auth token. group SECURITY_GROUP
staging applications.
token LABEL PROVIDER
TOKEN List security groups in the
cf staging-security-groups
staging set for applications.
cf update-service-auth- Update a service auth token.
token LABEL PROVIDER Unbind a security group from
cf unbind-staging-security-
TOKEN the set of security groups for
group SECURITY_GROUP
staging applications.
cf delete-service-auth- Delete a service auth token.
token LABEL PROVIDER Bind a security group to the list
cf bind-running-security-
of security groups to be used for
cf service-brokers List service brokers. group SECURITY_GROUP
running applications.
cf create-service-broker Create a service broker.
List security groups in the set
SERVICE_BROKER
cf running-security-groups of security groups for running
USERNAME PASSWORD URL
applications.
cf update-service-broker Update a service broker.
cf unbind-running- Unbind a security group from
SERVICE_BROKER
security-group SECURITY_ the set of security groups for
USERNAME PASSWORD URL
GROUP running applications.
cf delete-service-broker Delete a service broker.
SERVICE_BROKER
Environment Variable Groups
cf rename-service-broker Rename a service broker.
SERVICE_BROKER NEW_ Retrieve the contents of the
cf running-environment-
SERVICE_BROKER running environment variable
variable-group
group.
cf migrate-service- Migrate service instances from
instances v1_SERVICE one service plan to another. Retrieve the contents of the
cf staging-environment-
v1_PROVIDER v1_PLAN staging environment variable
variable-group
v2_SERVICE v2_PLAN group.
Retrieve list of feature flags cf add-plugin-repo [REPO_ Add a new plugin repository.
cf feature-flags with status of each flag-able NAME] [URL]
feature.
cf remove-plugin-repo Remove a plugin repository.
cf feature-flag FEATURE_ Retrieve an individual feature [REPO_NAME] [URL]
NAME flag with status.
List all the added plugin
cf list-plugin-repos
Enable the use of a feature so repositories.
cf enable-feature-flag
that users have access to and
FEATURE_NAME List all available plugins in all
can use the feature. cf repo-plugins
added repositories.
Disable the use of a feature so
cf disable-feature-flag
that users do not have access to
FEATURE_NAME Add/Remove Plugin
and cannot use the feature.
List all available plugin
Advanced cf plugins
commands.
Executes a raw request, cf install-plugin URL or Install the plugin defined in
cf curl PATH content-type set to application/ LOCAL_PATH/TO/PLUGIN command argument.
json by default.
cf uninstall-plugin PLUGIN- Uninstall the plugin defined in
Write default values to the NAME command argument.
cf config [OPTIONS]
config.
DZone, Inc.
150 Preston Executive Dr.
Cary, NC 27513
DZone communities deliver over 6 million pages each month to more than 3.3 million software 888.678.0399
developers, architects and decision makers. DZone offers something for everyone, including news, 919.678.0300
tutorials, cheat sheets, research guides, feature articles, source code and more.
Refcardz Feedback Welcome
"DZone is a developer's dream," says PC Magazine. refcardz@dzone.com
© DZo ne, ©I nc
form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. |
Copyright © 2015 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
DZone, dz oSponsorship
ne .c o m Opportunities
. in anyInc.
sales@dzone.com Version 1.0 $7.95