-
If you haven’t already, download this git repo and unpack it someplace convenient.
Lab08 starter project is located here:
cn-workshop: ├── labs │ ├── lab08 │ │ ├── spring-music
This directory contains two prebuilt versions of the spring-music app from https://github.com/cloudfoundry-samples/spring-music
-
In a terminal, change working directory to cn-workshop/labs/lab08/spring-music
$ cd <cn-workshop>/labs/lab08/spring-music
-
Take a look at the manifest to see how PCF will deploy the app
manifest.yml--- applications: - name: spring-music memory: 2G random-route: true path: spring-music-blue.jar buildpack: https://github.com/cloudfoundry/java-buildpack.git
This manifest will create an application named spring-music with 2GB of available memory
The compiled code in the spring-music-blue.jar located in this directory will be used for the application.
The application will use the java-buildpack from git as the runtime.
-
Push the application to PCF
$ cf push
This will push the app with a random route which will be displayed in the console output.
requested state: started instances: 1/1 usage: 2G x 1 instances urls: spring-music-unassuageable-pilule.bosh-lite.com last uploaded: Tue May 9 15:29:34 UTC 2017 stack: cflinuxfs2 buildpack: https://github.com/cloudfoundry/java-buildpack.git
-
Verify the application is running by browsing to the url
In this example it is spring-music-unassuageable-pilule.bosh-lite.com
The banner at the top should be blue.
NoteThe route will be used throughout the rest of the demo. In this example it is spring-music-unassuageable-pilule.
-
Reduce the available memory for the app to 1GB
$ cf scale spring-music -m 1G
When prompted to restart the app respond yes
-
Increase the number of instances of the app to 2
$ cf scale spring-music -i 2
When prompted to restart the app respond yes
-
Verify there are two running instances
$ cf apps Getting apps in org yolo / space development as admin... OK name requested state instances memory disk urls spring-music started 2/2 1G 1G spring-music-unassuageable-pilule.bosh-lite.com
-
Decrease the number of instances of the app to 1
$ cf scale spring-music -i 1
-
Push the green version of the app
$ cf push -f manifest-green.yml -n <application-route>-temp
The -n specifies the route to use for the new app. Use the route from earlier with -temp appended.
In this example the route is spring-music-unassuageable-pilule-temp
The -f specifies the manifest for deployment.
manifest-green.yml--- applications: - name: spring-music-new memory: 1G path: spring-music-green.jar buildpack: https://github.com/cloudfoundry/java-buildpack.git
This manifest will create an application named spring-music-new with 1GB of available memory
The compiled code in the spring-music-green.jar located in this directory will be used for the application.
-
Verify the application is running by browsing to the url
In this example it is spring-music-unassuageable-pilule-temp.bosh-lite.com
The banner at the top should be green.
-
Map the original route to the new app
$ cf map-route spring-music-new <host> -n <application-route>
In this example the host is bosh-lite.com and the application-route is spring-music-unassuageable-pilule
The route is now load balancing between the two version of the application
-
Verify the route points to both versions of the app
$ cf apps Getting apps in org yolo / space development as admin... OK name requested state instances memory disk urls spring-music started 1/1 1G 1G spring-music-unassuageable-pilule.bosh-lite.com spring-music-new started 1/1 1G 1G spring-music-unassuageable-pilule.bosh-lite.com, spring-music-unassuageable-pilule-temp.bosh-lite.com
Hard refresh the application a few times in a browser and it will change from blue to green
-
Unmap the route to the original application
$ cf unmap-route spring-music <host> -n <application-route>
In this example the host is bosh-lite.com and the application-route is spring-music-unassuageable-pilule
The route is only pointing to the new application now.
-
Verify the route only points to the new version of the application
$ cf apps Getting apps in org yolo / space development as admin... OK name requested state instances memory disk urls spring-music started 1/1 1G 1G spring-music-new started 1/1 1G 1G spring-music-unassuageable-pilule.bosh-lite.com, spring-music-unassuageable-pilule-temp.bosh-lite.com
Refresh the application in a browser and it will only be green now
-
Remove the temporary route
$ cf unmap-route spring-music-new <host> -n <application-route>-temp
-
Remove the original version of the app
$ cf delete spring-music
When prompted to restart the app respond yes
-
Rename the new version of the app to the original name
$ cf rename spring-music-new spring-music
-
Verify the new version of the app is named spring-music
$ cf apps Getting apps in org yolo / space development as admin... OK name requested state instances memory disk urls spring-music started 1/1 1G 1G spring-music-unassuageable-pilule.bosh-lite.com
-
Look at the List of Available Services
$ cf marketplace
$ cf marketplace Getting services from marketplace in org yolo / space development as admin... OK service plans description 3scale free_appdirect, basic_appdirect* API Management Platform app-autoscaler standard Scales bound applications in response to load blazemeter free-tier, basic1kmr*, pro5kmr* Performance Testing Platform cedexisopenmix opx_global*, openmix-gslb-with-fusion-feeds* Openmix Global Cloud and Data Center Load Balancer cedexisradar free-community-edition Free Website and Mobile App Performance Reports cleardb spark, boost*, amp*, shock* Highly available MySQL for your Apps. cloudamqp lemur, tiger*, bunny*, rabbit*, panda* Managed HA RabbitMQ servers in the cloud cloudforge free, standard*, pro* Development Tools In The Cloud elephantsql turtle, panda*, hippo*, elephant* PostgreSQL as a Service
-
Look at the List of Service Plans
cf marketplace -s <servicename>
In this example the servicename is elepantsql
cf marketplace -s elephantsql Getting service plan information for service elephantsql as admin... OK service plan description free or paid turtle 4 concurrent connections, 20MB Storage free panda 20 concurrent connections, 2GB Storage paid hippo 300 concurrent connections, 100 GB Storage paid elephant 300 concurrent connections, 1000 GB Storage, 500Mbps paid
-
Create a Service Instance
$ cf create-service <service> <service-plan> <service-name>
In this example the service is elepantsql the service-plan is turtle and the service-name is my-db
-
Bind the Service Instance to the Application
$ cf bind-service <app-name> <service-name>
In this example the app-name is spring-music the service-name is my-db
-
Restage the Application so the new service is detected
$ cf restage spring-music
-
Verify the Service has been Added to the App
Browse to the application and click the info icon in the top-right. You should see my-sql in the list of services.
Congratulations! You’ve just scaled an application and completed a blue/green deployment, and bound service to an application in PCF.