Skip to content

Latest commit

 

History

History

lab08

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Lab 8: Deploying to PCF

  1. 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

Push the App

  1. In a terminal, change working directory to cn-workshop/labs/lab08/spring-music

    $ cd <cn-workshop>/labs/lab08/spring-music
  2. 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.

  3. 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
  4. 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.

    Note
    The route will be used throughout the rest of the demo. In this example it is spring-music-unassuageable-pilule.

Scale the App Vertically

  1. Reduce the available memory for the app to 1GB

    $ cf scale spring-music -m 1G

    When prompted to restart the app respond yes

Scale the App Horizontally

  1. Increase the number of instances of the app to 2

    $ cf scale spring-music -i 2

    When prompted to restart the app respond yes

  2. 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
  3. Decrease the number of instances of the app to 1

    $ cf scale spring-music -i 1

Deploy a New Version of the App

  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.

  2. 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.

Do a Blue/Green Deployment

  1. 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

  2. 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

  3. 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.

  4. 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

  5. Remove the temporary route

    $ cf unmap-route spring-music-new <host> -n <application-route>-temp
  6. Remove the original version of the app

    $ cf delete spring-music

    When prompted to restart the app respond yes

  7. Rename the new version of the app to the original name

    $ cf rename spring-music-new spring-music
  8. 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

Bind Services to the App

  1. 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
  2. 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
  3. 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

  4. 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

  5. Restage the Application so the new service is detected

    $ cf restage spring-music
  6. 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.