Skip to content

Latest commit

 

History

History
213 lines (179 loc) · 9.08 KB

lab.adoc

File metadata and controls

213 lines (179 loc) · 9.08 KB

Lab 3 - Operating your Application

Pivotal Cloudfoundry makes the work of performing operations actions, such as scaling, doing a zero-downtime deploy, and managing application health very easy. In the next two labs we’ll explore Pivotal Cloudfoundry operations.

Scale the Application Up

  1. Now let’s increase the number of running application instances to 3. For this lab you can use the Java, Ruby, or Node.js sample app. In each of the commands below replace workshop with the name of your deployed application:

    $ cf scale -i 3 workshop
    Scaling app workshop in org TELCO / space gammon as [email protected]...
    OK

    In reporting OK, the CLI is letting you know that the additional requested instances have been started, but they are not yet necessarily running.

  2. We can determine how many instances are actually running like this:

    $ cf app workshop
    Showing health and status for app workshop in org TELCO / space gammon as [email protected]...
    OK
    
    requested state: started
    instances: 1/3
    usage: 512M x 3 instances
    urls: workshop.vert.fe.gopivotal.com, workshop-queasier-backup.vert.fe.gopivotal.com
    last uploaded: Fri Aug 7 13:15:14 UTC 2015
    stack: cflinuxfs2
    buildpack: java-buildpack=v3.0-offline-https://github.com/cloudfoundry/java-buildpack.git#3bd15e1 open-jdk-jre=1.8.0_40 spring-auto-reconfiguration=1.7.0_RELEASE tomcat-access-logging-support=2.4.0_RELEASE tomcat-instance=8.0.21 tomcat-lifecycle-support=2.4.0_REL...
    
         state      since                    cpu    memory           disk           details
    #0   running    2015-08-07 11:33:21 AM   0.1%   477.9M of 512M   144.4M of 1G  (1)
    #1   starting   2015-08-07 12:42:56 PM   0.0%   0 of 0           0 of 0  (2)
    #2   starting   2015-08-07 12:42:56 PM   0.0%   0 of 0           0 of 0
    1. This application instance has completed the startup process and is actually able to accept requests.

    2. This application instance is still starting and will not have any requests routed to it.

  3. Eventually all instances will converge to a running state:

    $ cf app workshop
    Showing health and status for app workshop in org TELCO / space gammon as [email protected]...
    OK
    
    requested state: started
    instances: 3/3
    usage: 512M x 3 instances
    urls: workshop.vert.fe.gopivotal.com, workshop-queasier-backup.vert.fe.gopivotal.com
    last uploaded: Fri Aug 7 13:15:14 UTC 2015
    stack: cflinuxfs2
    buildpack: java-buildpack=v3.0-offline-https://github.com/cloudfoundry/java-buildpack.git#3bd15e1 open-jdk-jre=1.8.0_40 spring-auto-reconfiguration=1.7.0_RELEASE tomcat-access-logging-support=2.4.0_RELEASE tomcat-instance=8.0.21 tomcat-lifecycle-support=2.4.0_REL...
    
         state     since                    cpu    memory           disk           details
    #0   running   2015-08-07 11:33:21 AM   0.1%   477.9M of 512M   144.4M of 1G
    #1   running   2015-08-07 12:43:04 PM   0.2%   396.2M of 512M   144.4M of 1G
    #2   running   2015-08-07 12:43:04 PM   0.2%   394.8M of 512M   144.4M of 1G
  4. Revisit the application route in the browser. Refresh several times. You should observe the instance index changing as you do so:

    lab

    The aforementioned (Go)Router is applying a random routing algorithm to all of the application instances assigned to this route. As an instance reaches the running state, its DEA registers that instance in the routing table assigned to its route by sending a message to Cloud Foundry’s message bus. All (Go)Router instances are subscribed to this channel and register the routes independently. This makes for very dynamic and rapid reconfiguration!

Scale the Application Down

  1. We can scale the application instances back down as easily as we scaled them up, using the same command structure:

    $ cf scale -i 1 workshop
    Scaling app workshop in org TELCO / space gammon as [email protected]...
    OK
  2. Check the application status again:

    $ cf app workshop
    Showing health and status for app workshop in org TELCO / space gammon as [email protected]...
    OK
    
    requested state: started
    instances: 1/1
    usage: 512M x 1 instances
    urls: workshop.vert.fe.gopivotal.com, workshop-queasier-backup.vert.fe.gopivotal.com
    last uploaded: Fri Aug 7 13:15:14 UTC 2015
    stack: cflinuxfs2
    buildpack: java-buildpack=v3.0-offline-https://github.com/cloudfoundry/java-buildpack.git#3bd15e1 open-jdk-jre=1.8.0_40 spring-auto-reconfiguration=1.7.0_RELEASE tomcat-access-logging-support=2.4.0_RELEASE tomcat-instance=8.0.21 tomcat-lifecycle-support=2.4.0_REL...
    
         state     since                    cpu    memory           disk           details
    #0   running   2015-08-07 11:33:21 AM   0.1%   477.9M of 512M   144.4M of 1G

    As you can see, we’re back down to only one instance running, and it is in fact the original index 0 that we started with.

  3. Confirm that by again revisiting the route in the browser and checking the instance index:

    lab1

HTTP Routing

There are two ways to discover what routes, or HTTP URLs, are ampped to an application The first is available via the CLI. Just type:

$ cf app workshop
Showing health and status for app workshop in org TELCO / space zwickey as [email protected]...
OK

requested state: started
instances: 3/3
usage: 512M x 3 instances
urls: workshop-leishmanial-preobligation.vert.fe.gopivotal.com
last uploaded: Fri Sep 25 15:07:25 UTC 2015
stack: cflinuxfs2
buildpack: java-buildpack=v3.1.1-offline-https://github.com/cloudfoundry/java-buildpack#7a538fb java-main java-opts open-jdk-like-jre=1.8.0_51 open-jdk-like-memory-calculator=1.1.1_RELEASE spring-auto-reconfiguration=1.7.0_RELEASE

     state     since                    cpu    memory           disk           details
#0   running   2015-09-25 11:11:33 AM   0.1%   411.6M of 512M   151.6M of 1G

and you’ll see the list of routes in the section that says urls.

The second way is via the Apps Manager UI. Click on the Workshop application to view application details. Select the Routes tab to view a list of mapped routes:

lab2
  1. We can easily add an additional route by clicking on + Map a Route and supplying the new hostname:

    lab3
  2. Navigate to the new URL in your browser window. You should see that same application displayed!

    lab4
  3. We can just as easily remove a route by clicking on Unmap on the route you wish to remove.

    lab5

    If you navigate to that URL you’ll receive a HTTP 404 response

    lab6
  4. This is how blue-green deployments are accomplished.

    blue green

Accessing Container Contents

  1. The contents of a deployed application container may be retrieved using the files command within the CLI. If the path supplied to the command represents a folder, the contents of the folder are retreived:

    $ cf files workshop
    Getting files for app workshop in org TELCO / space gammon as [email protected]...
    OK
    
    .bash_logout                              220B
    .bashrc                                   3.6K
    .profile                                  675B
    app/                                         -
    logs/                                        -
    run.pid                                     3B
    staging_info.yml                          1.1K
    tmp/
    
    $ cf files workshop app/    (1)
    Getting files for app workshop in org TELCO / space gammon as [email protected]...
    OK
    
    .java-buildpack/                             -
    .java-buildpack.log                     136.6K
    META-INF/                                    -
    WEB-INF/                                     -
    resources/                                   -                                         -
    1. The actual binaries of the application can be found in the /app folder

  2. We can also retrieve the contents of a file using the same command if the path supplied is a path to a file:

    $ cf files workshop staging_info.yml
    Getting files for app workshop in org TELCO / space gammon as [email protected]...
    OK
    
    ---
    buildpack_path: /var/vcap/data/dea_next/admin_buildpacks/920c5763-8b8e-4ea3-b903-c7b8b78947c5_a300c3fca530dc16345dbd6feb26b13897d05265
    detected_buildpack: java-buildpack=v3.0-offline-https://github.com/cloudfoundry/java-buildpack.git#3bd15e1
      open-jdk-jre=1.8.0_40 spring-auto-reconfiguration=1.7.0_RELEASE tomcat-access-logging-support=2.4.0_RELEASE
      tomcat-instance=8.0.21 tomcat-lifecycle-support=2.4.0_REL...
    start_command: JAVA_HOME=$PWD/.java-buildpack/open_jdk_jre JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR
      -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh -Xmx382293K
      -Xms382293K -XX:MaxMetaspaceSize=64M -XX:MetaspaceSize=64M -Xss995K -Daccess.logging.enabled=false
      -Dhttp.port=$PORT" $PWD/.java-buildpack/tomcat/bin/catalina.sh run
    effective_procfile:
      web: JAVA_HOME=$PWD/.java-buildpack/open_jdk_jre JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR
        -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh -Xmx382293K
        -Xms382293K -XX:MaxMetaspaceSize=64M -XX:MetaspaceSize=64M -Xss995K -Daccess.logging.enabled=false
        -Dhttp.port=$PORT" $PWD/.java-buildpack/tomcat/bin/catalina.sh run