Publicité
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Publicité
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Publicité
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Publicité
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Publicité
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Prochain SlideShare
Serverless Computing with Google CloudServerless Computing with Google Cloud
Chargement dans ... 3
1 sur 22
Publicité

Contenu connexe

Publicité
Publicité

Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run

  1. Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run Wesley Chun - @wescpy Developer Advocate, Google Adjunct CS Faculty, Foothill College Developer Advocate, Google Cloud ● Mission: enable current and future developers everywhere to be successful using Google Cloud and other Google developer tools & APIs ● Focus: GCP serverless (App Engine, Cloud Functions, Cloud Run); higher education, Google Workspace, GCP AI/ML APIs; multi-product use cases ● Content: speak to developers globally; make videos, create code samples, produce codelabs (free, self-paced, hands-on tutorials), publish blog posts About the speaker Previous experience / background ● Software engineer & architect for 20+ years ○ Yahoo!, Sun, HP, Cisco, EMC, Xilinx ○ Original Yahoo!Mail engineer/SWE ● Technical trainer, teacher, instructor ○ Taught Math, Linux, Python since 1983 ○ Private corporate trainer ○ Adjunct CS Faculty at local SV college ● Python community member ○ Popular Core Python series author ○ Python Software Foundation Fellow ● AB (Math/CS) & CMP (Music/Piano), UC Berkeley and MSCS, UC Santa Barbara ● Adjunct Computer Science Faculty, Foothill College (Silicon Valley)
  2. Why & agenda 1 Introduction 2 Google Cloud Serverless review 3 Nebulous, flexible app(s) 4 Deployments 5 Summary ● Cloud computing has taken industry by storm (all?) ● App modernization top priority/key goal at many enterprises ○ Containerize apps, get them on VMs, move to cloud ● Serverless: let users focus on solutions not what they run on ● GCP: 3 (4) different serverless products for different use cases ● Similar yet different from each other, but flexible apps deployable to all ● Help prep next-generation (cloud-ready) workforce 01 Introduction Why are you here?
  3. Serverless: what & why ● What is serverless? ○ Misnomer (a "PMM") :-) ○ "No worries" ○ Developers focus on writing code & solving business problems* ● Why serverless? ○ Fastest growing segment of cloud... per analyst research*: ■ $1.9B (2016) and $4.25B (2018) ⇒ $7.7B (2021) and $14.93B (2023) ○ What if you go viral? Autoscaling: your new best friend ○ What if you don't? Code not running? You're not paying. * in USD; source:Forbes (May 2018), MarketsandMarkets™ & CB Insights (Aug 2018) Serverless with Google Operational Model Programming Model Low infra management Managed security Pay only for usage Service-based monoliths Request + event-driven Open
  4. Google Compute Engine, Google Cloud Storage AWS EC2 & S3; Rackspace; Joyent SaaS Software as a Service PaaS Platform as a Service IaaS Infrastructure as a Service Google Workspace (was G Suite/Google Apps) Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365 Google App Engine, Cloud Functions Heroku, Cloud Foundry, Engine Yard, AWS Lambda Google BigQuery, Cloud SQL, Cloud Datastore, NL, Vision, Pub/Sub AWS Kinesis, RDS; Windows Azure SQL, Docker Serverless: PaaS-y compute/processing Google Apps Script Salesforce1/force.com cloud.google.com/hosting-options#hosting-options Google Cloud compute option spectrum Compute Engine Kubernetes Engine (GKE) Cloud Run on Anthos Cloud Run (fully-mgd) App Engine (Flexible) App Engine (Standard) Cloud Functions
  5. Serverless common use cases App Engine Cloud Run Cloud Functions Web services Web app hosting/custom domains ✓ ✓ HTTP services ✓ ✓ ✓ Container hosting ✓ APIs Web & mobile backends ✓ ✓ Internal APIs and services ✓ ✓ Data processing ✓ ✓ Automation Workflow & orchestration ✓ ✓ Event-driven automation ✓ ✓ Common use cases 02 Google Cloud serverless ...compute platforms review
  6. Google App Engine App-hosting in the cloud Why does App Engine exist? ● Focus on app not DevOps ○ Web app ○ Mobile backend ○ Cloud service ● Enhance productivity ● Deploy globally ● Fully-managed ● Auto-scaling ● Pay-per-use ● Familiar languages ● Test w/local dev server
  7. App Engine to the rescue!! ● Focus on app not DevOps ● Enhance productivity ● Deploy globally ● Fully-managed ● Auto-scaling ● Pay-per-use ● Familiar standard runtimes ● 2nd gen std platforms ○ Python 3.7 ○ Java 8, 11 ○ PHP 7.2 ○ Go 1.11 ○ JS/Node.js 8, 10 ○ Ruby 2.5 Hello World (Python "MVP") app.yaml runtime: python38 main.py from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Hello World!' requirements.txt Flask==1.1.2 Deploy: $ gcloud app deploy Access globally: PROJECT_ID.appspot.com cloud.google.com/appengine/docs/standard/python3/quickstart
  8. Google Cloud Functions Function-hosting in the cloud Why does Cloud Functions exist? ● Don't have entire app? ○ No framework "overhead" (LAMP, MEAN...) ○ Deploy microservices ● Event-driven ○ Triggered via HTTP or background events ■ Pub/Sub, Cloud Storage, Firebase, etc. ○ Auto-scaling & highly-available; pay per use ● Flexible development environment ○ Cmd-line or developer console (in-browser) ○ Develop/test locally with Functions Framework ● Cloud Functions for Firebase ○ Mobile app use-cases ● Available runtimes ○ JS/Node.js 8, 10, 12, 14 ○ Python 3.7, 3.8, 3.9 ○ Go 1.11, 1.13 ○ Java 11 ○ Ruby 2.6, 2.7 ○ .NET Core 3.1
  9. main.py def hello_world(request): return 'Hello World!' Deploy: $ gcloud functions deploy hello --runtime python38 --trigger-http Access globally (curl): $ curl REGION-PROJECT_ID.cloudfunctions.net/hello Access globally (browser): https://REGION-PROJECT_ID.cloudfunctions.net/hello Hello World (Python "MVP") cloud.google.com/functions/docs/quickstart-python
  10. Google Cloud Run Container-hosting in the cloud The rise of containers... ● Any language ● Any library ● Any binary ● Ecosystem of base images ● Industry standard FLEXIBILITY
  11. “We can’t be locked in.” “How can we use existing binaries?” “Why do I have to choose between containers and serverless?” “Can you support language _______ ?” Serverless inaccessible for some... CONVENIENCE Cloud Run: code, build, deploy .js .rb .go .sh .py ... ● Any language, library, binary ○ HTTP port, stateless ● Bundle into container ○ Build w/Docker OR ○ Google Cloud Build ○ Image ⇒ Container Registry ● Deploy to Cloud Run (managed or GKE) ● GitOps: (CI/)CD Push-to-deploy from Git State HTTP
  12. Hello World (Python "MVP") main.py import os from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080))) cloud.google.com/run/docs/quickstarts/build-and-deploy requirements.txt Flask==1.1.2 Hello World (Python "MVP") Dockerfile FROM python:3-slim WORKDIR /app COPY . . RUN pip install -r requirements.txt CMD ["python", "main.py"] .dockerignore Dockerfile README.md *.pyc *.pyo .git/ __pycache__ Build (think docker build and docker push) then deploy (think docker run): $ gcloud builds submit --tag gcr.io/PROJ_ID/IMG_NAME $ gcloud run deploy SVC_NAME --image gcr.io/PROJ_ID/IMG_NAME OR… Build and Deploy (1-line combo of above commands): $ gcloud run deploy SVC_NAME --source . Access globally: SVC_NAME-HASH-REG_ABBR.a.run.app Docker & Dockerfile OPTIONAL!!
  13. ● Build containers easily & securely without creating/managing Dockerfiles ● Open source, open standard; based on CNCF Buildpacks spec v3 ● Used by GCF Functions Framework to deploy locally-developed functions ● Supports most common development tools ○ Go 1.10+ ○ Node.js 10+ ○ Python 3.7+ ○ Java 8 & 11 ○ .NET Core 3.1+ ● Blog posts ○ cloud.google.com/blog/products/containers-kubernetes/google-cloud-now-supports-buildpacks and cloud.google.com/blog/products/serverless/build-and-deploy-an-app-to-cloud-run-with-a-single-command Deploy to Cloud Run with Buildpacks github.com/GoogleCloudPlatform/buildpacks $ ls index.js package.json $ gcloud run deploy myapp --source . $ ls app.py requirements.txt $ gcloud run deploy myapp --source . 03 Nebulous, flexible app(s) Deployable to all platforms
  14. Flexibility in options Cloud Functions App Engine Cloud Run local server Cloud Translation My "Google Translate" MVP github.com/googlecodelabs/cloud -nebulous-serverless-python ● "Nebulous" sample web app ○ Flask/Python app ○ Python 2 & 3 compatible ○ Uses Cloud Translation API ● Deployable to on-prem server ● Also GCP serverless compute ○ App Engine ○ Cloud Functions ○ Cloud Run ● With only config changes ● No changes to app code Nebulous files ● Application files ● Configuration files ● Administrative files ○ Information files ○ Testing - CI/CD files ● Files differ per deployment ● Mainly in configuration ● Application files identical ● Administrative files not part of deployments*
  15. Different nebulous deployments 1. Local (or hosted) Flask server (Python 2) 2. Local (or hosted) Flask server (Python 3) 3. Google App Engine (Python 2) 4. Google App Engine (Python 3) 5. Google Cloud Functions (Python 3) 6. Google Cloud Run (Python 2 via Docker) 7. Google Cloud Run (Python 3 via Docker) 8. Google Cloud Run (Python 3 via Cloud Buildpacks) 04 Deployments & required configuration tweaks
  16. Local (Flask) ● Python 2 or 3 ● Application files ○ main.py and templates/index.html ● Config files ○ requirements.txt (install locally; see below) ○ Service acct pub/prv key-pair & download (credentials.json) ○ Point $GOOGLE_APPLICATION_CREDENTIALS env var to ^^^^ ● Run pip install -U pip -r requirements.txt ● Run python main.py Google App Engine ● Python 2 ● Application files ○ main.py and templates/index.html ● Config files ○ requirements.txt (install locally; see below) ○ app.yaml ○ appengine_config.py ● Run pip install -t lib -r requirements.txt ● Run gcloud app deploy
  17. Google App Engine ● Python 3 ● Application files ○ main.py and templates/index.html ● Config files ○ requirements.txt ○ app.yaml (uncomment runtime: python38) ● Run gcloud app deploy Google Cloud Functions ● Python 3 ● Application files ○ main.py and templates/index.html ● Config files ○ requirements.txt ● Run gcloud functions deploy translate --runtime python37 --trigger-http --allow-unauthenticated
  18. Google Cloud Run (Docker) ● Python 2 ● Application files ○ main.py and templates/index.html ● Config files ○ requirements.txt (uncomment gunicorn) ○ Dockerfile (replace ENTRYPOINT with gunicorn) ● Run gcloud beta run deploy translate --allow-unauthenticated --platform managed --source . Google Cloud Run (Docker) ● Python 3 ● Application files ○ main.py and templates/index.html ● Config files ○ requirements.txt (uncomment gunicorn) ○ Dockerfile (use Py3 base image & gunicorn ENTRYPOINT) ● Run gcloud beta run deploy translate --allow-unauthenticated --platform managed --source .
  19. Google Cloud Run (Cloud Buildpacks) ● Python 3 ● Application files ○ main.py and templates/index.html ● Config files ○ requirements.txt (uncomment gunicorn) ○ Procfile (replace web: with gunicorn) ● Run gcloud beta run deploy translate --allow-unauthenticated --platform managed --source . 05 Summary Resources & conclusion
  20. Possible courses for this sample app ● Software Engineering ● Intro to Cloud Computing ● Machine Learning/AI ● Web application development ● Mobile app (backends) ○ Suggest Cloud Functions for Firebase (vs. GCF) ● Data science/big data ● Business applications Cost of Google Cloud serverless tools ● What is free in Google Cloud overall? ○ Free Trial (credit card required; expires) ■ $300USD credit good for first 90 days ○ Always Free tier (credit card required; no expiration; subject to change) ■ Independent of Free Trial & education grants (more below) ■ Some GCP products free up to usage limits ○ Learn about both programs at cloud.google.com/free ● Serverless Always Free tier (monthly) ○ App Engine (28 [or 9] hours, 1GB storage & 1GB egress) per day ○ Cloud Run (2M reqs, 350k GB-secs, 180k vCPU-secs, 1GB egress) per month ○ Cloud Functions (2M calls, 400k GB-secs, 200k vCPU-secs, 5GB egress) per month ● Higher education (teaching & research) grants ○ cloud.google.com/edu (credit card NOT required; expires) ○ Provides "free" usage for coursework and initial research $$ FREE $$
  21. Session summary ● What's the right tool for the job? ○ GAE, GCF, GCR: they've got different use cases ○ Goal: gain familiarity with all three (learn their differences) ○ They're not as different as you may think! ● One nebulous, flexible sample web app ○ Mini "My Google Translate MVP" featuring Cloud Translation API ○ Deployable to all serverless compute platforms ○ Only requires configuration changes ○ KISS: use default service account credentials ○ github.com/googlecodelabs/cloud-nebulous-serverless-python Other Google APIs & platforms ● Google Workspace (G Suite) (code Gmail, Drive, Docs, Sheets, Slides!) ○ developers.google.com/gsuite ● Firebase (mobile development platform and RT DB plus ML-Kit) ○ firebase.google.com and firebase.google.com/docs/ml-kit ● Google Data Studio (data visualization, dashboards, etc.) ○ datastudio.google.com/overview ○ goo.gle/datastudio-course ● Actions on Google/Assistant/DialogFlow (voice apps) ○ developers.google.com/actions ● YouTube (Data, Analytics, and Livestreaming APIs) ○ developers.google.com/youtube ● Google Maps (Maps, Routes, and Places APIs) ○ developers.google.com/maps ● Flutter (native apps [Android, iOS, web] w/1 code base[!]) ○ flutter.dev
  22. Invite me (or my team) to your campus... it's our job! ● Faculty & grad students ● Researchers ● Undergrads ● University IT staff/CIO/CTO ● University entrepreneurship centers/capstone project leads Thank you! Questions? Wesley Chun @wescpy Progress bars: goo.gl/69EJVw
Publicité