daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Up and Running with PCF
  2.  
  3. Examples will use a Spring Boot app
  4.  
  5. ## Prerequisities
  6.  
  7. - CF CLI installed
  8. - Some instance of PCF running, or access to PWS
  9. - That which is necessary to write/build/run a Spring Boot application
  10. - Understanding of YAML files and what an application manifest is
  11.  
  12. ## First things first
  13.  
  14. Login:
  15. ```
  16. cf login -a <YOUR_PCF_INSTANCE>
  17. ```
  18. Will require a username/email and a password on first login.
  19.  
  20. List commands:
  21. ```
  22. cf
  23. ```
  24.  
  25. Get help for a command:
  26. ```
  27. cf <COMMAND> --help
  28. ```
  29.  
  30. Target your cf org and space
  31. ```
  32. cf target <org> <space>
  33. ```
  34.  
  35. If you need help finding out your org or space, check out
  36. ```
  37. cf target --help
  38. ```
  39.  
  40. ## CF Push your app
  41. ### Build it
  42. From your repository's root, ensure your app's build is up to date with
  43. ```
  44. ./gradlew clean build
  45. ```
  46. assuming your app has the gradle wrapper configured
  47. ```
  48. gradle clean build
  49. ```
  50. assuming you're relying on a local gradle distribution.
  51.  
  52. If you're using Maven, do the usual.
  53.  
  54. ### Push it
  55. With your cf cli logged in and your org/space target set, from your repository's root run
  56.  
  57. ```
  58. cf push <DESIRED_APP_NAME_IN_CF> -p <PATH_TO_JAR_OR_WAR> --random-route
  59. ```
  60. e.g.
  61. ```
  62. cf push cf-demo-app -p build/libs/cf-demo.jar --random-route
  63. ```
  64.  
  65. CF will determine which buildpack to use based on the application type and will then configure and deploy it based on its defaults for that application type. The `--random-route` flag will assign it a random route to prevent collisions with other, already assigned, routes in that CF instance.
  66.  
  67. The output at the end of the command's run will display its state as 'running', last deployed date/time, cpu usage, memory allocated and in use and most notably the route it has been assigned to/is accessible at.
  68.  
  69. #### Check it out
  70. With your app successfully pushed, you can now get details on all your deployed apps with
  71. ```
  72. cf apps
  73. ```
  74.  
  75. To ge the details of a specific app use
  76. ```
  77. cf app <APP_NAME>
  78. ```
  79.  
  80. You can view the configuration the buildpack assigned to the instance with
  81. ```
  82. cf env <APP_NAME>
  83. ```
  84.  
  85. ### Scale it
  86. If you've decided the buildpack-determined memory, number of instances, etc. is insufficient for your app's needs, you can use
  87. ```
  88. cf scale
  89. ```
  90. To get the list of options available for your <APP_NAME>.
  91.  
  92. To apply a change, such as to scale your app from 1 instance to 2, you would use the following:
  93. ```
  94. cf scale <APP_NAME> -i 2
  95. ```
  96.  
  97. *Note:* Not only will `cf scale` create more instances of your app, it will retain them under the same route assigned initially and load-balance the requests to this app automatically.
  98.  
  99. *Note:* Memory/Disk limit changes will require a restart. Setting the available memory to below the minimum threshold for that app type will likely cause it to crash on restart.
  100.  
  101. ### View the logs
  102. To get the most recent logs for your app and the rest of the cloud foundry system relevant to your app, use
  103. ```
  104. cf logs <APP_NAME> --recent
  105. ```
  106.  
  107. To tail them in real-time, simply use
  108. ```
  109. cf logs <APP_NAME>
  110. ```
  111.  
  112. ### View the events
  113. CF outputs a concise audit trail of "events" for the app deployment lifecycle.
  114.  
  115. To view the events relevant to your app, use
  116. ```
  117. cf events <APP_NAME>
  118. ```
  119.  
  120. ## Provision & Bind Services
  121. ### Find out what's available
  122. While logged into your instance, you can view which services are available for provisioning via the CF Marketplace using
  123. ```
  124. cf marketplace
  125. ```
  126. or
  127. ```
  128. cf m
  129. ```
  130. This will show you the services available to you, the plans available for those services and more.
  131.  
  132. For specific details on a given service, use
  133. ```
  134. cf marketplace -s <SERVICE_NAME>
  135. ```
  136. e.g.
  137. ```
  138. cf marketplace -s p-mysql
  139. ```
  140. On my instance would return something similar to
  141. ```
  142. cf m -s p-mysql
  143. Getting service plan information for service p-mysql as <your-user>...
  144. OK
  145.  
  146. service plan   description           free or paid
  147. 100mb          Shared MySQL Server   free
  148. 1gb            Shared MySQL Server   free
  149. 20gb           Shared MySQL Server   free
  150. ```
  151.  
  152. ### Mysql DB example
  153. Let's provision a Mysql DB.
  154. To view the options available for the Mysql DB service use
  155. ```
  156. cf create-service p-mysql --help
  157. ```
  158.  
  159. For `cf create-service` we must adhere to the following format
  160. ```
  161. cf create-service SERVICE PLAN SERVICE_INSTANCE [-c PARAMETERS_AS_JSON] [-t TAGS]
  162. ```
  163.  
  164. For our Mysql DB, we'll then use the following
  165. ```
  166. cf create-service p-mysql 100mb demo-db-service
  167. ```
  168.  
  169. On success, the output should read as follows
  170. ```
  171. Creating service instance demo-db-service in org your-org / space your-space as your-user...
  172. OK
  173. ```
  174.  
  175. ### View your provisioned services
  176. ```
  177. cf services
  178. ```
  179. will display the services provisioned, the plan it was provisioned on and any apps (by name) bound to that service.
  180.  
  181. ### Bind your service to your app
  182. With the service provisioned, you can now use `cf bind-service` to bind your provisioned service to the app(s) of your choice
  183.  
  184. e.g.
  185. ```
  186. cf bind-service <APP_NAME> demo-db-service
  187. ```
  188.  
  189. With the service bound to your app, you will either have to `cf restage` the app in order to reflect the new environment variables set by the provisioning/binding actions, or `cf restart`.
  190.  
  191. Restarting the app for environment variable updates is more efficiently than restaging it entirely. On restart, you should be met with output containing the state of your app and its instances.
  192.  
  193. ### View the environment created and bound to your app
  194. To view the details of the Mysql service now bound to your app, you can once again use the command
  195. ```
  196. cf env <APP_NAME>
  197. ```
  198.  
  199. Under `VCAP_SERVICES` you will now be able to see the service `p-mysql` along with the details of the provisioned service, including the hostname, jdbcUrl, db name, username/password, port and more.
  200.  
  201. ## Application Manifests
  202. ### Create a manifest.yml from a provisioned application
  203.  
  204. A command exposed by the CF Cli is `cf create-app-manifest <APP_NAME>` which provides a shortcut for creating a CF manifest for the given application.
  205.  
  206. We can run the command and have the output piped to a file of our choice to create repeatable deployments, distribute via repos and more.
  207.  
  208. ```
  209. cf create-app-manifest <APP_NAME> -p <DESIRED_PATH_TO_OUTPUT_FILE>
  210. ```
  211. e.g.
  212. ```
  213. cf create-app-manifest demo-app -p ./manifest.yml
  214. ```
  215. will produce something similar to
  216. ```
  217. applications:
  218. - name: demo-app
  219.   disk_quota: 1G
  220.   instances: 1
  221.   memory: 1G
  222.   routes:
  223.   - route: demo-app-tea-cups.cfapps.io
  224.   services:
  225.   - demo-db-service
  226.   stack: cflinuxfs2
  227. ```
  228.  
  229. The above contains an almost-complete `manifest.yml` for the application we've deployed. We have to add a `path` field with a path to our built file in order for CF to automatically assign a buildpack to our deployment.
  230.  
  231. ```
  232. applications:
  233. - name: demo-app
  234.   path: ./demo-app.jar
  235.   disk_quota: 1G
  236.   instances: 1
  237.   memory: 1G
  238.   routes:
  239.   - route: demo-app-tea-cups.cfapps.io
  240.   services:
  241.   - demo-db-service
  242.   stack: cflinuxfs2
  243. ```
  244.  
  245. The presence of it in our repo root will enable us to `cf push` without `-p <PATH_TO_BUILT_WAR_OR_JAR>`, maintaining the configuration and services bindings every time without having to manually intervene on the commandline or via setting environment variables and `cf restage`-ing or `cf restart`-ing.
  246.  
  247. We can customize our `manifest.yml` and any changes will be reflected the next time we `cf push` it.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top