Google Cloud

GCP Kubernetes Engine을 통한 배포(2)

인프런 강의

1줄 요약

  • (GCP) GKE를 활용하여 nginx를 실행해보자.

Step 1. GCP Shell 활성화

  • You can list the active account name with this command:
(your_project_id)$ gcloud auth list
           Credentialed Accounts
ACTIVE  ACCOUNT
*       student-04-e46af1f1cd7b@qwiklabs.net

To set the active account, run:
    $ gcloud config set account `ACCOUNT`
  • You can list the project ID with this command:
(your_project_id)$ gcloud config list project
[core]
project = qwiklabs-gcp-04-79efc1e4ae0f

Your active configuration is: [cloudshell-24251]

Step 2. Create Deployment manifests

  • Task 1. Create deployment manifests and deploy to the cluster

(1) Connect to the lab GKE cluster

  • In Cloud Shell, type the following command to set the environment variable for the zone and cluster name.
(your_project_id)$ export my_zone=us-central1-a
(your_project_id)$ export my_cluster=standard-cluster-1
  • Configure kubectl tab completion in Cloud Shell.
(your_project_id)$ source <(kubectl completion bash)
  • In Cloud Shell, configure access to your cluster for the kubectl command-line tool, using the following command:
$ gcloud container clusters get-credentials $my_cluster --zone $my_zone
Fetching cluster endpoint and auth data.
kubeconfig entry generated for standard-cluster-1.
  • In Cloud Shell enter the following command to clone the repository to the lab Cloud Shell.
(your_project_id)$ git clone https://github.com/GoogleCloudPlatform/training-data-analyst
  • Create a soft link as a shortcut to the working directory.
(your_project_id)$ ln -s ~/training-data-analyst/courses/ak8s/v1.1 ~/ak8s
  • Change to the directory that contains the sample files for this lab.
(your_project_id)$ cd ~/ak8s/Deployments/
your_id@cloudshell:~/ak8s/Deployments (your_project_id)$

(2) Create a deployment manifest

  • You will create a deployment using a sample deployment manifest called nginx-deployment.yaml that has been provided for you. This deployment is configured to run three Pod replicas with a single nginx container in each Pod listening on TCP port 80.
    • Let’s create nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
  • To deploy your manifest, execute the following command:
~/ak8s/Deployments (your_project_id)$ kubectl apply -f ./nginx-deployment.yaml
  • To view a list of deployments, execute the following command:
~/ak8s/Deployments (your_project_id)$ kubectl get deployments
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           24s

Step 3.Manually scale up and down the number of Pods in deployments

Sometimes, you want to shut down a Pod instance. Other times, you want ten Pods running. In Kubernetes, you can scale a specific Pod to the desired number of instances. To shut them down, you scale to zero. In this task, you scale Pods up and down in the Google Cloud Console and Cloud Shell.

GCP Kubernetes Engine을 통한 배포(1)

인프런 강의

1줄 요약

  • (GCP) GKE를 활용하여 nginx를 실행해보자.

Step 1. GKE Cluster Setup

  • 네비게이션 메뉴에서 Kubernetes Engine > Clusters를 클릭합니다.

  • 위 화면에서 Create를 클릭합니다.

  • 그 이후에, Cluster 이름은 standard-cluster-1으로 바꾸고, Zone은 us-central1-a로 바꿉니다.

  • 나머지는 모두 Default로 그냥 놔둡니다.

Docker Started using Cloud Build

인프런 강의

1줄 요약

  • (GCP) Cloud Build를 활용하여 Docker를 활용해보자.

Step 1. API Enabled

  • 클라우드 네비게이션 메뉴에서 APIs & Services를 클릭한다.
  • Enable APIs and Services를 클릭한다.
  • Search for APIs & Services에서 Cloud Build를 입력한다.
  • Cloud Build API를 클릭한 후, Enable 버튼을 클릭한다.
  • 뒤로가기 버튼을 클릭한 후, Google Container Registry API 버튼을 클릭한다.

Step 2. Docker File 작성

  • 아래 그림처럼 Activate Cloud Shell를 클릭한다.

Ch07_data_upload

공지

  • 구글 빅쿼리 책 Chapter 4장 학습
  • 참고 교재는 아래와 같다.

개요

  • 로컬에서 데이터를 업로드 해본다.

데이터 다운로드

  • 깃허브에서 데이터를 다운로드 받는다.
$ git clone https://github.com/onlybooks/bigquery.git
  • ch04 폴더로 이동한 뒤, 실제 압축된 파일의 내용을 페이지 단위로 확인해본다.
  • 먼저 ch04 폴더로 이동한다.
  • zlees 명령으로 데이터를 확인해본다.
$ cd bigquery/ch04
$ zless college_scorecard.csv.gz
  • 명령을 실행한 후 스페이스 이용하여 페이지 단위로 데이터 확인 후, 종료하려면 q키를 누른다.
  • zless는 .gz과 같은 파일을 풀지 않고 Preview 형식으로 볼 수 있도록 도와준다.

bq 명령줄 도구

  • bq에 대해 자세히 확인하려면 아래 싸이트에서 확인하기를 바란다.
  • bq 명령줄 도구는 빅쿼리 플랫폼상의 빅쿼리 서비스를 사용하기 위한 편리한 명령들 제공
$ bq --location=US mk ch04
Dataset 'biggquerysample:ch04' successfully created.

에러 상황 1.

  • 다음과 같은 에러 메시지가 발견이 되면 프로젝트를 세팅해줘야 한다.
$ bq --location=US mk ch04
BigQuery error in mk operation: Not found: Project biggquerysample2
  • 대개의 경우, project 세팅을 해줘야 한다.
$ gcloud config set project your_project_ID

데이터 로드

  • 이제 데이터를 빅쿼리 내부의 테이블로 로드하는 명령을 수행해보자.
$ bq --location=US load --source_format=CSV --autodetect ch04.college_scorecard ./college_scorecard.csv.gz
Upload complete.
Waiting on bqjob_r1c47395bddea55ee_00000176e0b2548e_1 ... (37s) Current status: DONE 

에러 상황

  • 필자는 에러 상황이 발생하지는 않았다.
  • 교재에서는 에러가 발생할 수도 있다고 하였다.
Could not parse 'NULL' as int for field HBCU (position 26) starting at location 11945910
  • 위 문제는 데이터 상에 NULL값이 발생해서 생긴 값이다.

Ch06_gcloud_projects

개요

  • MacOS m1, Big Sur에서 gcloud 환경 세팅을 해본다.
  • 목표는 gcloud를 설치 한 뒤, 신규 프로젝트를 설치하도록 한다.

gcloud projects list

  • 현재 active project를 실행하여 보여주는 명령어를 실행하여 확인한다.
    • 프로젝트는 각 계정마다 조금씩 다를 수 있다.
$ gcloud projects list
PROJECT_ID       NAME             PROJECT_NUMBER
biggquerysample  biggquerysample  826877287968

New gcloud projects

  • 이제 새로운 프로젝트를 만들어본다.
$ gcloud projects create bigquerysample2
Create in progress for [https://cloudresourcemanager.googleapis.com/v1/projects/your_project_name].
Waiting for [your_number_will_be_created] to finish...done.                                                                                        
Enabling service [cloudapis.googleapis.com] on project [bigquerysample2]...
Operation "your_number_will_be_created" finished successfully.
  • 이제 새로운 프로젝트가 생겼는지 다시 확인해본다.
$ gcloud projects list
PROJECT_ID       NAME             PROJECT_NUMBER
biggquerysample  biggquerysample  826877287968
bigquerysample2  bigquerysample2  641510072575

새로운 프로젝트 이동

  • 먼저 gcloud config list로 실행하면 아래와 같이 project=bigquerysample로 세팅이 되어 있는 것을 확인할 수 있다.
$ gcloud config list
[core]
account = yourname@gmail.com
disable_usage_reporting = False
project = biggquerysample

Your active configuration is: [default]
  • 기존 gcloudbiggquerysample에서 biggquerysample2로 이동해보자.
$ gcloud config set project biggquerysample2
$ gcloud config list
[core]
account = yourname@gmail.com
disable_usage_reporting = False
project = biggquerysample2

Your active configuration is: [default]

Reference

Warrick.(2020). Setup and Switch Between Google Cloud Projects in the SDK. Retrieved from https://medium.com/google-cloud/setup-and-switch-between-google-cloud-projects-in-the-sdk-885c5000624c

Ch05_gcloud_settings

개요

  • MacOS m1, Big Sur에서 gcloud 환경 세팅을 해본다.
  • 목표는 gcloud를 설치 한 뒤, 신규 프로젝트를 설치하도록 한다.

Cloud SDK 시작 전

  • MacOS에서는 Python이 필요하다.
  • 지원되는 버전은 Python3(권장, 3.5 ~ 3.8) 및 Python 2 (2.7.9) 이상이다.
  • 만약 Python이 설치되지 않았다면 추가로 설치를 진행해야 한다.

Cloud SDK 시작

  • 필요한 파일 및 설치 참고 자료는 공식홈페이지: 빠른 시작: Cloud SDK 시작하기 에서 확인한다.
  • 압축 파일을 풀고 해당 경로로 이동한다.
  • 이 때, 환경문제가 발생할 수 있으니, 가급적 .sh 스크립트를 실행한다.
  • 다음과 같이 실행한다.
$ cd google-cloud-sdk
$ ./install.sh
.
.
Do you want to help improve the Google Cloud SDK (y/N)? y
.
.
Modify profile to update your $PATH and enable shell command 
completion?

Do you want to continue (Y/n)? N

Cloud SDK 초기화

  1. 명령 프롬프트에서 다음 명령어를 실행하면 로그인 등을 진행해야 한다.
  • 먼저, GCP 프로젝트 폴더를 만들고, 해당 경로로 이동한다.
$ mkdir GCP
$ cd GCP
  • 이제 초기화를 진행한다.
$ gcloud init
  1. Google 사용자 계정을 사용하여 로그인 한다.
To continue, you must log in. Would you like to log in (Y/n)? Y
  1. 그러면, 구글 사용자 계정에 로그인하고 허용을 클릭한다.
  2. 터미널에서 본인으 프로제트를 선택하거나 또는 신규 프로젝트를 선택한다.
This account has a lot of projects! Listing them all can take a while.
 [1] Enter a project ID
 [2] Create a new project
 [3] List projects
Please enter your numeric choice:
  1. Google Compute Engine API를 사용 설정한 경우 gcloud init을 사용하여 기본 Compute Engine 영역을 선택할 수 있습니다.
Which compute zone would you like to use as project default?
 [1] [asia-east1-a]
 [2] [asia-east1-b]
 ...
 [14] Do not use default zone
 Please enter your numeric choice:
  • gcloud init은 설정 단계를 성공적으로 완료되었다.
gcloud has now been configured!
You can use [gcloud config] to change more gcloud settings.

Your active configuration is: [default]

gcloud 실행 완료

  • SDK 설치에 대한 정보를 보려면 gcloud 명령어를 실행해보자.
$ gcloud auth list
[core]
account = jhjung@dschloe.com
disable_usage_reporting = False
project = bigquerysample

Your active configuration is: [default]
  • 위 내용까지 잘 출력이 되면, 정상적으로 출력이 된 것이다.

참고자료

빠른 시작: Cloud SDK 시작하기: https://cloud.google.com/sdk/docs/quickstart

구글 텐서플로우 공인 자격증 취득 방법

I. Python 개발환경 (2020.06.20) 기준

  • 텐서플로 자격증 시험은 PyCharm에서 실행된다.
  • 텐서플로 버전 2.x을 사용하고, (1.x) 사용하지 않는다.
  • 파이썬 버전은 3.7을 사용한다. 만약 현재 다른 버전을 사용한다면, 별도로 선정해야 하는 번거로움이 있다.
  • 추가 확인 사항
    • 우선, 인터넷 환경이 안정적이어야 한다.
    • PyCharm 기반 구성에 대해 익숙해져야 한다.

작성 중…

Ch22 Cleaner Null Handling with Coalesce

I. 구글 클라우드 설정

본격적인 빅쿼리 실습에 앞서서, Python과 연동하는 예제를 준비하였다. 빅쿼리 시작에 앞서서 선행적으로 클라우드 사용을 해야 한다.

  1. 만약 GCP 프로젝트가 없다면, 계정을 연동한다. Go to Cloud Resource Manager
  2. 그리고, 비용결제를 위한 카드를 등록한다. Enable billing
  3. 마지막으로 BigQuery API를 사용해야 하기 때문에 빅쿼리 API 사용허가를 내준다.Enable BigQuery

위 API를 이용하지 않으면 Python 또는 R과 연동해서 사용할 수는 없다. 자주 쓰는것이 아니라면 비용은 거의 발생하지 않으니 염려하지 않아도 된다. 비용관리에 대한 자세한 내용은 BigQuery 권장사항: 비용 관리에서 확인하기를 바란다.

Ch21 Conditional Expressions

I. 구글 클라우드 설정

본격적인 빅쿼리 실습에 앞서서, Python과 연동하는 예제를 준비하였다. 빅쿼리 시작에 앞서서 선행적으로 클라우드 사용을 해야 한다.

  1. 만약 GCP 프로젝트가 없다면, 계정을 연동한다. Go to Cloud Resource Manager
  2. 그리고, 비용결제를 위한 카드를 등록한다. Enable billing
  3. 마지막으로 BigQuery API를 사용해야 하기 때문에 빅쿼리 API 사용허가를 내준다.Enable BigQuery

위 API를 이용하지 않으면 Python 또는 R과 연동해서 사용할 수는 없다. 자주 쓰는것이 아니라면 비용은 거의 발생하지 않으니 염려하지 않아도 된다. 비용관리에 대한 자세한 내용은 BigQuery 권장사항: 비용 관리에서 확인하기를 바란다.

Ch20 Logical Operations

I. 구글 클라우드 설정

본격적인 빅쿼리 실습에 앞서서, Python과 연동하는 예제를 준비하였다. 빅쿼리 시작에 앞서서 선행적으로 클라우드 사용을 해야 한다.

  1. 만약 GCP 프로젝트가 없다면, 계정을 연동한다. Go to Cloud Resource Manager
  2. 그리고, 비용결제를 위한 카드를 등록한다. Enable billing
  3. 마지막으로 BigQuery API를 사용해야 하기 때문에 빅쿼리 API 사용허가를 내준다.Enable BigQuery

위 API를 이용하지 않으면 Python 또는 R과 연동해서 사용할 수는 없다. 자주 쓰는것이 아니라면 비용은 거의 발생하지 않으니 염려하지 않아도 된다. 비용관리에 대한 자세한 내용은 BigQuery 권장사항: 비용 관리에서 확인하기를 바란다.