├── .gitignore ├── images ├── gce01.png ├── gce02.png ├── gce03.png ├── gce04.png ├── gce05.png ├── gce06.png ├── gce07.png ├── gce08.png ├── gpu01.png ├── gpu02.png ├── colab1.png ├── datalab1.png ├── meta01.png ├── meta02.png ├── meta03.png ├── meta04.png ├── meta05.png ├── cm-tutorial01.png ├── cm-tutorial02.png ├── cm-tutorial03.png ├── cm-tutorial04.png ├── cm-tutorial05.png ├── cm-tutorial06.png ├── kubernete-result.png ├── kubernetes-cluster.png ├── kubernetes-connect.png ├── kubernetes-preview.png ├── bigquery-tutorial01.png ├── bigquery-tutorial02.png ├── bigquery-tutorial03.png ├── bigquery-tutorial04.png ├── bigquery-tutorial05.png ├── bigquery-tutorial06.png ├── bigquery-tutorial07.png ├── dataflow-tutorial01.png ├── dataflow-tutorial02.png ├── dataflow-tutorial03.png ├── dataprep-tutorial01.png ├── dataprep-tutorial02.png ├── dataprep-tutorial03.png ├── dataprep-tutorial04.png ├── dataprep-tutorial05.png ├── dataprep-tutorial06.png ├── dataprep-tutorial07.png ├── dataprep-tutorial08.png ├── dataprep-tutorial09.png ├── dataprep-tutorial10.png ├── dataprep-tutorial11.png ├── dataprep-tutorial12.png ├── dataprep-tutorial13.png ├── dataprep-tutorial14.png ├── dataprep-tutorial15.png ├── dataprep-tutorial16.png ├── kubernetes-connect2.png ├── kubernetes-dashboard.png ├── kubernetes-roll-out.png ├── kubernete-architecture.png ├── kubernetes-change-port.png ├── kubernetes-cloud-shell.png ├── kubernetes-cloud-shell-prompt.png ├── kubernetes-container-registry.png ├── kubernetes-compute-enginge-node.png ├── kubernetes-container-registry01.png ├── kubernetes-container-registry02.png ├── kubernetes-dashboard-authentication.png └── kubernetes-container-registry-architecture.png ├── 06-stackdriver-tutorial.md ├── 24-apache-beam-installation.md ├── 21-colab.md ├── README.md ├── 01-quickstart.md ├── 10-bigquery-web-interface-tutorial.md ├── 20-datalab.md ├── 04-ssh-keys-in-metadata.md ├── 11-dataprep-tutorial.md ├── apache_beam └── word_count │ └── wordcount.py ├── 03-create-compute-engine-with-gpu-tutorial.md ├── 25-dataflow-landsat-images-tutorial.md ├── 02-create-compute-engine-tutorial.md ├── 22-cloud-ml-tutorial.md └── 05-kubernetes-tutorial.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Project 3 | .idea 4 | venv 5 | 6 | # Python 7 | *.pyc -------------------------------------------------------------------------------- /images/gce01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/gce01.png -------------------------------------------------------------------------------- /images/gce02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/gce02.png -------------------------------------------------------------------------------- /images/gce03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/gce03.png -------------------------------------------------------------------------------- /images/gce04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/gce04.png -------------------------------------------------------------------------------- /images/gce05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/gce05.png -------------------------------------------------------------------------------- /images/gce06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/gce06.png -------------------------------------------------------------------------------- /images/gce07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/gce07.png -------------------------------------------------------------------------------- /images/gce08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/gce08.png -------------------------------------------------------------------------------- /images/gpu01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/gpu01.png -------------------------------------------------------------------------------- /images/gpu02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/gpu02.png -------------------------------------------------------------------------------- /images/colab1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/colab1.png -------------------------------------------------------------------------------- /images/datalab1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/datalab1.png -------------------------------------------------------------------------------- /images/meta01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/meta01.png -------------------------------------------------------------------------------- /images/meta02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/meta02.png -------------------------------------------------------------------------------- /images/meta03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/meta03.png -------------------------------------------------------------------------------- /images/meta04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/meta04.png -------------------------------------------------------------------------------- /images/meta05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/meta05.png -------------------------------------------------------------------------------- /images/cm-tutorial01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/cm-tutorial01.png -------------------------------------------------------------------------------- /images/cm-tutorial02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/cm-tutorial02.png -------------------------------------------------------------------------------- /images/cm-tutorial03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/cm-tutorial03.png -------------------------------------------------------------------------------- /images/cm-tutorial04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/cm-tutorial04.png -------------------------------------------------------------------------------- /images/cm-tutorial05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/cm-tutorial05.png -------------------------------------------------------------------------------- /images/cm-tutorial06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/cm-tutorial06.png -------------------------------------------------------------------------------- /images/kubernete-result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernete-result.png -------------------------------------------------------------------------------- /images/kubernetes-cluster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-cluster.png -------------------------------------------------------------------------------- /images/kubernetes-connect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-connect.png -------------------------------------------------------------------------------- /images/kubernetes-preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-preview.png -------------------------------------------------------------------------------- /images/bigquery-tutorial01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/bigquery-tutorial01.png -------------------------------------------------------------------------------- /images/bigquery-tutorial02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/bigquery-tutorial02.png -------------------------------------------------------------------------------- /images/bigquery-tutorial03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/bigquery-tutorial03.png -------------------------------------------------------------------------------- /images/bigquery-tutorial04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/bigquery-tutorial04.png -------------------------------------------------------------------------------- /images/bigquery-tutorial05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/bigquery-tutorial05.png -------------------------------------------------------------------------------- /images/bigquery-tutorial06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/bigquery-tutorial06.png -------------------------------------------------------------------------------- /images/bigquery-tutorial07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/bigquery-tutorial07.png -------------------------------------------------------------------------------- /images/dataflow-tutorial01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataflow-tutorial01.png -------------------------------------------------------------------------------- /images/dataflow-tutorial02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataflow-tutorial02.png -------------------------------------------------------------------------------- /images/dataflow-tutorial03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataflow-tutorial03.png -------------------------------------------------------------------------------- /images/dataprep-tutorial01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial01.png -------------------------------------------------------------------------------- /images/dataprep-tutorial02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial02.png -------------------------------------------------------------------------------- /images/dataprep-tutorial03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial03.png -------------------------------------------------------------------------------- /images/dataprep-tutorial04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial04.png -------------------------------------------------------------------------------- /images/dataprep-tutorial05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial05.png -------------------------------------------------------------------------------- /images/dataprep-tutorial06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial06.png -------------------------------------------------------------------------------- /images/dataprep-tutorial07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial07.png -------------------------------------------------------------------------------- /images/dataprep-tutorial08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial08.png -------------------------------------------------------------------------------- /images/dataprep-tutorial09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial09.png -------------------------------------------------------------------------------- /images/dataprep-tutorial10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial10.png -------------------------------------------------------------------------------- /images/dataprep-tutorial11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial11.png -------------------------------------------------------------------------------- /images/dataprep-tutorial12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial12.png -------------------------------------------------------------------------------- /images/dataprep-tutorial13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial13.png -------------------------------------------------------------------------------- /images/dataprep-tutorial14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial14.png -------------------------------------------------------------------------------- /images/dataprep-tutorial15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial15.png -------------------------------------------------------------------------------- /images/dataprep-tutorial16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/dataprep-tutorial16.png -------------------------------------------------------------------------------- /images/kubernetes-connect2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-connect2.png -------------------------------------------------------------------------------- /images/kubernetes-dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-dashboard.png -------------------------------------------------------------------------------- /images/kubernetes-roll-out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-roll-out.png -------------------------------------------------------------------------------- /images/kubernete-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernete-architecture.png -------------------------------------------------------------------------------- /images/kubernetes-change-port.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-change-port.png -------------------------------------------------------------------------------- /images/kubernetes-cloud-shell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-cloud-shell.png -------------------------------------------------------------------------------- /images/kubernetes-cloud-shell-prompt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-cloud-shell-prompt.png -------------------------------------------------------------------------------- /images/kubernetes-container-registry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-container-registry.png -------------------------------------------------------------------------------- /images/kubernetes-compute-enginge-node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-compute-enginge-node.png -------------------------------------------------------------------------------- /images/kubernetes-container-registry01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-container-registry01.png -------------------------------------------------------------------------------- /images/kubernetes-container-registry02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-container-registry02.png -------------------------------------------------------------------------------- /images/kubernetes-dashboard-authentication.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-dashboard-authentication.png -------------------------------------------------------------------------------- /images/kubernetes-container-registry-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndersonJo/google-cloud-platform/master/images/kubernetes-container-registry-architecture.png -------------------------------------------------------------------------------- /06-stackdriver-tutorial.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # Overview 4 | 5 | Stackdriver Monitoring은 클라우드 기반의 애플리케이션의 performance, uptime, health check 등등의 모니터링을 제공합니다. 기본적으로 AWS의 CloudWatch와 유사하다고 볼 수 있습니다. 애플리케이션에는 Nginx, Apache Web Server, Elasticsearch, 등등이 될 수 있으며, Slack, PagerDuty, HipChat, Campfile등등과 연동을 할 수도 있습니다. 6 | 7 | 8 | 9 | # Setup and Requirements 10 | 11 | -------------------------------------------------------------------------------- /24-apache-beam-installation.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # Apache Beam Python SDK 설치 4 | 5 | 일단 가장 중요한 점은 Apache Beam은 Python2.7을 지원하고 있으며, 아직까지는 3.x를 지원하고 있지 않습니다. 6 | 아래의 명령어로 Apache Beam Python SDK를 설치합니다. 7 | 8 | ```bash 9 | sudo pip install --upgrade pip virtualenv setuptools apache-beam 10 | sudo pip install --upgrade apache-beam 11 | ``` 12 | 13 | 14 | Extra requirements도 설치하기 위해서 다음과 같이 합니다. 15 | 16 | * apache-beam[gcp] : Google DataFlow, GCS IO, Datastore IO, BigQuery IO 에 필요 17 | * apache-beam[test] : Unittests 에 필요 18 | 19 | ``` 20 | sudo pip install --upgrade apache-beam[gcp] apache-beam[test] 21 | ``` 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /21-colab.md: -------------------------------------------------------------------------------- 1 | # Google Colaboratory 2 | 3 | Google Colaboratory 를 사용해서 딥러닝 모델을 구현할수 있습니다. 4 | Tesla K80 GPU를 무료로 사용가능하며, Keras, TensorFlow, 그리고 Pytorch 사용이 가능합니다. 5 | 6 | ## Creating New Colab Notebook 7 | 8 | 구글 Colab은 Google Drive에서 사용이 가능합니다. 9 | `새로 만들기` -> `더보기` -> `Colaboratory` 를 누름으로서 생성할수 있습니다. 10 | 11 | > 생성까지 다소 시간이 걸립니다. 그동안에 트와이스 보고 있으면 됩니다. 12 | > `Colaboratory` 버튼이 안보이면 `연결할 앱 더보기`를 눌러서 설치합니다. 13 | 14 | ![Colab1](images/colab1.png) 15 | 16 | 17 | ## Installing Pytorch 18 | 19 | ``` 20 | !pip3 install http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp36-cp36m-linux_x86_64.whl 21 | !pip3 install torchvision 22 | ``` 23 | 24 | 아래의 코드로 잘 되는지 확인해 봅니다. 25 | ``` 26 | import torch 27 | from torch.autograd import Variable 28 | 29 | a = Variable(torch.cuda.FloatTensor([[1, 2, 3], [0, 1, 1], [1, 0, 3]])) 30 | b = Variable(torch.cuda.FloatTensor([[1, 0, 4], [1, 5, 3], [2, 3, 0]])) 31 | %time a.matmul(b) # a @ b 32 | ``` 33 | 34 | ## Installing Keras 35 | 36 | ``` 37 | !pip3 install keras 38 | ``` 39 | 40 | # 전반적인 의견 41 | 42 | Colab은 내부동작은 당연히 빠르다. 43 | 하지만 네트워크의 문제로 체감상은 인터랙티브가 느리게 느껴진다. 44 | 또한 아직 부족한 인터페이스는 실무연구원에게는 매우 답답하게 느껴졌다. 45 | 46 | 따라서 대부분의 작업은 local에서 하고, 실제 학습은 colab에서 하는 것이 좋을 것 같다. 딥러닝의 특성상 hyperparameter optimization이 중요한데 이때 이용하면 효율적으로 일 할 수 있다. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | 해당 repository는 구글 클라우드의 주요 서비스에 대한 간단한 설명과 주요 기능에 대한 튜토리얼을 포함하고 있습니다. 4 | 5 | 6 | # Basic Tutorials 7 | 8 | 1. [Quick Start](01-quickstart.md) : gcloud 설치및 주요 명령어 9 | 10 | ## Compute Engine 11 | 12 | 1. [Create Compute Engine](02-create-compute-engine-tutorial.md) : EC2에 해당하는 가상 머신 생성 방법 13 | 2. [Create Compute Engine with GPU](03-create-compute-engine-with-gpu-tutorial.md) : GPU가 달린 GCE 생성 방법 14 | 3. [SSH Keys in Metadata](04-ssh-keys-in-metadata.md) : SSH접속 방법 15 | 16 | ## Kubernetes 17 | 18 | 1. [Kubernetes Tutorial](05-kubernetes-tutorial.md) : Kubernetes 튜토리얼 19 | 20 | 21 | ## BigQuery 22 | 23 | 1. [BigQuery Web Interface Tutorial](10-bigquery-web-interface-tutorial.md) : 빅쿼리 기초 24 | 25 | ## DataPrep 26 | 27 | 1. [Dataprep Tutorial](11-dataprep-tutorial.md) : Trifacta의 제품으로서 구글에서 서비스하고 있다. 28 | 29 | 30 | ## Data Science / Machine Learning / TensorFlow 31 | 32 | 1. [DataLab](20-datalab.md) : GCP의 Jupyter 33 | 2. [Colab](21-colab.md) : Google Colab 34 | 3. [Cloud Machine Learning Tutorial](22-cloud-ml-tutorial.md) : TensorFlow기반의 Machine Learning 서비스 35 | 36 | ## DataFlow 37 | 38 | 1. [Apache Beam Installation](24-apache-beam-installation.md) : Apache Beam 설치 39 | 2. [DataFlow Landsat Images Tutorial](25-dataflow-landsat-images-tutorial.md) : Landsat 데이터를 이용한 Dataflow 예제 40 | -------------------------------------------------------------------------------- /01-quickstart.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # Cloud SDK 4 | 5 | ## Install SDK 6 | 7 | 설치방식에는 2가지가 있습니다. 8 | Interactive Installer는 사람이 쓰기 편하고, versioned SDK 를 다운로드 받아서 하는 경우는 특정 버젼을 받거나, automation으로 처리할때 사용합니다. 9 | 10 | 1. [Interactive Installer](https://cloud.google.com/sdk/downloads#interactive) 11 | 2. [Download versioned SDK](https://cloud.google.com/sdk/downloads#versioned) 12 | 13 | Interactive Installer를 사용해서 설치하는 방법은 다음과 같이 한다. 14 | 15 | ``` 16 | curl https://sdk.cloud.google.com | bash 17 | exec -l $SHELL 18 | gcloud init 19 | ``` 20 | > Datalab GPU 활용시 다음의 regions으로 설정해줘야 합니다. (현재 Beta버젼이라서 supported regions이 적음. `gcloud init` 할때 설정 하면 됩니다) 21 | > 22 | > - us-east1 23 | > - us-central1 24 | > - asia-east1 25 | > - europe-west1 26 | 27 | # Authentication 28 | 29 | ## 계정 리스트 보기 30 | 31 | ```bash 32 | gcloud auth list 33 | ``` 34 | 35 | ## 설정 파일의 속성 보기 36 | 37 | 38 | ```bash 39 | $ gcloud config list 40 | [core] 41 | account = anderson@exem.ai 42 | disable_usage_reporting = True 43 | 44 | Your active configuration is: [default] 45 | ``` 46 | 47 | ## 설정 파일 정보 그리고 SDK 설정 정보 확인 48 | 49 | ```bash 50 | gcloud info 51 | ``` 52 | 53 | # Projects 54 | 55 | ## 프로젝트 리스트 출력 56 | 57 | ```bash 58 | gcloud projects list 59 | ``` 60 | 61 | ## 프로젝트 생성 62 | 63 | 새로운 프로젝트를 만들려면 다음의 명령어 실행. 64 | Project ID는 6자리 이상이며, 다른 사람이 만든 프로젝트 이름과 겹치면 안된다. 65 | 66 | ```bash 67 | gcloud projects create [project-id] 68 | ``` 69 | 70 | ## 프로젝트 변경 71 | 72 | ```bash 73 | gcloud config set project [project-id] 74 | ``` 75 | 76 | 변경되었는지는 `gcloud info` 또는 `gcloud config list` 로 확인이 가능하다. 77 | 78 | 79 | 80 | # Application 81 | 82 | ## Login 83 | 84 | Application으로서 기본 로그인을 설정하기 위해서는 다음과 같이 합니다. 85 | 자세한 문서는 [여기](https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login)를 참조합니다. 86 | 87 | ``` 88 | gcloud auth application-default login 89 | ``` 90 | 91 | -------------------------------------------------------------------------------- /10-bigquery-web-interface-tutorial.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | BigQuery는 대규모 데이터셋을 SQL query를 통하여 다루도록 도와줍니다. 4 | 5 | 6 | 7 | # Tutorial 8 | 9 | ## Query a public dataset 10 | 11 | BigQuery는 [public dataset](https://cloud.google.com/bigquery/public-data/)을 제공하고 있습니다. 해당 공개된 데이터를 통해서 튜토리얼을 진행할 수 있습니다. 12 | 13 | BigQuery -> Compose Query 를 선택한후 다음과 query를 실행시킵니다. 14 | 15 | ``` 16 | #standardSQL 17 | SELECT 18 | weight_pounds, state, year, gestation_weeks 19 | FROM 20 | `bigquery-public-data.samples.natality` 21 | ORDER BY weight_pounds DESC LIMIT 10; 22 | ``` 23 | 24 | ![Bigquery Result](images/bigquery-tutorial01.png) 25 | 26 | ## 외부 데이터 불러오기 27 | 28 | 먼저 BigQuery에서 데이터셋을 생성합니다. 29 | 데이터셋은 여러개의 테이블을 갖고 있는 것으로서 RDBMS의 DB와 같은 개념입니다. 30 | 31 | ![Create new table](images/bigquery-tutorial02.png) 32 | 33 | Dataset ID는 baby_names로 생성을 합니다. 34 | 35 | ![Create a new dataset](images/bigquery-tutorial03.png) 36 | 37 | 그 다음 Cloud Shell에서 데이터를 다운 받습니다. 38 | 39 | ``` 40 | mkdir names 41 | cd names 42 | wget http://www.ssa.gov/OACT/babynames/names.zip 43 | unzip names.zip 44 | ``` 45 | 46 | Storage -> Create Bucket을 눌러서 데이터를 cloud로 올립니다. 47 | 48 | ![Tutorial 04](images/bigquery-tutorial04.png) 49 | 50 | 이름에는 unique한 이름이 들어가야 합니다. 51 | 52 | ![Create bucket](images/bigquery-tutorial05.png) 53 | 54 | 아래의 명령어를 이용해서 Google Cloud Storage에 데이터를 올립니다. 55 | 56 | ``` 57 | gsutil cp yob1984.txt gs://anderson-data52 58 | ``` 59 | 60 | BigQuery로 돌아와서 Cloud Storage에 올라온 데이터를 BigQuery로 가져옵니다. 61 | 62 | 데이터셋 baby_names에서 + 버튼을 눌러서 테이블을 생성합니다. 63 | 64 | ![Create bucket](images/bigquery-tutorial06.png) 65 | 66 | Preview를 눌러서 대략적인 데이터 내용을 확인할 수 있습니다. 67 | 68 | ![Create bucket](images/bigquery-tutorial07.png) 69 | 70 | 쿼리는 다음과 같이 할 수 있습니다. 71 | 72 | ``` 73 | #standardSQL 74 | SELECT 75 | name, count 76 | FROM 77 | `baby_names.names_1984` 78 | WHERE 79 | gender = 'M' 80 | ORDER BY count DESC LIMIT 5; 81 | ``` 82 | 83 | -------------------------------------------------------------------------------- /20-datalab.md: -------------------------------------------------------------------------------- 1 | # Setting up Cloud Datalab 2 | 3 | ## Before you begin 4 | 5 | 1. Google Cloud Platform 콘솔에서 프로젝트를 생성 또는 선택 6 | 2. 해당 프로젝트의 billing을 설정 7 | 3. `Google Compute Engine` 그리고 `Cloud Source Repository` API 를 enable시킨다 8 | 9 | ## Installation 10 | 11 | 업데이트후 `datalab`을 설치합니다. 12 | 13 | ``` 14 | gcloud components update 15 | gcloud components install datalab 16 | ``` 17 | 18 | 설치후 `gcloud components list` 명령어를 통해 설치 된 components를 확인 할 수 있습니다. 19 | 20 | ## Creating Datalab Instance 21 | 22 | ``` 23 | datalab create [datalab-instance-name] 24 | ``` 25 | 26 | 만약 K80 GPU 를 갖은 Cloud Datalab VM 을 생성하고자 하면 다음과 같이 합니다. 27 | 28 | > Multi GPUs 를 사용할때는 `--accelerator-count [number]` flag를 사용 29 | 30 | ``` 31 | datalab beta create-gpu [datalab-instance-name] 32 | ``` 33 | 34 | 생성까지 조금 시간이 걸리며, 생성완료된후 `localhost:8081` 같은 주소로 접속이 가능합니다. 35 | 36 | ![Datalab1](images/datalab1.png) 37 | 38 | 현재 GPU Datalab 은 Beta라서 다음의 regions만 가능합니다. 39 | 40 | * us-east1 41 | * us-central1 42 | * asia-east1 43 | * europe-west1 44 | 45 | 46 | ## Cleaning Up Datalab Instance 47 | 48 | 생성된 Datalab에 대한 자원을 종료를 해줍니다. (cleaning up을 안 할 경우 비용이 추가적으로 나올 수 있습니다.) Datalab VM instance의 생성부터 종료까지 비용이 발생하게 되며, notebooks이 저장되어 있는 persistent disk에 대해서도 비용이 발생합니다. 49 | 50 | 다음의 명령어는 **Datalab Instance** 그리고 **Persistent Disk** 모두 제거합니다. 51 | 52 | > `datalab list` 를 통해서 instances를 확인 가능합니다. 53 | 54 | ``` 55 | datalab delete --delete-disk [instance-name] 56 | ``` 57 | 58 | ## Package Installation 59 | 60 | #### Pytorch & TorchVision 61 | 62 | ``` 63 | !pip3 install http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp35-cp35m-linux_x86_64.whl 64 | !pip3 install torchvision 65 | ``` 66 | 67 | 설치 확인 코드 68 | 69 | ``` 70 | import torch 71 | from torch.autograd import Variable 72 | 73 | a = Variable(torch.cuda.FloatTensor([[1, 2, 3], [0, 1, 1], [1, 0, 3]])) 74 | b = Variable(torch.cuda.FloatTensor([[1, 0, 4], [1, 5, 3], [2, 3, 0]])) 75 | %time a.matmul(b) # a @ b 76 | ``` -------------------------------------------------------------------------------- /04-ssh-keys-in-metadata.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # Overview 4 | 5 | SSH Keys를 생성 그리고 관리를 통해서 [third-party tools](https://cloud.google.com/compute/docs/instances/connecting-advanced#thirdpartytools)을 통해서 접속을 할 수 있습니다. 6 | SSH Key는 2가지 파일로 구성이 되어 있습니다. 7 | 8 | - Public SSH Key file 9 | - Private SSH Key file 10 | 11 | 사용자는 private ssh key를 사용해서, public ssh key를 갖고 있는 인스턴스에 접속할 수 있습니다. 이때 Cloud Platform project의 맴버가 아니어도 접속이 가능해집니다. 따라서 어떤 유저가 접속할지 관리하는 것은 전적으로 public ssh key metadata를 관리함으로서 컨트롤 할 수 있습니다. 12 | 13 | 14 | 15 | # 새로운 SSH Key 생성하기 16 | 17 | 만약 기존의 private SSH key file이 존재하지 않다면 다음의 방법으로 생성할 수 있습니다. 18 | 19 | 먼저 local 환경에서 terminal을 열고 새로운 키를 생성합니다. 20 | 21 | ```bash 22 | ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME] 23 | chmod 400 ~/.ssh/[KEY_FILENAME] 24 | ``` 25 | 26 | 예를 들어서 다음과 같이 만들수 있습니다 . 27 | 28 | ``` 29 | ssh-keygen -t rsa -f ~/.ssh/gcp -C "a141890@gmail.com" 30 | chmod 400 ~/.ssh/gcp 31 | ``` 32 | 33 | 34 | 35 | # GCP에 SSH Key 등록하기 36 | 37 | 3가지 방식의 메타데이터가 있으며, 이를 통해서 접속을 컨트롤 할 수 있습니다. 38 | 39 | 1. **[Project-wide public SSH keys](https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys#project-wide)**: 프로젝트의 모든 인스턴스에 접속할수 있도록 합니다. 40 | 2. [**Allow or Block project-wide public SSH keys**](https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys#block-project-keys): 특정 인스턴스만 project-wide public ssh key를 통해서 접근을 못하도록 막을 수 있습니다. 41 | 3. [**Instance-level public SSH keys**](https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys#instance-only): 특정 인스턴스에만 특정 public ssh key 설정합니다. 42 | 43 | ## project-wide public SSH Keys 설정하기 44 | 45 | 먼저 `Compute Engine`에서 `메타데이터` 를 선택합니다. 46 | 47 | ![Meta01](images/meta01.png) 48 | 49 | `메타데이터 추가`를 누른 후 `SSH 키` 메뉴를 누르면 여기서 public 키를 등록시킬 수 있습니다. 50 | 51 | ![Meta01](images/meta02.png) 52 | 53 | 등록후 모든 인스턴스에 접속이 가능해집니다. 54 | 55 | ## Project-wide Public Key 접속 막기 56 | 57 | 기본적으로 위에서 project-wide public key를 설정하면 모든 인스턴스에 접속이 가능해집니다. 58 | 하지만 특정 인스턴스는 막고 싶다면 다음과 같이 하면 됩니다. 59 | 60 | 먼저 Compute Engine에서 `VM 인스턴스` 메뉴를 선택후 막고자 하는 인스턴스를 선택합니다. 61 | 62 | ![Meta01](images/meta03.png) 63 | 64 | 캡쳐화면에서 `instance-2`가 있는데 선택후 `수정 `버튼을 눌러서 인스턴스 정보를 수정합니다. 65 | 66 | 수정 화면에서 다음과 같은 체크박스표시가 있습니다. 67 | 68 | ![Meta01](images/meta04.png) 69 | 70 | 체크박스를 선택하면 project-wide public key를 통해서 해당 인스턴스에는 들어갈수 없게 됩니다. 71 | 72 | ## 특정 Instance에 메타데이터 설정하기 73 | 74 | 위의 접속막기와 마찬가지로 Compute Engine에서 `VM 인스턴스` 선택후 `수정`을 누릅니다. 75 | 76 | SSH 키에서 추가하면 끝. 77 | 78 | ![meta05](images/meta05.png) 79 | 80 | # 접속하기 81 | 82 | ``` 83 | ssh -i ~/.ssh/gcp [IP] 84 | ``` 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /11-dataprep-tutorial.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # Overview 4 | 5 | Google Cloud Dataprep은 분석을 하기전 데이터 탐색, 정제, 전처리등등을 시각적으로 실행할 수 있는데 서비스입니다. Cloud Dataprep은 serverless이며 데이터 이외의 관리할 인프라스트럭쳐가 없습니다. 오직 데이터 전처리에만 신경쓰면 됩니다. 또한 코드도 존재하지 않으며 단지 마우스 클릭 몇번으로 모든 일이 처리 될 수 있습니다. 6 | 7 | # 튜토리얼 8 | 9 | ## 준비 10 | 11 | 1. Cloud Storage에서 데이터를 저장할 bucket을 만듭니다. 12 | 2. GCP -> Dataprep 선택후 Trifacta가 프로젝트에 접근할수 있도록 허용하도록 합니다. 13 | (Dataprep은 Trifacta와 구글과 긴밀하게 협력하여 제공되는 서비스입니다.) 14 | 15 | ![Trifacta Access](images/dataprep-tutorial01.png) 16 | 17 | ![Trifacta Access](images/dataprep-tutorial02.png) 18 | 19 | 20 | 21 | ## Flow 생성하기 22 | 23 | 위의 과정을 지나면 다음과 같은 화면이 보입니다. 24 | 25 | ![Trifacta Access](images/dataprep-tutorial03.png) 26 | 27 | Tutorial에서는 [Federal Eletions Commision 2016 ](http://classic.fec.gov/finance/disclosure/ftpdet.shtml#a2015_2016)데이터를 사용하기 때문에 이름을 `FEC-2016`이라고 지어 줍니다. 28 | 29 | ![Trifacta Access](images/dataprep-tutorial04.png) 30 | 31 | ## 데이터 불러오기 32 | 33 | FEC-2016 Flow에서 `Import & Add Datasets` 을 선택합니다. 34 | 35 | ![Trifacta Access](images/dataprep-tutorial05.png) 36 | 37 | 파일을 선택한 후 `Import`를 누릅니다. 38 | 39 | ![Trifacta Access](images/dataprep-tutorial06.png) 40 | 41 | 42 | 43 | ## 데이터 전처리하기 44 | 45 | 등록한후, `Add new Recipe`을 누릅니다. 46 | 47 | ![Trifacta Access](images/dataprep-tutorial07.png) 48 | 49 | `Edit Recipe`을 선택합니다. 50 | 51 | ![Trifacta Access](images/dataprep-tutorial08.png) 52 | 53 | Grid view 화면이 열립니다. 여기에서 데이터 탐색및 변환을 수행할 수 있습니다. 54 | 55 | ![Trifacta Access](images/dataprep-tutorial09.png) 56 | 57 | 먼저 Column5를 보면 1990부터 2064년까지의 년도가 지정되어 있습니다. 58 | 필요한 데이터가 2016년 1월 1일 부터 2018년 1월 1일 전까지라고 가정했을때, 히스토그램에서 2016년 2017년을 포함하는 드래그해서 선택을 합니다. 59 | 60 | ![Trifacta Access](images/dataprep-tutorial10.png) 61 | 62 | 드래그로 선택하고 난뒤 어떻게 처리할지 suggestions을 해줍니다. 63 | 64 | ![Trifacta Access](images/dataprep-tutorial11.png) 65 | 66 | Edit을 눌러서 2016년 1월 1일부터, 2018년 1월 1일전까지로 설정을 합니다. 67 | 68 | ![Trifacta Access](images/dataprep-tutorial12.png) 69 | 70 | Add를 누르고 나면 데이터는 2016년, 2017년 데이터만 남게 됩니다. 71 | 72 | 이번에는 Column6의 mismatched values를 선택합니다. 73 | 74 | ![Trifacta Access](images/dataprep-tutorial13.png) 75 | 76 | 화면 아래쪽의 `Show only affected`에서 `rows` 체크버튼을 클릭합니다. 77 | 78 | ![Trifacta Access](images/dataprep-tutorial14.png) 79 | 80 | Column6에 mismatched values가 생겨나게 된 이유는, 데이터 타입이 state이기 때문입니다. 하지만 mismatched values로 지정된 데이터를 보면 미국 주가 아닌 US로 되어 있는게 대부분입니다. 81 | 82 | ![Trifacta Access](images/dataprep-tutorial15.png) 83 | 84 | mismatched를 해결하기 위해서는 Column6 오른쪽에 있는 깃발(주를 상징)을 클릭후 String으로 변환해줍니다. 85 | 86 | ![Trifacta Access](images/dataprep-tutorial16.png) 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /apache_beam/word_count/wordcount.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | 3 | import argparse 4 | import re 5 | import sys 6 | 7 | import apache_beam as beam 8 | from apache_beam.io.textio import ReadFromText, WriteToText 9 | from apache_beam.options.pipeline_options import PipelineOptions, SetupOptions 10 | 11 | 12 | def get_args(): 13 | parser = argparse.ArgumentParser(sys.argv[1:]) 14 | parser.add_argument('--input', default='gs://dataflow-samples/shakespeare/kinglear.txt') 15 | parser.add_argument('--output', default='gs://YOUR_BUCKET/DEST') 16 | known_args, pipeline_args = parser.parse_known_args() 17 | 18 | pipeline_args.extend([ 19 | # 구글 클라우드 DataFlow에서 pipeline을 돌릴려면 `DataflowRunner` 로 바꿈 20 | # Spark에서 돌릴시 `SparkRunner` 로 바꿔줄수도 있음 21 | '--runner=DirectRunner', 22 | 23 | # Google Cloud Dataflow Service에서 실행시 Project ID 를 명시해줘야함 24 | # 예제) anderson-1189 25 | '--project=YOUR_PROJECT_ID', 26 | 27 | # Google Cloud Dataflow Service에서 실행시 Local file을 stagning시키기 위해서 필요 28 | '--staging_location={0}/staging'.format(known_args.output), 29 | 30 | # Google Cloud Dataflow Service에서 실행시 temporary파일을 위해서 필요 31 | '--temp_location={0}/temp'.format(known_args.output), 32 | 33 | # Job 이름 설정 34 | 'job_name=wordcount_job' 35 | ]) 36 | 37 | print(known_args) 38 | print(pipeline_args) 39 | 40 | return known_args, pipeline_args 41 | 42 | 43 | def main(): 44 | args, pipeline_args = get_args() 45 | 46 | # 먼저 PipelineOpions 을 통해서 pipeline에 대한 설정을 할 수 있습니다. 47 | # 예를 들어서 pipeline runner를 설정하여 무엇이 pipeline을 실행할지 설정할수 있습니다. 48 | 49 | pipeline_options = PipelineOptions(pipeline_args) 50 | pipeline_options.view_as(SetupOptions).save_main_session = True 51 | 52 | with beam.Pipeline(options=pipeline_options) as p: 53 | # Input data file -> TextIO.Read Transform -> PCollection(lines) 54 | lines = p | ReadFromText(args.input) 55 | 56 | counts = ( 57 | lines 58 | | 'Split' >> (beam.FlatMap(lambda x: re.findall(r'[A-Za-z\']+', x)) 59 | .with_output_types(unicode)) 60 | | 'PairWithOne' >> beam.Map(lambda x: (x, 1)) 61 | | 'GroupAndSum' >> beam.CombinePerKey(sum)) 62 | 63 | # Format the counts into a PCollection of strings. 64 | def format_result(word_count): 65 | (word, count) = word_count 66 | return '%s: %s' % (word, count) 67 | 68 | output = counts | 'Format' >> beam.Map(format_result) 69 | 70 | # Write the output using a "Write" transform that has side effects. 71 | # pylint: disable=expression-not-assigned 72 | output | WriteToText(args.output) 73 | 74 | 75 | if __name__ == '__main__': 76 | main() 77 | -------------------------------------------------------------------------------- /03-create-compute-engine-with-gpu-tutorial.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # GPU Instance 생성하기 4 | 5 | 아래와 같이 Instance를 생성합니다. 6 | 7 | ![GPU01](images/gpu01.png) 8 | 9 | GPU 가 지원되는 특정 지역에서만 지원이 되고 있습니다. 10 | 11 | [링크](https://cloud.google.com/compute/docs/gpus/)를 에서 지원되는 지역을 참고 합니다. 12 | 13 | ![GPU02](images/gpu02.png) 14 | 15 | # CUDA 설치 16 | 17 | [구글 클라우드 GPU 등록하기](https://cloud.google.com/compute/docs/gpus/add-gpus) 문서에 나와 있는 그대로 CUDA를 설치합니다. 18 | NVIDIA에서 문서에 나와있지 않는 드라이버를 설치시 나중에 설치가 되지 않을 것입니다. 19 | 정확하게 문서에 나온 그대로의 버젼을 설치해야 합니다. 20 | 21 | ```bash 22 | $ curl -O http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.0.176-1_amd64.deb 23 | $ sudo dpkg -i cuda-repo-ubuntu1604_9.0.176-1_amd64.deb 24 | $ sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub 25 | $ sudo apt-get update 26 | $ sudo apt-get install cuda-9-0 27 | $ sudo nvidia-smi -pm 1 28 | ``` 29 | 30 | `nvidia-smi` 명령어를 통해서 설치가 잘 되었는지 확인합니다. 31 | 설치가 잘되었다면 아래와 같이 나와야 합니다. 32 | 33 | ``` 34 | anderson@instance-1:~$ nvidia-smi 35 | Sat May 12 11:32:10 2018 36 | +-----------------------------------------------------------------------------+ 37 | | NVIDIA-SMI 390.30 Driver Version: 390.30 | 38 | |-------------------------------+----------------------+----------------------+ 39 | | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | 40 | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | 41 | |===============================+======================+======================| 42 | | 0 Tesla K80 On | 00000000:00:04.0 Off | 0 | 43 | | N/A 44C P0 57W / 149W | 0MiB / 11441MiB | 0% Default | 44 | +-------------------------------+----------------------+----------------------+ 45 | | 1 Tesla K80 On | 00000000:00:05.0 Off | 0 | 46 | | N/A 42C P0 61W / 149W | 0MiB / 11441MiB | 0% Default | 47 | +-------------------------------+----------------------+----------------------+ 48 | | 2 Tesla K80 On | 00000000:00:06.0 Off | 0 | 49 | | N/A 61C P0 73W / 149W | 0MiB / 11441MiB | 0% Default | 50 | +-------------------------------+----------------------+----------------------+ 51 | | 3 Tesla K80 On | 00000000:00:07.0 Off | 0 | 52 | | N/A 41C P0 57W / 149W | 0MiB / 11441MiB | 0% Default | 53 | +-------------------------------+----------------------+----------------------+ 54 | 55 | +-----------------------------------------------------------------------------+ 56 | | Processes: GPU Memory | 57 | | GPU PID Type Process name Usage | 58 | |=============================================================================| 59 | | No running processes found | 60 | +-----------------------------------------------------------------------------+ 61 | 62 | ``` 63 | 64 | -------------------------------------------------------------------------------- /25-dataflow-landsat-images-tutorial.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # Overview 4 | 5 | 해당 튜토리얼에서는 Apache Beam 그리고 Cloud Dataflow를 사용해서 [Landsat data](https://cloud.google.com/storage/docs/public-datasets/landsat)를 처리하도록 하겠습니다. 6 | 7 | Landsat data는 GCP에서 public dataset으로 제공을 하고 있습니다. 일반적으로 Landsat images는 농업에서 vegetation index (식생지수: 녹생식물의 상대적 분포량과 활동성 등등을 포함하는 지표)를 만드는데 사용이 됩니다. 월별vegetation index를 만들기 위해서는 다음과 같은 일을 처리하는 스크립트가 필요 합니다. 8 | 9 | 1. 알고자 하는 지역의 Landsat Images를 찾는다 10 | 2. 이중에서 가장 구름이 안낀 사진을 월별로 찾는다 11 | 3. 각각의 이미지는 인공위성의 종류에 따라, 밴드 3과 4 또는 4와 5사이의 정규화된 차이 (normalized difference)를 계산해야 합니다. 이것을 NDVI (Normalized Difference Vegetation Index)라고 합니다. 12 | 13 | 이런 일을 처리하기 위해서 Python 스크립트를 만들수 있을 것입니다. 문제는 여러대의 머신에서 fault-torelent로 동시다발적으로 일을 처리하는 것은 매우 어렵습니다. 이때 사용할수 있는 것이 바로 Google Cloud Dataflow입니다. 14 | 15 | >Google Cloud Dataflow는 구글의 proprietary managed service로서 스트리밍 그리고 배치데이터를 파이프라인을 통해 처리를 할 수 있습니다. Programming model 그리고 SDK는 Apache Beam을 통해서 오픈소스화 되었습니다. 자세한 내용은 [링크](https://cloudplatform.googleblog.com/2016/01/Dataflow-and-open-source-proposal-to-join-the-Apache-Incubator.html?m=1)를 확인합니다. 16 | 17 | 18 | 19 | # Tutorial 20 | 21 | ## Enable Dataflow API 22 | 23 | 먼저 `제품및 서비스` > `API 및 서비스` > `라이브러리` 를 선택합니다. 24 | 25 | ![Enable Dataflow](images/dataflow-tutorial01.png) 26 | 27 | 검색창에서 `dataflow`를 검색후 서택한후 `사용설정 `버튼을 누릅니다. 28 | 29 | ![Enable Dataflow](images/dataflow-tutorial02.png) 30 | 31 | `API 사용 설정`이 되면 외부에서 해당 API를 사용할수 있게 됩니다. 32 | 33 | 34 | 35 | ## Beam code를 Dataflow runner로 보내기 36 | 37 | 먼저 튜토리얼에 사용할 코드를 클론합니다. 38 | 39 | ```bash 40 | git clone https://github.com/GoogleCloudPlatform/training-data-analyst 41 | cd training-data-analyst/blogs/landsat 42 | ``` 43 | 44 | 튜토리얼에 필요한 패키지를 설치합니다. 45 | 46 | ```bash 47 | cd ~/training-data-analyst/blogs/landsat/ 48 | yes | sudo ./install_packages.sh 49 | ``` 50 | 51 | 52 | 53 | `gsutil mb` 명령어를 통해서 Google Cloud Storage에 bucket을 새로 만듭니다. 54 | (이미 있으면 만들필요 당연히 없습니다.) 55 | 56 | ```bash 57 | gsutil mb gs://your-unique-bucket-name 58 | ``` 59 | 60 | `nano run_oncloud.sh` 파일을 열고 `max_num_workers=10` 에서 5로 변경합니다. 61 | 62 | 63 | 64 | 다음을 실행하여 클라우드에서 코드를 실행하도록 합니다. 65 | 66 | ```bash 67 | ./run_oncloud.sh 68 | ``` 69 | 70 | `run_oncloud.sh` 파일에는 다음과 같은 내용이 있습니다. 71 | 72 | ```bash 73 | #!/bin/bash 74 | if [ "$#" -ne 2 ]; then 75 | echo "Usage: ./run_oncloud.sh project-name bucket-name" 76 | echo "Example: ./run_oncloud.sh cloud-training-demos cloud-training-demos" 77 | exit 78 | fi 79 | PROJECT=$1 80 | BUCKET=$2 81 | gsutil -m rm -rf gs://$BUCKET/landsat/output 82 | python ./dfndvi.py \ 83 | --project=$PROJECT \ 84 | --runner=DataflowRunner \ 85 | --staging_location=gs://$BUCKET/landsat/staging \ 86 | --temp_location=gs://$BUCKET/landsat/staging \ 87 | --index_file=gs://cloud-training-demos/landsat/2015index.txt.gz \ 88 | --max_num_workers=5 \ 89 | --autoscaling_algorithm=THROUGHPUT_BASED \ 90 | --output_file=gs://$BUCKET/landsat/output/scenes.txt \ 91 | --output_dir=gs://$BUCKET/landsat/output \ 92 | --job_name=monthly-landsat \ 93 | --save_main_session \ 94 | --setup_file=./setup.py 95 | ``` 96 | 97 | 98 | 99 | ## Dataflow Job 확인하기 100 | 101 | Dataflow 메뉴를 누르면 새롭게 업로드된 job을 확인할 수 있습니다. 102 | 103 | 오른쪽 `작업`화면에서 max_num_workers를 확인해보면 5로 되어 있는것을 확인할 수 있습니다 . 104 | 105 | ![Enable Dataflow](images/dataflow-tutorial03.png) 106 | 107 | 108 | 109 | 약 10~12분정도 걸려서 job이 완료가 되면 Bucket에 가서 결과물을 확인할 수 있습니다. 110 | 111 | -------------------------------------------------------------------------------- /02-create-compute-engine-tutorial.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # Overview 4 | 5 | Google Compute Engine을 사용하여 서로 다른 운영체제 (Debian, Ubuntu, Suse, Red Hat, CoreOS) 기반의 가상 머신을 생성할 수 있습니다. 6 | 7 | # Create VM Instance 8 | 9 | ## 콘솔에서 생성하기 10 | 11 | 먼저 Compute Engine 메뉴로 이동을 합니다. 12 | 13 | ![GCE01](images/gce01.png) 14 | 15 | 최초인 경우 다음의 화면이 보이게 됩니다. 16 | 17 | ![GCE02](images/gce02.png) 18 | 19 | `만들기`를 누르면 새로운 VM Instance를 생성할 수 있습니다. 20 | 21 | ![GCE03](images/gce03.png) 22 | 23 | 캡쳐화면에서 볼 수 있듯이 `이름,` `영역 (Zone)` , `머신 유형, ` `부팅 디스크` 등등을 설정 할 수 있습니다. 24 | `만들기` 버튼을 누른후 잠시 뒤 콘솔에서 생성된 인스턴스를 확인 할 수 있습니다. 25 | 26 | ![GCE04](images/gce04.png) 27 | 28 | ## 명령어로 생성하기 29 | 30 | 예제로 다음과 같이 생성시킬 수 있습니다. 31 | 32 | ``` 33 | gcloud compute instances create test-instance --zone us-central1-c 34 | ``` 35 | 36 | ![GCE07](images/gce07.png) 37 | 38 | 39 | 40 | 접속은 다음과 같이 합니다. 41 | 42 | ``` 43 | gcloud compute ssh test-instance --zone us-central1-c 44 | ``` 45 | 46 | 47 | 48 | 49 | 50 | # Instance에 접속 하기 51 | 52 | ## 콘솔에서 접속 53 | 54 | 아래의 화면에서 `SSH`를 누릅니다. 55 | 56 | ![GCE04](images/gce05.png) 57 | 58 | * 브라우저 창에서 열기를 하면.. 정말 손쉽게 브라우저 창에서 SSH로 연결이 바로 됩니다. 59 | * 개인적으로 `gcloud 명령 보기`를 누릅니다. 60 | * 누르면 명령어가 있는데 그대로 카피해서 terminal에 적으면 바로 연결이 됩니다. 61 | 62 | ![GCE06](images/gce06.png) 63 | 64 | ## SSH로 접속 65 | 66 | 먼저 instance의 리스트를 출력합니다. 67 | 68 | ```bash 69 | gcloud compute instances list 70 | ``` 71 | 72 | [output] 73 | 74 | ``` 75 | NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS 76 | gcelab us-central1-c n1-standard-1 10.128.0.2 35.192.35.18 RUNNING 77 | gcelab2 us-central1-c n1-standard-1 10.128.0.3 35.188.64.84 RUNNING 78 | test-instance us-central1-c n1-standard-1 10.128.0.4 35.193.180.63 RUNNING 79 | ``` 80 | 81 | test-instance에 **접속** 하려면 다음과 같이 합니다. 82 | 83 | ``` 84 | gcloud compute ssh test-instance --zone us-central1-c 85 | ``` 86 | 87 | 88 | 89 | # Persistent Disk 생성하기 90 | 91 | ## 생성및 설정 92 | 93 | 아마존의 EBS (Elastic Block Store)가 persistent block storage가 있듯이, GCP에서도 동일한 기능을 제공합니다. 94 | 95 | ``` 96 | gcloud compute disks create mydisk --size=200GB --zone us-central1-c 97 | ``` 98 | 99 | GCE과 동일한 zone에 persistent disk를 생성해야 합니다. 100 | 또는 VM Instance details 화면에서 변경이 가능합니다. 101 | 102 | ![GCE08](images/gce08.png) 103 | 104 | 생성한 디스크를 virtual instance에 붙이도록 합니다. 105 | 106 | ``` 107 | gcloud compute instances attach-disk gcelab --disk mydisk --zone us-central1-c 108 | ``` 109 | 110 | 만약 다른 이름으로 붙이고 싶다면, `--device-name ` 을 써서 바꿔줄수 있습니다. 111 | 기본적으로 생성되는 이름은.. `scsi-0Google_PersistentDisk_persistent-disk-1` 입니다. 112 | 113 | 확인을 위해서 먼저 SSH로 접속을 합니다. 114 | 115 | ```bash 116 | gcloud compute ssh gcelab --zone us-central1-c 117 | ``` 118 | 119 | 이후 disk devices를 리스트로 뽑아봅니다. 120 | 121 | ```bash 122 | ls -l /dev/disk/by-id/ 123 | ``` 124 | 125 | `scsi-0Google_PersistentDisk_persistent-disk-1` 또는 설정한 이름으로 등록된 디바이스가 추가되어 있으면 문제없이 persistent disk를 분였다는 뜻입니다. 126 | 127 | ## 포맷및 마운팅 128 | 129 | 먼저 mount point를 생성합니다. 130 | 131 | ``` 132 | sudo mkdir /mnt/mydisk 133 | ``` 134 | 135 | 포맷을 해줍니다. 136 | 137 | ``` 138 | sudo mkfs.ext4 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/scsi-0Google_PersistentDisk_persistent-disk-1 139 | ``` 140 | 141 | Mount시켜줍니다 142 | 143 | ``` 144 | sudo mount -o discard,defaults /dev/disk/by-id/scsi-0Google_PersistentDisk_persistent-disk-1 /mnt/mydisk 145 | ``` 146 | 147 | ## Restart시 자동으로 Mount시키기 148 | 149 | `/etc/fstab` 을 vim으로 열어 줍니다. 150 | 151 | ``` 152 | sudo vi /etc/fstab 153 | ``` 154 | 155 | `UUID=...` 로 시작하는 문장 다음에 다음을 집어 넣습니다. 156 | 157 | ``` 158 | /dev/disk/by-id/scsi-0Google_PersistentDisk_persistent-disk-1 /mnt/mydisk ext4 defaults 1 1 159 | ``` 160 | 161 | 저장하고 나오면.. restart때마다 자동으로 해당 persistent disk가 mount되게 됩니다. 162 | 163 | ## Local SSD 164 | 165 | 실제 물리적인 디스크를 virtual machine에 물리적으로 붙일수도 있습니다. 166 | 이 경우 Local SSDs를 사용하게 되며, 다음의 이점이 있습니다. 167 | 168 | * 1ms 보다 적은 latency 169 | * 680,000 read IOPs 170 | * 360,000 write IOPs 171 | 172 | 퍼포먼스 측면에서는 뛰어나나, 관리적 측면 또는 데이터 손실에 있어서 위험이 있습니다. 173 | 자세한 내용은 [링크](https://cloud.google.com/compute/docs/disks/local-ssd#create_a_local_ssd)를 확인합니다. 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /22-cloud-ml-tutorial.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # Overview 4 | 5 | 1. Cloud ML은 TensorFlow application을 **클라우드 환경에서 학습**할 수 있도록 도와 둡니다. 6 | 2. 학습이 끝난 모델은 바로 Inference를 하도록 클라우드 환경에 호스트시킵니다. 7 | 8 | 9 | 10 | # Tutorial 11 | 12 | ## Requirements 13 | 14 | ```bash 15 | pip3 install --upgrade google-api-python-client oauth2client virtualenv 16 | ``` 17 | 18 | 19 | 20 | ## Virtual Environment 생성하기 21 | 22 | `gcloud ml-engine local` 등을 실행시키면 python2.7이 실행이 됩니다. 23 | 만약 python3.x 를 사용한다면, TensorFlow를 찾을수 없다든지 같은 에러를 경험하게 될 것입니다. python버젼을 명시해서 실행시킬수 없는 문제가 있기 땜누에 virtual environment 를 사용하면 문제를 우회해서 풀 수 있습니다. 24 | 25 | 먼저 가상환경을 생성합니다. 26 | 27 | ```bash 28 | virtualenv cmle-env --python=/usr/bin/python3.5 --system-site-packages 29 | source cmle-env/bin/activate 30 | python -V 31 | ``` 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | ## Clone the example repository 40 | 41 | Cloud Shell에서 [repo](https://github.com/GoogleCloudPlatform/cloudml-samples)를 클론시키고 편집하기 위해서 새로운 shell 탭을 엽니다. 42 | 43 | ``` 44 | cloudshell_open --repo_url "https://github.com/googlecloudplatform/cloudml-samples" --page "editor" --open_in_editor "census/estimator" 45 | ``` 46 | 47 | ![Screen](images/cm-tutorial01.png) 48 | 49 | 다음의 위치로 이동을 합니다. 50 | 51 | ```bash 52 | cd census/estimator 53 | ``` 54 | 55 | 56 | 57 | ## 학습 데이터 받기 58 | 59 | 학습 데이터는 Google Cloud Storage Bucket에 public 형태로 저장이 되어 있습니다. 또한 해당 데이터는 이미 학습을 위한 전처리가 완료되어 있기 때문에 원본 데이터와는 다릅니다. 60 | 61 | 학습 데이터를 다운받은후 다시 Cloud Storage에 올리도록 하겠습니다. 62 | 63 | ```bash 64 | mkdir data 65 | gsutil -m cp gs://cloudml-public/census/data/* data/ 66 | ``` 67 | 68 | **TRAIN_DATA 그리고 EVAL_DATA 변수를 설정**합니다. 69 | 70 | ```bash 71 | TRAIN_DATA=$(pwd)/data/adult.data.csv 72 | EVAL_DATA=$(pwd)/data/adult.test.csv 73 | ``` 74 | 75 | 76 | 77 | ## Dependencies 설치하기 78 | 79 | ```bash 80 | pip install --upgrade tensorflow 81 | ``` 82 | 83 | 설치가 제대로 되었는지 `ipython`을 실행시켜서 확인합니다. 84 | 85 | ```python 86 | import tensorflow as tf 87 | hello = tf.constant('Hello, TensorFlow!') 88 | sess = tf.Session() 89 | print(sess.run(hello)) 90 | ``` 91 | 92 | 93 | 94 | ## Local 환경에서 Trainer 개발 및 학습하기 95 | 96 | 실제 Cloud ML Engine 환경에서 live로 돌려보기전에 유사한 환경에서 돌려보는 것이 중요합니다. 97 | 98 | 먼저 **output directory를 설정**합니다. 99 | 100 | ```bash 101 | MODEL_DIR=output 102 | ``` 103 | 104 | 아래의 명령어는 training job을 local에서 실행을 시킵니다. 105 | 106 | ```bash 107 | gcloud ml-engine local train \ 108 | --module-name trainer.task \ 109 | --package-path trainer/ \ 110 | --job-dir $MODEL_DIR \ 111 | -- \ 112 | --train-files $TRAIN_DATA \ 113 | --eval-files $EVAL_DATA \ 114 | --train-steps 1000 \ 115 | --eval-steps 100 116 | ``` 117 | 118 | 119 | 120 | ## TensorBoard에서 training 확인하기 121 | 122 | output디렉토리를 확인하면 model checkpoints 그리고 summary information이 생성되어 있는 것을 확인할 수 있습니다. TensorBoard를 통해서 학습과정을 확인 할 수 있습니다. 123 | 124 | ``` 125 | tensorboard --logdir=output --port=8080 126 | ``` 127 | 128 | 8080포트를 통해서 웹을 통해서 확인 할 수 있습니다 . 129 | 130 | ![Screen](images/cm-tutorial02.png) 131 | 132 | ![Screen](images/cm-tutorial03.png) 133 | 134 | 135 | 136 | ## Local에서 Prediction 해보기 137 | 138 | Tensorflow Model을 학습한뒤, prediction을 해 볼 수 있습니다. `output/export/census` 디렉토리를 보면 **최종 학습 완료된 모델이 timestamp subdirectory 아래에 저장**되어 있습니다. 139 | 140 | > `output/export/census/1525698067/` 위치는 timestamp에 따라서 변경됩니다. 141 | 142 | ```bash 143 | gcloud ml-engine local predict --model-dir output/export/census/1525698067/ --json-instances ../test.json 144 | ``` 145 | 146 | 결과값. 147 | 148 | ``` 149 | CLASS_IDS CLASSES LOGISTIC LOGITS PROBABILITIES 150 | [0] [u'0'] [0.06806272268] [-2.616835832] [0.9319372773, 0.06806272268] 151 | ``` 152 | 153 | 154 | 155 | ## Cloud에서 Training 시키기 156 | 157 | Cloud ML Engine은 데이터를 읽고 쓰기 위해서 Google Cloud Storage (GCS)를 access 권한이 있어야 합니다. 158 | 159 | 다음과 같은 variables을 설정합니다. 160 | 161 | ```bash 162 | PROJECT_ID=$(gcloud config list project --format "value(core.project)") 163 | BUCKET_NAME=${PROJECT_ID}-mlengine 164 | REGION=us-central1 165 | ``` 166 | 167 | GCS에 새로운 bucket을 만듭니다. 168 | 169 | ```bash 170 | gsutil mb -l $REGION gs://$BUCKET_NAME 171 | ``` 172 | 173 | 데이터를 업로드 하고, TRAIN_DATA 그리고 EVAL_DATA 변수를 새로 설정합니다. 174 | 175 | ```bash 176 | gsutil cp -r data gs://$BUCKET_NAME/data 177 | TRAIN_DATA=gs://$BUCKET_NAME/data/adult.data.csv 178 | EVAL_DATA=gs://$BUCKET_NAME/data/adult.test.csv 179 | ``` 180 | 181 | 182 | 183 | ## Cloud에서 Single-instance Trainer 실행시키기 184 | 185 | Local환경에서 학습 그리고 예측이 잘 돌아가는것을 확인했습니다. 이제 cloud환경에서 training job을 실행시킬 준비가 되었습니다. 186 | 187 | >예제에서는 single instance를 사용하지만, distributed training 또는 GPU를 사용하는 방법등등 모두 손쉽게 실행할 수 있습니다. 188 | 189 | 먼저 다음과 같이 변수들을 설정합니다. 190 | 191 | ```bash 192 | JOB_NAME=census1 193 | OUTPUT_PATH=gs://$BUCKET_NAME/$JOB_NAME 194 | echo $OUTPUT_PATH 195 | ``` 196 | 197 | 클라우드로 job를 전송합니다. 198 | 199 | ```bash 200 | gcloud ml-engine jobs submit training $JOB_NAME \ 201 | --job-dir $OUTPUT_PATH \ 202 | --runtime-version 1.4 \ 203 | --module-name trainer.task \ 204 | --package-path trainer/ \ 205 | --region $REGION \ 206 | -- \ 207 | --train-files $TRAIN_DATA \ 208 | --eval-files $EVAL_DATA \ 209 | --train-steps 5000 \ 210 | --verbosity DEBUG 211 | ``` 212 | 213 | 다음의 명령어로 training job에 대한 progress를 로그로 확인할 수 있습니다. 214 | 215 | ```bash 216 | gcloud ml-engine jobs stream-logs $JOB_NAME 217 | ``` 218 | 219 | 220 | 221 | Cloud Machine Learning Engine에서 실행되고 있는 job을 확인할 수 있습니다. 222 | 223 | ![Screen](images/cm-tutorial04.png) 224 | 225 | Google Cloud Storage에 저장된 결과값을 확인합니다. 226 | 227 | ```bash 228 | gsutil ls -r $OUTPUT_PATH 229 | ``` 230 | 231 | TensorBoard에서 결과값을 확인합니다. 232 | 233 | ```bash 234 | tensorboard --logdir=$OUTPUT_PATH --port=8080 235 | ``` 236 | 237 | 238 | 239 | ## Deploy your Model to serve prediction requests 240 | 241 | Cloud Machine Learning Engine에 학습된 모델을 디플로이하면, prediction requests를 처리할수 있으며, scalable serving이 가능해집니다. 242 | 243 | 일단은 training job이 완료될때까지 기다려야 합니다. 작업 ID옆에 녹색 체크박스가 표시되거나 또는 "Job completed successfully"를 보게되면 디플로이준비가 완료된것이라고 볼 수 있습니다. 244 | 245 | > 반드시 클라우드에서 학습한 모델을 사용할 필요는 없습니다. Local 환경에서 학습이 완료된 모델을 디플로이도 가능합니다. 246 | 247 | 먼저 Cloud ML Engine에 모델을 생성합니다. 248 | 249 | ```bash 250 | MODEL_NAME=census 251 | gcloud ml-engine models create $MODEL_NAME --regions=$REGION 252 | ``` 253 | 254 | 콜솔에서 생성된 모델을 확인할 수 있습니다. 255 | 256 | ![Screen](images/cm-tutorial05.png) 257 | 258 | 최종 생성된 모델의 위치를 찾습니다. (timestamp로 디렉토리가 생성되기 때문에 반드시 필요합니다.) 259 | 260 | ```bash 261 | gsutil ls -r $OUTPUT_PATH/export 262 | ``` 263 | 264 | Timestamp를 확인해서 변수를 생성합니다. 265 | 266 | ```bash 267 | MODEL_BINARIES=$OUTPUT_PATH/export/census// 268 | ``` 269 | 270 | 271 | 272 | 디플로이를 합니다. 273 | 274 | ```bash 275 | gcloud ml-engine versions create v1 \ 276 | --model $MODEL_NAME \ 277 | --origin $MODEL_BINARIES \ 278 | --runtime-version 1.4 279 | ``` 280 | 281 | 디플로이는 완료되기까지 실제로 몇분이상이 걸립니다. 282 | 283 | 최종 디플로이된 모델에 대한 확인은 다음과 같이 합니다. 284 | 285 | ```bash 286 | gcloud ml-engine models list 287 | ``` 288 | 289 | 콘솔에서 확인내용은 다음과 같습니다. 290 | 291 | ![Screen](images/cm-tutorial06.png) 292 | 293 | Prediction request를 다음과 같이 보내서 테스트할 수 있습니다. 294 | 295 | ```bash 296 | gcloud ml-engine predict \ 297 | --model $MODEL_NAME \ 298 | --version v1 \ 299 | --json-instances ../test.json 300 | ``` 301 | 302 | 결과값은 다음과 같습니다. 303 | 304 | ``` 305 | CLASS_IDS CLASSES LOGISTIC LOGITS PROBABILITIES 306 | [0] [u'0'] [0.03047093376] [-3.46003723144] [0.96952909231, 0.030470931902] 307 | ``` 308 | 309 | -------------------------------------------------------------------------------- /05-kubernetes-tutorial.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 4 | 5 | # Google Kubernetes 이란? 6 | 7 | [Kubernetes](http://kubernetes.io/)은 오픈 소스 프로젝트로서 컨테이너같은 서비스를 제공합니다. 8 | 9 | ![Architecture2](images/kubernetes-container-registry-architecture.png) 10 | 11 | ![Kubernetes Architecture](images/kubernete-architecture.png) 12 | 13 | 14 | 15 | # Tutorial 16 | 17 | 해당 튜토리얼은 Google Cloud shell에서 진행을 할 수 있습니다. 18 | 19 | 20 | 21 | 22 | 23 | ## Node.js 애플리케이션 만들기 24 | 25 | 먼저 server.js 에다가 아주 기본적인 스크립트를 작성합니다. 26 | 27 | ``` 28 | vi server.js 29 | ``` 30 | 31 | 아래와 같이 작성을 합니다. 32 | 33 | ``` 34 | var http = require('http'); 35 | var handleRequest = function(request, response) { 36 | response.writeHead(200); 37 | response.end("Hello World!"); 38 | } 39 | var www = http.createServer(handleRequest); 40 | www.listen(8080); 41 | ``` 42 | 43 | 서버를 실행시킵니다. 44 | 45 | ``` 46 | node server.js 47 | ``` 48 | 49 | ![Preview](images/kubernetes-preview.png) 50 | 51 | 미리보기 버튼을 누르면 Hello World! 가 찍히는 것을 볼 수 있습니다. 52 | 53 | 54 | 55 | ## Docker Container Image 만들기 56 | 57 | ``` 58 | vi Dockerfile 59 | ``` 60 | 61 | 내용은 다음과 같습니다. 62 | 63 | ``` 64 | FROM node:6.9.2 65 | EXPOSE 8080 66 | COPY server.js . 67 | CMD node server.js 68 | ``` 69 | 70 | **Docker image를 생성**합니다. 이때 `PROJECT_ID`는 `gcloud projects list` 로 확인 할 수 있습니다. 71 | 72 | ``` 73 | docker build -t gcr.io/PROJECT_ID/hello-node:v1 . 74 | ``` 75 | 76 | 생성한 **docker container를 실행**시켜서 제대로 작동하는지 확인해 볼 수 있습니다. 77 | 78 | ``` 79 | docker run -d -p 8080:8080 gcr.io/PROJECT_ID/hello-node:v1 80 | ``` 81 | 82 | docker images 그리고 processor를 확인합니다. 83 | 84 | ``` 85 | docker images 86 | docker ps -a 87 | ``` 88 | 89 | 프리뷰 버튼을 눌러서 확인합니다. 90 | 91 | ![Preview](images/kubernetes-preview.png) 92 | 93 | curl 을 통해서도 확인이 가능합니다. 94 | 95 | ``` 96 | curl http://localhost:8080 97 | ``` 98 | 99 | 돌아가는 것을 확인했으니 **중지**시킵니다. 100 | 101 | ```bash 102 | $ docker ps -a 103 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 104 | a3cae6681914 gcr.io/xmdw33/hello-node:v1 "/bin/sh -c 'node ..." 5 minutes ago Up 5 minutes 0.0.0.0:8080->8080/tcp stupefied_cori 105 | 106 | $ docker stop stupefied_cori 107 | ``` 108 | 109 | 작동하는 것을 확인했으니, [Google Container Registry](https://cloud.google.com/container-registry/) 로 보냅니다. Google Container Registry는 docker images를 위한 private repository 로서 google cloud projects에서 접근이 가능합니다. 110 | 111 | ``` 112 | gcloud docker -- push gcr.io/PROJECT_ID/hello-node:v1 113 | ``` 114 | 115 | ![Container Registry](images/kubernetes-container-registry.png) 116 | 117 | ![container registry01](images/kubernetes-container-registry01.png) 118 | 119 | ![container registry01](images/kubernetes-container-registry02.png) 120 | 121 | 명령어에서도 확인할 수 있습니다. 122 | 123 | ```bash 124 | $ gcloud container images list 125 | NAME 126 | gcr.io/qwiklabs-gcp-8bba0513ed0c0ffd/hello-node 127 | ``` 128 | 129 | 130 | 131 | ## Container Engine Cluster 생성하기 132 | 133 | Cluster는 master API server 그리고 여러개의 worker nodes로 이루어져 있으며, worker nodes는 Compute Engine 의 가상 머신이라고 생각하면 됩니다. 134 | 135 | 아래의 명령어는 두개의 [n1-standard-1](https://cloud.google.com/compute/docs/machine-types) 노드를 생성합니다. (몇분이 걸립니다) 136 | 137 | ```bash 138 | gcloud container clusters create hello-world --num-nodes 2 --machine-type n1-standard-1 --zone us-central1-f 139 | ``` 140 | 141 | **확인**은 다음과 같이 합니다. 142 | 143 | ```bash 144 | gcloud container clusters list 145 | gcloud container images list 146 | ``` 147 | 148 | 콘솔에서 Kubernetes Cluster를 확인할 수 있습니다. 149 | 150 | ![Kubernetes Cluster](images/kubernetes-cluster.png) 151 | 152 | 2개 생성한 nodes는 Compute Engine에서 확인 할 수 있습니다. 153 | 154 | ![nodes](images/kubernetes-compute-enginge-node.png) 155 | 156 | 157 | 158 | ## Pod 생성하기 159 | 160 | Kubernetes Pod는 containers 그룹으로서 **관리** 및 **네트워크** 목적을 갖고 있으며, **하나 또는 다수의 containers를 갖고 있을 수 있습니다.** 161 | 162 | 먼저 이미지를 확인합니다. 163 | 164 | ```bash 165 | $ gcloud container images list 166 | NAME 167 | gcr.io/xmdw33/backend 168 | gcr.io/xmdw33/frontend 169 | gcr.io/xmdw33/hello-node 170 | Only listing images in gcr.io/xmdw33 171 | ``` 172 | 173 | 아래의 명령어는 deployments object를 생성합니다. 174 | 175 | ```bash 176 | $ kubectl run hello-node --image=gcr.io/PROJECT_ID/hello-node:v1 --port=8080 177 | deployment "hello-node" created 178 | ``` 179 | 180 | 생성된 **deployments를 확인**합니다. 181 | 182 | ```bash 183 | $ kubectl get deployments 184 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE 185 | hello-world 1 1 1 1 17m 186 | ``` 187 | 188 | 생성된 **pods도 확인**합니다. 189 | 190 | ```bash 191 | $ kubectl get pods 192 | NAME READY STATUS RESTARTS AGE 193 | hello-world-96db85b94-lvxwr 1/1 Running 0 19m 194 | ``` 195 | 196 | **cluster info** 확인합니다. 197 | 198 | ```bash 199 | kubectl cluster-info 200 | ``` 201 | 202 | 설정확인은 다음과 같이 합니다. 203 | 204 | ``` 205 | kubectl config view 206 | ``` 207 | 208 | 혹시 잘못 만들어서 삭제시 다음과 같이 합니다. 209 | 210 | ``` 211 | kubectl delete deployment hello-world 212 | ``` 213 | 214 | 215 | 216 | ## 외부접속 설정 217 | 218 | Pod까지 생성을 했습니다. 하지만 Pod은 오직 내부 IP에서만 접속이 가능합니다. `hello-node` container를 kubernete virtual network**밖에서 접속이 가능하도록 만들려면 pod을 Kubernetes service로 만들어야 합니다**. 219 | 220 | 먼저 deployments를 확인합니다. 221 | 222 | ```bash 223 | $ kubectl get deployments 224 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE 225 | hello-node 1 1 1 1 9m 226 | ``` 227 | 228 | **expose시킵니다.** 229 | 230 | ```bash 231 | $ kubectl expose deployment hello-node --type="LoadBalancer" --port 8080 232 | service "hello-node" exposed 233 | ``` 234 | 235 | LoadBalancer 옵션은 [Compute Engine에서 제공하는 Load Banaler](https://cloud.google.com/compute/docs/load-balancing/) 를 사용하겠다는 뜻이며, Pod을 집접적으로 expose시키는 대신에 deployment 를 expose시켰습니다. 236 | 237 | **publicly-accessible IP 주소를 확인**하기 위해서 다음과 같이 합니다. 238 | 239 | ```bash 240 | $ kubectl get services 241 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 242 | hello-node LoadBalancer 10.3.246.84 35.184.230.137 8080:31574/TCP 3m 243 | kubernetes ClusterIP 10.3.240.1 443/TCP 1h 244 | ``` 245 | 246 | External-IP로 써져있는 35.184.230.137:8080 으로 접속시 Hello World! 를 확인 할 수 있습니다. 247 | 248 | ![External IP](images/kubernete-result.png) 249 | 250 | ## Service를 Scale Up 하기 251 | 252 | Kubernete의 장점중의 하나는 scaling up 그리고 down이 매우 쉽다는 것 입니다. 253 | 254 | 아래의 명령어는 해당 pod에 대한 **replicas를 생성**하도록 합니다. 255 | (이미 2개가 생성되어 있었으니 2개가 추가로 생성이 됩니다. ) 256 | 257 | ``` 258 | kubectl scale deployment hello-node --replicas=4 259 | ``` 260 | 261 | deployment를 확인합니다. 262 | 263 | ```bash 264 | $ kubectl get deployment 265 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE 266 | hello-node 4 4 4 4 29m 267 | ``` 268 | 269 | Pods 도 확인합니다. 270 | 271 | ```bash 272 | $ kubectl get pods 273 | NAME READY STATUS RESTARTS AGE 274 | hello-node-cf99b4b9d-kqm8b 1/1 Running 0 32m 275 | hello-node-cf99b4b9d-qbml5 1/1 Running 0 8m 276 | hello-node-cf99b4b9d-v65zt 1/1 Running 0 8m 277 | hello-node-cf99b4b9d-xws6r 1/1 Running 0 8m 278 | ``` 279 | 280 | 281 | 282 | ## Roll Out 하기 283 | 284 | hello-world 라는 node.js 서버를 만들고 디플로이까지 시켰습니다. 실제 운영중에는 버그픽스도 필요하고 새로운 피쳐를 롤아웃 할때도 있습니다. Kubernetes은 새로운 버젼을 production으로 디플로이 하도록 도와줍니다. 285 | 286 | 먼저 node.js 앱에 대한 수정을 합니다. 287 | 288 | ``` 289 | vi server.js 290 | ``` 291 | 292 | 아래와 같이 수정합니다. 293 | 294 | ``` 295 | response.end("Hello Kubernetes World!"); 296 | ``` 297 | 298 | 새로운 container image를 생성하고 registry에 등록합니다. 299 | `gcloud container images list` 를 통해서 이미지 정보를 얻을 수 있습니다. 300 | 301 | ``` 302 | docker build -t gcr.io/PROJECT_ID/hello-node:v2 . 303 | gcloud docker -- push gcr.io/PROJECT_ID/hello-node:v2 304 | ``` 305 | 306 | 새로운 애플리케이션으로 업데이트하기 위해서 기존의 `hello-node deployment`에서 `gcr.io/PROJECT_ID/hello-node:v1` 을 `gcr.io/PROJECT_ID/hello-node:v2` 으로 수정해줘야 합니다. (수정후 바로 자동으로 적용이 됩니다) 307 | 308 | ```bash 309 | $ kubectl edit deployment hello-node 310 | deployment "hello-node" edited 311 | ``` 312 | 313 | 수정후 몇분뒤 천천히 roll out이 진행이 됩니다. 314 | 315 | ![Roll Out](images/kubernetes-roll-out.png) 316 | 317 | 318 | ## Kubernetes Graphical Dashboard 319 | 320 | GCP에서 Kubernetes clusters로 이동한뒤 `connect`버튼을 찾아서 누룹니다. 321 | 322 | ![Connect](images/kubernetes-connect.png) 323 | 324 | Command-line access 에서 해당 명령어를 복사합니다. 325 | 326 | ![Connect2](images/kubernetes-connect2.png) 327 | 328 | ```bash 329 | gcloud container clusters get-credentials hello-world --zone us-central1-f --project qwiklabs-gcp-8bba0513ed0c0ffd 330 | ``` 331 | 332 | 대쉬보드에 접속하기 위해서는 token을 사용해서 authenticate를 해야 합니다. 333 | 334 | ``` 335 | kubectl -n kube-system describe $(kubectl -n kube-system get secret -n kube-system -o name | grep namespace) | grep token: 336 | ``` 337 | 338 | 8081포트로 변환해서 대쉬보드를 킵니다. 339 | 340 | ![Change Port](images/kubernetes-change-port.png) 341 | 342 | `?authuser=0`을 지우고 `/ui`를 추가시켜서 URL을 만듭니다. 343 | 아래는 예제 입니다. 344 | 345 | ``` 346 | https://8081-dot-3839902-dot-devshell.appspot.com/ui 347 | ``` 348 | 349 | 아래의 화면에서 Token을 선택하고, 이전에 얻은 Token값을 복사해서 넣습니다. 350 | 351 | ![DashBoard](images/kubernetes-dashboard-authentication.png) 352 | 353 | 최종적으로 다음과 같은 화면을 볼 수 있습니다. 354 | 355 | ![Dash Board](images/kubernetes-dashboard.png) 356 | 357 | --------------------------------------------------------------------------------