LyonJUG - Combo - Quick Cloud Foundry Intro + Cloud Best Practices

1,520 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,520
On SlideShare
0
From Embeds
0
Number of Embeds
55
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

LyonJUG - Combo - Quick Cloud Foundry Intro + Cloud Best Practices

  1. 1. Introduction to Cloud Foundryfor Spring & Java DevelopersEric BOTTARDDeveloper Advocate@ebottard / ebottard@vmware.com
  2. 2. Eric Bottard Developer Advocate • VMware t@ebottard Äericbottard
  3. 3. Cloud Stack - Classic Pyramid Software as a Service Platform as a Service Infrastructure as a Service
  4. 4. Cloud Foundry – The Open Platform as a Service Target a choice of deployment cloudsProvide a choice of Bind a choice of development application frameworks services github.com/cloudfoundry CONFIDENTIAL
  5. 5. CloudFoundry.COM – Multi-Tenant PaaS Operated byVMware CloudFoundry.COM (beta) Frameworks Services vCenter / vSphere Infrastructure
  6. 6. Micro Cloud FoundryTM – Cloud on a Stick Micro Cloud Foundry Frameworks Services Your Laptop/PC Single VM instance of Cloud Foundry that runs on a developer’s MAC or PC CONFIDENTIAL
  7. 7. CloudFoundry.ORG – Community Open Source Project CloudFoundry.ORG Community Frameworks Contributions Community Services Contributions Your Infrastructure Download Setup Tool Chain & Deploy Behind Code Environment Scripts Firewall Cloud Foundry BOSH Apache2 license CONFIDENTIAL
  8. 8. CloudFoundry.ORG – Community Open Source Project github.com/cloudfoundry§ .NET x 2 § Memcached§ PHP § SQL Server§ JRuby § Neo4j§ Python § CouchDB§ Rails 2.x § VirtualBox§ Clojure § Mono§ Erlang § Rack§ Haskell CONFIDENTIAL
  9. 9. Main Risk: Lock In Welcome to the hotel california Such a lovely place Such a lovely face Plenty of room at the hotel california Any time of year, you can find it here Last thing I remember, I was Running for the door I had to find the passage back To the place I was before ’relax,’ said the night man, We are programmed to receive. You can checkout any time you like, But you can never leave! -the Eagles CONFIDENTIAL
  10. 10. Cloud Foundry - Making Multi-Cloud a Reality Private Cloud Management and Public Cloud Distributions Deployment Operators .COM Bare metal CONFIDENTIAL
  11. 11. Cloud Foundry: Clouds § AppFog.com • community lead for PHP • PaaS for PHP § Joyent • community lead for Node.js § ActiveState • community lead for Python, Perl • Providers of Stackato private PaaS CONFIDENTIAL
  12. 12. Demos
  13. 13. VCAP_*VCAP_APP_HOST = 192.168.1.13VCAP_APP_PORT = 58121VCAP_SERVICES ={ "redis-2.2": [ { "name": "my-redis-service", "label": "redis-2.2", "plan": "free", "tags": [ "key-value", "nosql", "redis-2.2", "redis" ], "credentials": { "hostname": "127.0.0.1", "host": "127.0.0.1", "port": 5000, "password": "ce7b483f-66d1-436d-8aa7-7c33a9ee31ac", "name": "e740add8-24ce-40f5-94ed-8a2623e0be57" } } ], "postgresql-9.0": [...]} 13
  14. 14. Auto-reconfiguration§ Works for Spring, Node, Ruby§ Spring: Uses a BeanFactoryPostProcessor under the hood • adds a jar to your app • modifies web.xml to load the BFPP • also adds correct jdbc driver jar§ Only works if no ambiguity (80% of apps) • One service of a kind CONFIDENTIAL
  15. 15. Production Grade Cloud Foundry Clusters§ 500 – 5,000 VMs cloudfoundry.com§ 40+ unique node types§ 75+ unique software packages§ 75+ unique environments§ 2x/week cf.com updates§ 24x7x365 non-stop operation§ No-downtime deployments§ Reliable, robust, repeatable deployments, updates, capacity adjustments§ Small teams manage many production, staging, stress, qa, dev instancesGoogle style problem è Google style solution CONFIDENTIAL
  16. 16. Cloud Foundry BOSH§ Cloud Foundry BOSH is an open source tool-chain for release engineering, deployment, and lifecycle management of large scale distributed services • Prescriptive way of creating releases and managing systems and services • It is not a collection of shell scripts, not a pile of Perl§ Built to deploy and manage production-class, large scale clusters • Production grade Cloud Foundry clusters: 500+ VMs, 40+ jobs, 75+ packages • Multi-node, multi-tier, complex clusters: e.g., our Gerrit/Jenkins Cluster§ Built for devops usage and scale by a crack team of veterans • A project, not a product: command line interface, YAML, etc. • Continuous improvement, iterative development, rough edgesgithub.com/cloudfoundry/bosh CONFIDENTIAL
  17. 17. Key Takeaways§ PaaS is the application platform for the Cloud era§ Cloud Foundry is the Industry’s Open PaaS • Developer agility • Portability without changes • Open system§ What’s next? • Free Signup: www.cloudfoundry.com (use “cloudtoday” as a promocode) • Get started: docs.cloudfoundry.com/getting-started.html • Learn more on the blog: blog.cloudfoundry.com • Download your Micro Cloud Foundry: my.cloudfoundry.com/micro • Get the source code: www.cloudfoundry.org • Follow us: @cloudfoundry • Watch us: www.youtube.com/cloudfoundry CONFIDENTIAL
  18. 18. Cloud Best PracticesEric BOTTARDDeveloper Advocate@ebottard / ebottard@vmware.com
  19. 19. Eric Bottard Developer Advocate • VMware t@ebottard Äericbottard
  20. 20. Agenda10 DOs & DON’Ts in the CLOUD
  21. 21. DISCLAIMER
  22. 22. CAPTAIN OBVIOUS! t-shirt available at threadless.comDesign by Nathan Stillie and Joshua Kemble
  23. 23. Http Traffic Latency Matters
  24. 24. Where’s the Data Center?
  25. 25. Where’s the Data Center?
  26. 26. LEARNLots of Literature
  27. 27. DIAGNOSEChrome Dev Tools YSlowGoogle PageSpeed
  28. 28. FIX ! Unique (e.g. hash) Paths Far Future Expires Header Minification CSS Sprites CDNSpring ResourceHandler Abstraction WRO4J / RoR Asset Pipeline
  29. 29. FileSystem Just pretend it’s not there
  30. 30. Is your File there? Is it Not?
  31. 31. Is your File there? Is it Not?
  32. 32. IT IS THEREBut...
  33. 33. IT’S EPHEMERAL(disappears on restarts)
  34. 34. IT’S NOT SHARED Either
  35. 35. Use Some PersistentSTORAGE
  36. 36. Use Some Persistent STORAGE• Mongo GridFS
  37. 37. Use Some Persistent STORAGE• Mongo GridFS• Database Blob
  38. 38. Use Some Persistent STORAGE• Mongo GridFS• Database Blob• External Blob Service
  39. 39. StateIt’s Better Not To Have It
  40. 40. Try to beSTATELESS
  41. 41. Try to beSTATELESS• Horizontal Scaling
  42. 42. Try to beSTATELESS• Horizontal Scaling• High Availability
  43. 43. Try to beSTATELESS• Horizontal Scaling• High Availability• Zero Downtime Deploy
  44. 44. The Usual Suspects
  45. 45. The Usual Suspects6’6”6’0”5’6”5’0”4’6”4’0”
  46. 46. The Usual Suspects6’6”6’0”5’6”5’0”4’6”4’0”
  47. 47. The Usual Suspects6’6”6’0”5’6”5’0”4’6”4’0”
  48. 48. The Usual Suspects6’6”6’0”5’6”5’0”4’6”4’0”
  49. 49. The Usual Suspects
  50. 50. IF there is statePUSH TO CLIENT(e.g. Cookie, HTML5 apps)
  51. 51. IF there is state USE CENTRAL SERVICE (e.g. Redis)
  52. 52. IF there is state MAKE IT PER USER + Sticky Sessions
  53. 53. Databases They Have A Right To Evolve Too
  54. 54. vmc tunnel (caldecott)$ vmc tunnel1: foobar-mq2: foobar-pg3: postgresql-handson-cfWhich service instance?> 31: none2: psqlWhich client would you like to start?> 2Opening tunnel on port 10000...
  55. 55. HUMAN.EQUALS(ERROR)(when they simply don’t forget)
  56. 56. YOUR CODE IS VERSIONED* Why isn’t your DB? * It is, right?
  57. 57. DON’T ROLL YOUR OWN! (and beware of clusters)
  58. 58. Don’t Roll your Own! MIGRATIONS
  59. 59. Hotel California Better Stay Out of It
  60. 60. Main Risk: Lock In Welcome to the hotel california Such a lovely place Such a lovely face Plenty of room at the hotel california Any time of year, you can find it here Last thing I remember, I was Running for the door I had to find the passage back To the place I was before ’relax,’ said the night man, We are programmed to receive. You can checkout any time you like, But you can never leave! -the Eagles
  61. 61. Don’t Code to (any) Cloud!
  62. 62. Don’t Code to (any) Cloud!§ Auto-Reconfiguration
  63. 63. Don’t Code to (any) Cloud!§ Auto-Reconfiguration§ For the Last 5% • Insulate your Code • Leverage Frameworks, e.g. Spring Profiles <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"...> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg ref="mongoDbFactory" /> </bean> <beans profile="default"> <mongo:db-factory id="mongoDbFactory" dbname="test" host="127.0.0.1" port="27017" username="foo" password="bar" /> </beans> <beans profile="cloud"> <cloud:mongo-db-factory id="mongoDbFactory" service-name="myBoundServiceName" /> </beans> </beans>
  64. 64. Beware of Data!
  65. 65. Segregation All Environments Were Created Equal
  66. 66. Dev vs. Test vs. Staging vs. Prod
  67. 67. Traditional Cloud Dev ≠ StagingMachines Identical ≠ Prod Manual,Process Automated inconsistent People Dev ≠ Ops Devops
  68. 68. Traditional Cloud Dev ≠ StagingMachines Identical ≠ Prod Manual,Process Automated inconsistent People Dev ≠ Ops Devops
  69. 69. Traditional Cloud Dev ≠ StagingMachines Identical ≠ Prod Manual,Process Automated inconsistent People Dev ≠ Ops Devops
  70. 70. Traditional Cloud Dev ≠ StagingMachines Identical ≠ Prod Manual,Process Automated inconsistent People Dev ≠ Ops Devops
  71. 71. One app, Many deploys Code Build Deployment Config
  72. 72. One app, Many deploys of ONE set les deliverab Code Build Deployment Config
  73. 73. One app, Many deploys of ONE set les deliverab Code Build Deployment Config ploys MANY de
  74. 74. “ Environment Variables [...] unlike custom config files, or other config mechanisms such as Java System Properties, are a language- and OS- agnostic standard The Twelve Factor App, http://www.12factor.net
  75. 75. SOAThis time, it’s for real
  76. 76. Do your current apps look like this? Tomcat .war Browser Apache MySQL
  77. 77. “ SOA is like Adam Sandler’s career: Do one thing, and do it well. Rob Spectre, Developer Evangelism, Twilio
  78. 78. Another way to look at itcut -d" " -f1 < access.log | sort | uniq -c | sort -rn | less
  79. 79. Chances are they will soon look like this.. Tomcat search. warDesktopBrowser TomcatNative users. Node.js Message Bus war MongoMobile Front End e.g. RabbitMQ AppHTML5Mobile App Tomcat orders. war MySQL
  80. 80. Communication
  81. 81. SYNCH vs. ASYNCHe.g. HTTP vs. AMQP
  82. 82. FORMATXML, JSON, PBuffers, Thrift
  83. 83. LOW TECHDatabase + cron
  84. 84. When To Do It?
  85. 85. EARLY ONYAGNI?Slows Progress
  86. 86. NOWWould be a Good Time
  87. 87. LATER ONNow You Need ItHard To Refactor
  88. 88. Spring Integration§ Pipes & Filters Architecture§ Promotes Loose Coupling • Handles the Plumbing for you§ Declarative Model§ Internal & External Messaging
  89. 89. Deploy Do It Early & Do It Often
  90. 90. CONTINUOUS INTEGRATIONAutomatic builds, tests
  91. 91. CONTINUOUS DELIVERY CI + automatic deploy
  92. 92. IT’S OKIf it’s not PROD
  93. 93. Automate!<build> <plugins> <plugin> <groupId>org.cloudfoundry</groupId> <artifactId>maven-cf-plugin</artifactId> <version>1.0.0.M4-SNAPSHOT</version> <configuration> <server>mycloudfoundry-instance</server> <target>http://api.cloudfoundry.com</target> <appname>spring-integration-rocks</appname> <url>spring-int-rocks.cloudfoundry.com</url> ⊕ <memory>1024</memory> <services> <service> <name>mysql-test</name> <vendor>mysql</vendor> </service> <service> <name>mongodb-test</name> <vendor>mongodb</vendor> </service> </services> </configuration> </plugin> </plugins></build>
  94. 94. Scale Your own Way
  95. 95. Every app isDIFFERENT
  96. 96. Every app isDIFFERENT• CPU
  97. 97. Every app isDIFFERENT• CPU• RAM
  98. 98. Every app isDIFFERENT• CPU• RAM• DISK
  99. 99. Every app isDIFFERENT• CPU• RAM• DISK• Bugs
  100. 100. Write your own logic http://www.sxc.hu/photo/1128191
  101. 101. Write your own logicUse system-level metrics http://www.sxc.hu/photo/1128191
  102. 102. Write your own logicUse system-level metrics$vmc stats myappinstance #0 cpu 0.0% of 2 cores memory 191.6M of 512M disk 15.0M of 2G http://www.sxc.hu/photo/1128191
  103. 103. Write your own logicUse system-level metrics$vmc stats myappinstance #0 cpu 0.0% of 2 cores memory 191.6M of 512M disk 15.0M of 2G as well as business-related info http://www.sxc.hu/photo/1128191
  104. 104. Write your own logicUse Inter-process scaling
  105. 105. Write your own logicUse Inter-process scaling$vmc scale myapp --instances 3 --memory 1G
  106. 106. Write your own logicUse Inter-process scaling$vmc scale myapp --instances 3 --memory 1G as well as intra-process (thread pools)
  107. 107. Upgrade With Zero Downtime
  108. 108. Blue/Green Deployment
  109. 109. Blue/Green Deployment$vmc app awesome awesome: running platform: spring on java usage: 512M × 1 instance urls: awesome.cloudfoundry.com services: postgresql-db
  110. 110. Blue/Green Deployment$vmc app awesome awesome: running platform: spring on java usage: 512M × 1 instance urls: awesome.cloudfoundry.com services: postgresql-db Version N Version N Users LB / Proxy
  111. 111. Blue/Green Deployment Version N Version N Users LB / Proxy
  112. 112. Blue/Green Deployment$vmc push --name awesome_v2 --url awesome_secret.cloudfoundry.com Version N Version N Users LB / Proxy
  113. 113. Blue/Green Deployment$vmc push --name awesome_v2 --url awesome_secret.cloudfoundry.com Version N Version N Users LB / Proxy Version N+1 Version N+1
  114. 114. Blue/Green Deployment Version N Version N Users LB / Proxy Version N+1 Version N+1
  115. 115. Blue/Green Deployment$vmc unmpap awesome awesome.cloudfoundry.com$vmc map awesome_v2 awesome.cloudfoundry.com Version N Version N Users LB / Proxy Version N+1 Version N+1
  116. 116. Blue/Green Deployment$vmc unmpap awesome awesome.cloudfoundry.com$vmc map awesome_v2 awesome.cloudfoundry.com Version N Version N Users LB / Proxy Version N+1 Version N+1
  117. 117. Blue/Green Deployment$vmc unmpap awesome awesome.cloudfoundry.com$vmc map awesome_v2 awesome.cloudfoundry.com Version N Version N Users LB / Proxy Version N+1 Version N+1
  118. 118. Variations Canary Release
  119. 119. Variations1.Have some (privileged) population Canary use N+1 Release
  120. 120. Variations1.Have some (privileged) population Canary use N+1 Release 2.then roll out
  121. 121. Variations A|B Testing
  122. 122. Variations1.Have some share of the population try A|B a different version Testing
  123. 123. Variations1.Have some share of the population try A|B a different version Testing2.then decide
  124. 124. What about db changes?
  125. 125. BEFORECode @ Version NPersonidfirstnamelastnameaddress
  126. 126. TRANSITIONCode @ Version N & N+1Person Addressid idfirstname person_idlastname streetaddress zipcode city country
  127. 127. AFTER Code @ Version N+2Person Addressid idfirstname person_idlastname street zipcode city country
  128. 128. MIGRATIONS
  129. 129. Limit your Http Traffic There is no File System Strive for StatelessnessAutomate your DB Migrations Avoid Vendor Lock-in Treat all envs as IdenticalIt’s all about Loose Coupling Use Frequent Deployments Targeted and Custom ScalingUpgrade with Zero Downtime
  130. 130. Thank You Eric Bottard Developer Advocate • VMware t@ebottard Äericbottard ebottard@vmware.com

×