Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
© 2015, 2016 IBM Corporation
Using the Cloud Foundry CLI
© 2015, 2016 IBM Corporation
• How to use the cf Cloud Foundry command-line interface (CLI) to
manage applications
• cf commands to help you do tasks such as:
– Log in to Bluemix
– Push applications
– Scale applications
– Work with domains, routes, organizations, users, roles, and spaces
After you complete this section, you should understand:
2
© 2015, 2016 IBM Corporation
• Download the cf CLI: https://github.com/cloudfoundry/cli/releases
• To install on Windows:
1. Extract the ZIP file.
2. Double-click the cf executable file and follow the prompts to install the CLI.
• To install on MAC OS X or Linux:
1. Open the PKG file.
2. In the installation wizard, follow the prompts to install the CLI.
Installing the Cloud Foundry CLI
3
© 2015, 2016 IBM Corporation
Cloud Foundry CLI: common commands
4
cf l: log in cf ds: delete a service
cf t: target a space or organization cf bs: bind a service to an application
cf a: list apps in the current space cf st: start an app
cf app: display status for specific app in the
current space
cf sp: stop an app
cf p: push (deploy or update) an app cf d: delete an app
cf s: show service information cf scale: scale an app
cf cs: create a service cf logs: tail or show logs for an app
cf help: show help for all commands cf help <command>: show help for a
specific command
cf m: list available marketplace offering cf r: list all routes in the current space
Bluemix uses the Cloud Foundry CLI (cf - ) to interact with Cloud Foundry.
© 2015, 2016 IBM Corporation
• Usagecf login [-a API_URL] [-u USERNAME] [-p PASSWORD] [-o ORG]
[-s SPACE]
• Arguments
– API_URL: This is the URL of the Cloud Controller in your Cloud Foundry instance.
– Username: Your user name, such as your Bluemix ID.
– Password: Your password.
– Org: The organization where you want to deploy your application.
– Space: The space in the organization where you want to deploy your application.
• Examplecf login –a https://api.ng.bluemix.net –u [email protected]
-p XXXX –o [email protected] -s dev
Log in to Bluemix by using the CLI
5
© 2015, 2016 IBM Corporation
• Usagecf push APP [-b URL] [-c COMMAND] [-d DOMAIN] [-i NUM_INSTANCES] [-m MEMORY] [-n HOST] [-p PATH] [-s STACK] [--no-hostname] [--no-route] [--no-start]
• Arguments– -b: Custom buildpack URL, for example, https://github.com/heroku/heroku-
buildpack-play.git or https://github.com/heroku/heroku-buildpack-play.git#stable to select stable branch
– -c: Start command for the application.
– -d: Domain, for example, example.com.
– -f: Replaces --manifest.
– -i: Number of instances of the application to run.
– -m: Memory limit, for example, 256, 1G, 1024M, and so on.
– -n: Host name, for example, my-subdomain.
– -p: Path to application directory or archive.
– -s: Stack to use.
– -t: Timeout to start in seconds, give your application more time to start, up to 180 secs.
– --no-hostname: Map the root domain to this application.
– --no-manifest: Ignore manifests if they exist.
– --no-route: Do not map a route to this application.
– --no-start: Do not start the application after pushing.
• Examplecf push my-app -c “node my-app.js”
Push an application to Bluemix
6
© 2015, 2016 IBM Corporation
• Scaling an application means adjusting the resources required by an application
to improve performance.
• Cloud Foundry provides the cf scale command to scale your application up
or down, horizontally and vertically, to meet workload demand.
• Scaling horizontally
– Cloud Foundry increases or decreases the number of instances of your application to
match INSTANCES.
– cf scale APP -i INSTANCES: Horizontally scale your application.
o Example: cf scale myApp –i 5
• Scale vertically
– Vertically scaling of an application changes the disk space limit or memory limit that
Cloud Foundry applies to all instances of the application.
– cf scale App –k DISK: Change the disk space limit. DISK must be an integer
followed by either an M for megabytes or G for gigabytes.
o Example: cf scale myApp -k 512M
o Example: cf scale myApp -k 1G
Scale your application
7
© 2015, 2016 IBM Corporation
• A user application logging subsystem of Cloud Foundry
• Loggregator allows you to:
– Tail your application logs
– Dump a recent set of application logs (where recent is a configurable
number of log packets)
– Continually drain your application logs to 3rd party log archive and analysis
services
– Operators and administrators only: Access the firehose, which includes the
combined stream of logs from all apps, plus metrics data from CF
components
• Usage
– cf logs APP_NAME [--recent]
Application Loggregator
8
© 2015, 2016 IBM Corporation
• View your organization information:
– cf target: Print the current target organization and space.
– cf org ORGNAME: View your organization information such as domains,
quota, and spaces.
Manage organizations
9
© 2015, 2016 IBM Corporation
• Check what organization and space you are logged into or to change
the space:
– cf target: Print the current target organization and space.
– cf t -s test: Switch to the test space.
Manage spaces
10
© 2015, 2016 IBM Corporation
• List organization users:
– cf org-users ORG: List users in the organization by role.
• Administrator only: manage roles in your organization:
– cf set-org-role USERNAME ORG ROLE: Assign an organization role
to a user. The available roles are OrgManager, BillingManager, and
OrgAuditor.
– cf unset-org-role USERNAME ORG ROLE: Remove an organization
role from a user.
Manage users and roles of an organization
11
© 2015, 2016 IBM Corporation
• List space users:
– cf space-users ORG SPACE: List users in the space by role.
• Administrators only: manage roles in your space:
– cf set-space-role:Assign a space role to a user. The available roles
are SpaceManager, SpaceDeveloper, and SpaceAuditor.
– cf unset-space-role: Remove a space role from a user.
Manage users and roles of a space by using the CLI
12
© 2015, 2016 IBM Corporation
• All domains are mapped to an organization.
• Domains can be shared or private. Shared domains are registered to multiple orgs while
private domains, or owned domains, are registered to one org. A Cloud Foundry instance
defines a default shared domain that your application uses unless you specify a different
domain.
Manage domains
13
• Manage domains:• cf create-domain: Create a domain.
• cf delete-domain: Delete a domain.
• cf domains: List domains in the target organization.
• cf create-shared-domain:Administrator only: share a domain with all organizations.
• cf delete-shared-domain:Administrator only: delete a domain that was shared with all
organizations.
© 2015, 2016 IBM Corporation
• A route is a path used to access an application online. Each route is directly
bound to one or more applications in Cloud Foundry. A route is a URL
composed of a domain and an optional host as a prefix.
– For example, “myappname” is the host and “example.com” is the domain in the route
“myappname.example.com.” Here “example.com” could be a custom domain of your
own or a domain that you created in Cloud Foundry.
• The command cf routes lists all routes in the current space or current
organization and its related space, host, domain, and application name.
• Manage routes:
– cf create-route: Create a route.
– cf map-route: Map a route to an application. If the route does not exist, this
command creates it and then maps it.
– cf unmap-route: Remove a route from an application.
– cf delete-route: Delete a route.
Manage routes
14
© 2015, 2016 IBM Corporation
• IBM Bluemix documentation: “Services”
– https://www.ng.bluemix.net/docs/#services/services.html
• IBM Bluemix documentation: “Bluemix overview”
– https://www.ng.bluemix.net/docs/#overview/overview.html#overview
• IBM Bluemix documentation: “Bluemix concepts: regions”
– https://www.ng.bluemix.net/docs/#overview/overview.html#ov_intro__reg
• Cloud Foundry documentation: “Getting Started with the cf CLI”
– http://docs.cloudfoundry.org/devguide/installcf/whats-new-v6.html
• Cloud Foundry documentation: “Domains, Routes, Organizations, and Spaces”
– http://docs.cloudfoundry.org/devguide/installcf/whats-new-v6.html#domains-etc
• Cloud Foundry documentation: “Identifying the API Endpoint for your Cloud Foundry
Instance”
– http://docs.cloudfoundry.org/running/cf-api-endpoint.html
Related links
15