Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GCP_WORKSHOP_1_GCE

iwagami
December 15, 2017

 GCP_WORKSHOP_1_GCE

* Overview of GCP
* GCE

iwagami

December 15, 2017
Tweet

More Decks by iwagami

Other Decks in Programming

Transcript

  1. Once upon a time, (90s - 2000s) Working with a

    web application, you used to use • Physical servers • Instruction text • Historical shell script • Deploy and pray (aka お祈りデプロイ)
  2. 201x - Now, we have Cloud tech. & Configuration files!!!

    - Dockerfile, Procfile, etc. Doing deploy is only .. - git push - press deploy button - speak to chatbot Eg. Configuration file FROM ruby:2.3 # throw errors if Gemfile has been modified since Gemfile.lock RUN bundle config --global frozen 1 RUN mkdir -p /usr/src/app WORKDIR /usr/src/app ONBUILD COPY Gemfile /usr/src/app/ ONBUILD COPY Gemfile.lock /usr/src/app/ ONBUILD RUN bundle install ONBUILD COPY . /usr/src/app RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/* EXPOSE 3000 CMD ["rails", "server", "-b", "0.0.0.0"]
  3. Schecule • #1 12/2 GCP overview, GCE • #2 12/16

    GCE • #3 1/13? App Engine • #4 1/27? App Engine • #5 2/?? Kurbenetis • Gradually Difficult
  4. IaaS: Infrastructure as a Service • Such as; Amazon EC2,

    Google Compute Engine (GCE) • Rental Infrastructure (server, data store, network) on demand ◦ Similar: virtual machine (VMWare, VirtualBox) • Build and run web application on freehand ◦ No restriction for user web application •
  5. PaaS: Platform as a Service • Such as; ElasticBeans, AppEngine,

    Heroku • Go publish web app by `git push` • Platform takes care of everything about web app ◦ Network, scaling, monitor, logging • Strong restriction ◦ Limited languages, frameworks, networks, version •
  6. mBaaS: Mobile Backend as a Service • Such as; Firebase,

    Parse.com(dead) • For Mobile(iPhone app, Android App) • Datastore, Authentication, Push, ads, ...
  7. FaaS: Function as a Service • Such as; Amazon Lambda,

    Cloud functions • Serverless - ultimate web app • Compose functions to make web app ◦ Charge per-function invocation • Stronger Restriction!! ◦ Languages(JS?), no framework, complete vendor lockin
  8. Orchestration • More and more complicate web application ◦ App

    Servers, Load balancer, Proxy server, Database, 3rd party API calls • Problems; ◦ Hard to manage a configuration or architecture ◦ Hard to set up in local environment • Describe a configuration of web application
  9. Regular Rails App in Cloud Nginx Redis PostgreSQL Compute Engine

    10GB PD 2 1 Compute Engine 10GB PD 1 Compute Engine 10GB PD 4 1 Compute Engine 10GB PD 4 1 Compute Engine 10GB PD 4 1 Rails Cloud Load Balancing Compute Engine 10GB PD 1 Cloud CDN
  10. Docker compose; wordpress version: '3' services: db: image: mysql:5.7 volumes:

    - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress volumes: db_data:
  11. Map; GCP vs AWS 種類 GCP AWS IaaS GCE(G. Contaier

    Engine) EC2 Object Storage Cloud Storage S3 NoSQL DataStore Cloud datastore Dynano DB PaaS AppEngine Elastic Beanstalk SQL server Cloud SQL RDS BigData BigQuery Redshift mBaaS FireBase Amazon Mobile Serverless Cloud functions Amazon Lambda CDN Cloud CDN Cloud Front https://cloud.google.com/free/docs/map-aws-go ogle-cloud-platform?hl=ja
  12. Why GCP • AWS is the biggest player, though •

    GCP is ◦ Cheap ◦ Cutting-edge ◦ Made by Google ◦ For Startups ◦
  13. Adopted by cutting-edge companies • Pokemon Go, Nintendo (AppEngine) •

    メルカリアッテ, Mercali (AppEngine) • Abema TV, Cyberagent (GCE, GKE) • DeNA (AppEngine) •
  14. Horror story; AWS 破産 • GCP has wider free tier

    than AWS but… • Charging point ◦ Instance ◦ Storage ◦ Traffic ◦ API calls •
  15. Set a budget alert • Notice earlier when forget to

    turning off a instance • [〓] → billing → `Budgets & alerts` → `CREATE BUDGET` • Input like this •
  16. Delete VM & Project • VM instances → [DELETE] •

    Delete Project https://console.cloud.google.com/cloud-resource-man ager ◦ Type project id • まめに消すこと
  17. Install Google Cloud SDK • Cloud SDK - Command line

    tool • Open Terminal.app and `brew cask install google-cloud-sdk` • https://cloud.google.com/sdk/gcloud/?hl=ja
  18. Create project by cloud sdk - `gcloud projects create your-project-name`

    - Must be unieque ERROR: (gcloud.projects.create) Project creation failed. The project ID you specified is already in use by another project. Please try an alternative ID. - `gcloud config set project your-project-name`
  19. Create VM - `gcloud compute instances create gaminstance --machine-type f1-micro

    --image-family ubuntu-1710 --image-project ubuntu-os-cloud` - us-west-a https://cloud.google.com/compute/docs/instances/create -start-instance
  20. 演習 Rails • 次のインスタンスを作る ◦ MachineType: n1-standard / OS: Ubuntu

    16.04 / Zone: us-west/ allow-http-access • Ssh でインスタンスにログインする • Ruby をインストール • Rails をインストール • `rails new` • sudo ./bin/rails server -p 80 -b 0.0.0.0
  21. Shell script sudo apt-get update sudo apt-get install autoconf bison

    build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev sudo apt-get install ruby-dev sqlite3 libsqlite3-dev nodejs sudo gem install rails rails new HelloApp cd HelloApp # 元気のある人はDockerfileを作ってください
  22. 次回 • Dockernize • Network • Cost estimation • もうちょっと現実的な構成

    • App Server Compute Engine Autoscaling App Server Compute Engine Autoscaling Cloud Load Balancing