Pivotal CF Commands - ashwin-shetty/Documents-Wiki GitHub Wiki

Contents

  1. Basic Commands
  2. Log Commands
  3. Scaling Application
  4. Services
  5. Blue Green Deployment
  6. Miscellaneous
  7. Space and Org

1. Basic Commands

1. Command to push application and run it at once

cf push appName 

2. Command to push application without starting it

cf push appName -p ./app-0.01.snapshot.jar -m 512M --random-route --no-start 
push is used deploy application
-p is path of application
--random-route to specify route automatically
--no-start Not to start application by default

3. Command to Start Application

 cf start appName

4. Restart Application

cf restart appName

5. Get info about Application

 cf app appName

6. Audit Trail of Application

 cf events appName 
Note : It will give application History regarding health of Application and other events

2. Log Commands

1. Check logs

 cf logs  appName

2. Grep particular word in log

 cf logs appName | grep "API\Cell"

3. Scaling Application

1. Scaling Application Vertically

 cf  scale appName -m 1G
Note : Earlier Container is destroyed and new container with 1 GB is created. For MB -m 512M

2. Scaling Application Horizontally

 cf scale appName articulate  -i   3 
  Note : here 3 instance is created  without downtime they can be differentiated with Container Address and Cell    Address. 

4. Services

Cloud Foundry has multiple built-in services which we can find in market place and also user can define his own service and use in application. Built-in services like mysql database, redis server and many more are found in market place. In below command we use mysql database service and use in our application

1. Getting or Provisioning MySQL Database

cf create-service p-mysql 100mb-dev attendee-mysql
 Note : p-mysql is service name, 100mb-dev is plan name, attendee-mysql is user defined database name

2. Binding Services to Application

 cf bind-service attendee-service attendee-mysql
 Note : bind-service is command, attendee-service is application Name, attendee-mysql is the service which is binding (MySQL database in this case) . If service is not working then run cf restage appName Command  or  cf restart

5. Blue Green Deployment

Application should be running in two or more instance to use blue green deployment.

  • Assume we have two version of a application appName and appName-v2
  • Using cf push we deploy first version of application(appName)
  • We need to scale application horizontally for two or more instance
  • We deploy new version of the application with different route name and then test application
  • After testing is complete use map-route command to route newer version to production domain. After executing command we see warning message saying route already exist as older version is also running

    cf map-route appName-v2 hostname -n subdomain.ashwin-shetty.com

  • Scale down older version and Scale up the new version of the application
  • Now unmap the older version of the application so that only one version is running in production

    cf unmap-route appName hostname -n subdomain.ashwin-shetty.com

6. Miscellaneous

1. Get Environment variables set for the applications

 cf env attendee-service
Note  : attendee-service is application name

2. Creating user provided Services

 i.  cf create-user-provided-service attendee-service -p uri
Then url> http://attendee-service.pivotal.io
Note : create-user-provided-service is the command, attendee-service is the service name 
In url give the application url from cf-apps 
ii.  cf  bind-service appName attendee-service
iii. cf restart appName

3. Creating manifest

cf create-app-manifest attendee-service -p ./manifest.yml
It will create the file. You can look at the content by using command
 cat manifest.yml 

4. To check security level of the space

 cf security-groups

5. Application Autoscaler, Performance Monitor, and Metrics: Application AutoscalerTo Give Security info based on group name

cf security-groups all_open

6. Application Autoscaler, Performance Monitor, and Metrics: Application Autoscaler

cf m -s Service -> will give details of the specific service

7. Buildpacks and Service Brokers: Buildpack

    cf push -b -> used to deploy application with build pack specified
cf buildpacks -> get list of build packs

7. Space and Org

Commands Related to Space and Org

1. Command used to get information endpoint,user,org and space

   cf t

2. Command to get details of all applications running

   cf apps

3. Search a Command

cf | grep manifest
Note : It will search all commands starting with manifest

4. Getting details of available built-in Services in Market Place

 cf m