An introduction to PCF and its capabilities
Let's start with a simple NodeJS application.
- Download the
cf cli
from https://github.com/cloudfoundry/cli#downloads - Make sure cli is properly install by running
cf version
- Login to the environment:
CF_API_URL=<provided by instructor>
cf login -a $CF_API_URL
- Select the org and space that matches your team as provided by the instructor.
- Clone the NodeJS application from the following URL: https://github.com/odedia/cf-sample-app-nodejs
- Review the
package.json
file. - Review the
manifest.yml
file. - Push your application to the Pivotal Cloud Foundry by running
cf push
.
The apps manager is a great place to view information about your application, but everything can also be done from the command line or through REST api calls.
- Run
cf app cf-nodejs
to see an overview about your application - Run
cf scale -i 2 cf-nodejs
to scale your application to two instances. - Run
cf logs --recent cf-nodejs
to view the latest aggregated logs from all instances of your application. - Run
cf logs cf-nodejs
to get a constant stream of the current logs from your application. Refresh the app on a browser and see the results in the logs. Notice how some logs are emitted from the platform, such as [RTR/0]. - Run
cf restart cf-nodejs
to perform a simple restart of the node process in each container. - Run
cf restage cf-nodejs
to perform a full container rebuild from the last push. - Run
cf events cf-nodejs
to view the latest events that occured in your application. - Sometimes it makes sense to see exactly what goes on inside a container. Run
cf ssh cf-nodejs
to ssh into one of the running containers of your application. Remember, all containers are stateless and created from the same image, so they are all pretty much the same. Explore the contents of theapp
directory.exit
the container when done. - The
cf cli
is extensible. View the available extensions by runningcf repo-plugins
. - Install the
top
cf plugin by runningcf install-plugin top
. - Run
cf top
to view a unix-liketop
of the orgs you can work on. - You can review all available commands by running
cf help
.
- Download the python example from https://github.com/odedia/python-cf-example
- Review the manifest.yml
- Push your app with
cf push
. - Check the app in Apps Manager. What has changed from the previous deployment?
- Clone the .NET Framework application from https://github.com/odedia/pcf-dotnet-environment-viewer.
- Inspect the code. This is a standard .NET Framework application.
- Under the ViewEnvironment directory, create a manifest.yml with the following data (replace :
---
applications:
- name: dotnet-app
host: dotnet-<Your Name>
memory: 1024m
stack: windows2016
buildpack: hwc_buildpack
cf push
the app.- View the application in your browser. Inspect the app in Apps Manager.
- Run
cf ssh dotnet-app
. You are now inside the Windows container. You can see the code under theapp
diretory.
- Inspect the options in the marketplace from the UI. Each service has a few plans available as defined by the operator.
- Run
cf marketplace
from the command line. You should see the same services. - Create a MySQL service from the command line:
cf create-service p.mysql db-small mysql
. - Run
cf service mysql
to monitor the progress of the service creation. The platform now creates a virtual machine at the BOSH layer to host your database. - Bind the application to your dotnet-app:
cf bind-service mysql dotnet-app
. - Restage your application:
cf restage dotnet-app
- Inspect the app in Apps Manager. Under services, you will see the bounded service.
- Inspect the running application. You will now see an "Attendees" section in the UI. You can restart the app and the data will remain.