Google Cloud Professional Cloud Architect Certification(구글 PCA 자격증 대비) (2/5)

wonsik·2022년 12월 18일
1

자격증

목록 보기
2/5
post-thumbnail

6. Getting Started with Gcloud

Gcloud

Command line interface to interact with Google Cloud Resources

모든 서비스는 아니지만 대부분의 서비스를 Gcloud를 사용해서 CRUD가능

Installation

  • 로컬에 Google Cloud SDK 다운로드
  • Console에서 Cloud shell 사용

Connecting to GCP

  • gcloud init: initialize or reinitialize gcloud

    • Authorize gcloud to use your user account credentials
    • Setup configuration
      • Includes current project, default zone etc
  • gcloud config list: list all properties of the active configuration

gcloud command structure

  • GROUP: config or compute or container or dataflow or functions or iam or..
  • SUBGROUP - instances or images or instance-templates or machine-types or regions or zones
  • ACTION - create or list or start or stop or describe or ...

Examples

  • gcloud compute instances list
  • gcloud compute zones list
  • gcloud compute regions list
  • gcloud compute machine-types list
  • gcloud compute machine-types list --filter="zone:us-central1-b"
  • gcloud compute machine-types list --filter="zone:( us-central1-b europe-west1-d )"

Important things you need to know about Cloud Shell:

Cloud Shell is backed by a VM instance (automatically provisioned by
Google Cloud when you launch Cloud Shell)

7. Getting Started with Google Cloud Platform Managed Services

Managed Services

Some terminology used with cloud services:

  • IaaS(Infrastructure as a Service)
  • PaaS(Platform as a Service)
  • FaaS(Function as a Service)
  • CaaS(Container as a Service)
  • Serverless

IAAS

  • Example: Using VM to deploy your application or databases

You are Responsible for:

  • Application Code and Runtime
  • Configuring load balancing
  • Auto scaling
  • OS upgrade and patches
  • Availability

PAAS

Use a platform provided by cloud

Cloud provider is Responsible for:

  • OS
  • Application Runtime
  • Auto scaling, Availability & Load balancing

You are Responsible for:

  • Configuration (of Application and Services)
  • Application code

Varieties:

  • CAAS(Container as a Service): Containers instead of Apps
  • FAAS(Function as a Service): Function instead of Apps
  • Databases - Relational & NoSQL, AI, ML ...

Microservices

기업들은 마이크로서비스 아키텍처를 향하고 있다(유연성 확보)

하지만 배포가 복잡해진다! -> 다양한 언어를 하나의 방법으로 배포하기

컨테이너로 해결(Docker)

Containers - Docker

  • 마이크로서비스 개별로 도커 이미지를 생성할 수 있다.
  • 도커는 응용 프로그램 코드와 종속성을 포함한다.
  • 일단 도커 이미지를 가지면 어떤 인프라에서든 똑같이 실행할 수 있다.

장점

  • 대체로 가볍다(가상 머신에 비해 OS가 없기 때문에)
  • 컨테이너들이 서로 분리되어 있다.(서로 영향을 끼치지 않음)
  • 클라우드 중립적이다.

Container Orchestration

각 마이크로서비스마다 필요한 컨테이너의 인스턴스 수가 다를 수 있음.

Typical Features:

  • Auto Scaling: Scale containers based on demand
  • Service Discovery: Help microservices find on another
  • Load Balancer: Distribute load among multiple instances of a microservice
  • Self Healing: Do health checks and replace failing instances
  • Zero Downtime Deployments: Release new versions without downtime

Serverless

어플리케이션을 개발할 때 생각할 점

  • 어디에 배포? 어떤 서버? 어떤 OS?
  • 어플리케이션의 크기와 가용성을 어떻게 케어할지?

서버에 걱정하지 않으면서 코드에 집중할 수 있는 방법: 서버리스(서버리스의 뜻은 No Servers가 아님!, 단지 백그라운드에서 서버를 사용. 즉 코드가 실행되는 서버에 대한 가시성이 없다.)

특징:

  • Infrastructure에 대한 걱정을 할 필요가 없다.
  • 사용료(리퀘스트가 없으면 사용료가 0이다.)

예: AWS 람다, Azure Function, Google Function

GCP Managed Services for Compute

8. Getting Started with Google Cloud App Engine

APP Engine

GCP에서 어플리케이션을 배포 및 확장하는 가장 간단한 방법

앱 엔진 자체는 무료이지만 앱 엔진을 통해 컴퓨트 인스턴스를 프로비전했다면 그에 대한 비용을 지불해야 함

특징

  • Automatic load balancing & Auto scaling
  • Managed platform updates & Application health monitoring
  • Application versioning
  • Traffic splitting

Compute Engine vs App Engine

Compute Engine

  • IaaS
  • MORE Flexibility
  • MORE Responsibility
    • Choosing Image
    • Installing Software
    • Choosing Hardware
    • Fine grained Access/Permissions (Certificates/Firewalls)
    • Availability etc

App Engine

  • PaaS
  • Serverless
  • LESSER Responsibility
  • LOWER Flexibility

App Engine environments

Standard: Applications run in language specific sandboxes

  • V1: Java, Python, PHP, Go(Old ver)
  • V2: Java, Python, PHP, Node.js, Ruby, Go(New ver)

Flexible: Application instances run within Docker containers(응용 프로그램 인스턴스는 도커 컨테이너 안에서 실행)

App Engine - Scaling Instances

Automatic: Automatically scale instances based on the load

  • Recommended for Continuosly Running Workloads
    • Auto scale based on
      • Target CPU Utilization
      • Target Throughput Utilization
      • Max Concurrent Requests
    • Configure Max instances and Min instances

Basic: Instances are created as and when requests are received:

  • Recommended for Adhoc Workloads
    • Instances are shutdown if ZERO requests
      • Tries to keep costs low
      • High latency is possible
    • NOT suppoerted by APP Engine Flexible Environment
    • Configure Max Instance and Idle Timeout

Manual: Configure specific number of instances to run

App Engine - From the Command Line

cd default-service
gcloud app deploy 
gcloud app services list
gcloud app versions list
gcloud app instances list
gcloud app deploy --version=v2
gcloud app versions list
gcloud app browse #각 버전 트래픽 등 확인
gcloud app browse --version 20210215t072907 #특정 버전 보기 위한 url
gcloud app deploy --version=v3 --no-promote #버전은 바꾸지만 배포는 안하기 위함(테스트 용), 트레픽인 기존 버전으로 이용
gcloud app browse --version v3
gcloud app services set-traffic --splits=v3=.5,v2=.5 -- 새 버전을 마이그레이션 할 때 기존과 반반 나눠서 트래픽을 주고 싶을 때, 같은 ip주소에서는 같은 버전만 나오게 된다.
watch curl https://melodic-furnace-304906.uc.r.appspot.com/ -- 2초마다 해당 url에 get요청을 보냄
gcloud app services set-traffic --splits=v3=.5,v2=.5 --split-by=random -- 동일IP여도 다른 버전을 보내줌
-- 트래픽을 분산시킬 수 있는 다른 방법에는 쿠키가 있다. 
 
cd ../my-first-service/
gcloud app deploy
gcloud app browse --service=my-first-service
 
gcloud app services list
gcloud app regions list

서비스 이름을 yaml파일에 적어두지 않으면 **default 서비스**로 생긴다.

특정 url 순서: **버전.서비스.프로젝트**

9. Google Cloud Kubernetes Engine for Cloud Architects

Google Kubernetes Engine(GKE)

Kubernetes

  • 쿠버네티스는 가장 인기 있는 오픈 소스 컨테이너 오케스트레이션 솔루션이다.
  • 클러스터 관리를 해준다.
  • 단일 클러스터에서 다양한 유형의 가상 컴퓨터를 가질 수 있다, 각 노드들은 다른 하드웨어와 소프트웨어를 가질 수 있다.

Provides all important container orchestration features:

  • Auto Scaling
  • Service Discovery
  • Load Balancer
  • Self Healing
  • Zero Downtime Deployments

Google Kubernetes Engine(GKE)

쿠버네티스 서비스를 관리해준다.

  • 자동 수리로 작업을 최소화 할 수 있다.
  • 자동 업데이트를 통해 최신 버전의 쿠버네티스를 사용할 수 있다.
  • 포드와 클러스터 오토스케일링을 제공한다.
  • 로깅 및 클라우드 모니터링이 쉽게 가능
  • 컨테이너 최적화 OS를 사용한다.
  • 노드와 로컬SSD연결이 가능하다.

쿠버네티스 - 마이크로서비스 여정

0: 쿠버네티스API 허용, 쿠버네티스 클러스터 생성(Standard/Autopilot)

1: Create a Kubernetes cluster with the default node pool

  • gcloud container clusters create or use cloud console

2: Login to Cloud Shell

3: Connect to the Kubernetes Cluster

  • gcloud container clusters get-credentials my-cluster --zone us-central1-a --project
    solid-course-258105

4: Deploy Microservice to Kubernetes:

  • Create deployment & service using kubectl commands

    • kubectl create deployment hello-world-rest-api --image=in28min/hello-world-rest-api:0.0.1.RELEASE
    • kubectl expose deployment hello-world-rest-api --type=LoadBalancer --port=8080
  • 해당 URL 확인: kubectl get service --watch

  • curl 34.72.242.119:8080/hello-world 입력 후 url에 입력하여 능확인 가능

5: Increase number of instances of your microservice:

  • kubectl scale deployment hello-world-rest-api --replicas=2

  • 배포 확인: kubectl get deployment

  • 인스턴스 확인: kubectl get pods

6: Increase number of nodes in your Kubernetes cluster:

  • gcloud container clusters resize my-cluster --node-pool default-pool --num-nodes=2 --zone=us-central1-c
  • You are NOT happy about manually increasing number of instances and nodes!

7: Setup auto scaling for your microservice:

  • kubectl autoscale deployment hello-world-rest-api --max=10 --cpu-percent=70
    • Also called horizontal pod autoscaling - HPA - kubectl get hpa

8: Setup auto scaling for your Kubernetes Cluster

  • gcloud container clusters update cluster-name --enable-autoscaling --min-nodes=1 --
    max-nodes=10

9: Add some application configuration for your microservice

  • Config Map - kubectl create configmap todo-web-application-config --from-literal=RDS_DB_NAME=todos

10: Add password configuration for your microservice

  • Kubernetes Secrets - kubectl create secret generic todo-web-application-secrets-1 --
    from-literal=RDS_PASSWORD=dummytodos

11: Deploy a new microservice which needs nodes with a GPU
attached

  • Attach a new node pool with GPU instances to your cluster
    • gcloud container node-pools create POOL_NAME --cluster CLUSTER_NAME
    • gcloud container node-pools list --cluster CLUSTER_NAME
    • 실제 입력: gcloud container node-pools list --zone=us-central1-c --cluster=my-cluster
  • Deploy the new microservice to the new pool by setting up nodeSelector in the
    deployment.yaml
    • nodeSelector: cloud.google.com/gke-nodepool: POOL_NAME

12: Delete the Microservices

  • Delete service - kubectl delete service
  • Delete deployment - kubectl delete deployment

13: Delete the Cluster

  • gcloud container clusters delete

Google Kubernetes Engine(GKE) Cluster

  • 클러스터: 컴퓨터 엔진 인스턴스들의 그룹

    • Master Node: Manages the cluster

      • API Server: 마스터 노드에서 명령 요청을 받는 곳
      • Scheduler: 파드의 위치를 결정
      • Control Manager: 건강한지 체크
      • etcd: 클러스터 상태를 저장하는 분산 데이터베이스
    • Worker Node: Run your workloads(pods)

      • Runs your pods
      • Kubelet: 마스터 노드와 통신을 관리

Kubernetes -Pods

  • 쿠버네티스의 가작 장은 배포가능한 유닛
  • 하나 이상의 컨테이너가 포함
  • 각 포드는 IP주소가 할당된다.
  • 한 포드에 여러 컨테이너가 존재하면 네트워크, 저장소, IP주소, 포트 등을 공유한다.

Kubernetes - Deployment vs Replica Set

  • 복제판은 특정 수의 포드가 특정 버전을 실행하도록 해줌
  • 배포는 하나의 릴리스에서 다른 릴리스로 이동하는 것만 책임짐(가동시간 없이)

쿠버네티스 서비스가 외부에서 내부의 변화를 알 수 없도록 서비스를 생성하는 방법

  1. 클러스터 IP: 마이크로서비스를 사용하거나 공개하는 서비스가 오직 클러스터에만 사용
  2. 로드밸런서: 서비스를 외부 사용자에게 노출될 때 사용
  3. 노드포트: 서비스를 공개하고자 할 때 사용, 노드IP를 고정 포트에 추가. 모든 마이크로서비스를 노드포트로 노출할 수 있고 인그레스도 가질 수 있다. 여러 노드 포트 서비스로 라우트 할수 있다.

Ingress

Kubernetes 인그레스는 외부 HTTP(S) 트래픽을 서비스로 라우팅하기 위한 규칙 모음입니다. 서비스 탭을 사용하여 인그레스를 만들 수 있습니다.

  • path에 따라 특정 서비스로 이동(serviceName, servicePort)
  • 한 개의 로드밸런서로 여러개의 마이크로서비스 운영이 가능하다.

Creating Docker Images - Dockerfile

Dockerfile contains instruction to create Docker images

  • FROM: Sets a base image
  • WORKDIR: Sets the working directory
  • RUN: excute a command
  • EXPOSE: Informs Docker about the port that the container listens on at runtime
  • COPY: Copies new files or directories into image
  • CMD: Default command for an executing container

시험대비

  • 도커파일은 도커이미지를 생성
  • 도커이미지는 최소 사이즈로 만들어야함
  • 도커이미지를 생성할 때 적절한 레이어를 따르도록 해야함
  • 자주 변경되는 것은 아래쪽에 잘 변경안하는 것은 위쪽에

삭제

서비스 삭제 -> 배포 삭제 -> 클러스터 삭제 -> 프로젝트 삭제

10. Getting Started with Google Cloud Functions

Cloud Functions

이벤트가 발생했을 때 그에 대응해 코드를 실행할 때 사용

Concepts

  • Event: Upload object to cloud storage
  • Trigger: Respond to event with a Function call

11. Getting Started with Google Cloud Run

Cloud Run & Cloud Run for Anthos

Cloud Run - "Container to Production in Seconds"
Fully managed severless platform for containerized applications

  • ZERO infrastructure management
  • Pay-per-use(For used CPU, Memory, Requests and Networking)

클러스터를 만들지 않고 사용가능

Fully integrated end-to-end developer experience:

  • No limitations in language, binaries and dependencies
  • Easily portable because of container based architecture(다른 클라우드 환경에서도 컨테이너를 배포할 수 있음)
  • 클라우드 코드와 아주 잘 통합된다.

Anthos

  • Cloud, Multi Cloud and On-premise
    쿠버네티스 클러스터를 어디서든 사용가능
    단일 클라우드 데이터 센터에서 쿠버네티스 클러스터를 실행할 수 있어야한다.

Cloud Run Command Line

12. Exploring Google Cloud Functions Gen 2

Cloud Functions - Second Generation

2번째 버전이 추천됨

Key Enhancements in 2nd gen:

  • Longer Request timeout: Up to 60min for HTTP-triggered functions
  • Larger instance sizes: 가상 CPU사용으로 16GB 메모리까지 가능
  • Concurrency: 인스턴스당 최대 천 개의 요청을 처리가
  • Multiple Function Revisions and Traffic splitting supported
  • Support for 90+ event types-enabled by Eventarc

Typical serverless function architecture:

1st Gen은 위에 포함

하지만 2nd Gen은 하나의 함수 인스턴스가 동시에 여러개의 요청을 수행할 수 있다.(동시성)

2세대 Cloud Funtion은 Cloud Run과 연관이 깊다.

profile
새로운 기술을 배우는 것을 좋아하는 엔지니어입니다!

0개의 댓글