Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

JINIers

[PCK] Deploying Apps to Google Cloud lab 본문

GCP/Qwiklabs

[PCK] Deploying Apps to Google Cloud lab

JINIers 2022. 2. 4. 09:53

※ 수정

220921


google cloud 서비스를 App Engine, kubernetes Engine, cloud run에 애플리케이션 배포

 

 

 

 


작업 1. github에서 샘플 앱 다운로드

shell > 

mkdir gcp-course
cd gcp-course

#github에서 python flask 앱 복제
git clone https://GitHub.com/GoogleCloudPlatform/training-data-analyst.git

cd training-data-analyst/courses/design-process/deploying-apps-to-gcp

#프로그램 설치
sudo pip3 install -r requirements.txt

#프로그램 실행
python3 main.py


web preview > preview on port 8080 접속해서 홈페이지 확인 > ctrl+c 프로그램중지


작업 2. app engine에 배포

open editor > ~ new windows
gcp-course/training-data-analyst/courses/design-process/deploying-apps-to-gcp 폴더에 파일만들기 > app.yaml

 

  • app.yaml
runtime: python37


shell > 

#앱 생성지역 지정
gcloud app create --region=us-central

#앱 배포
gcloud app deploy --version=one --quiet



app engine > dashbord > 링크 확인

오른쪽 상단 파란링크를 눌러 test

그러면

버전 1

이게 뜬당

 

 

 

코드편집기 > 

> main.py > title 수정 : Hello App Engine

 

 

shell > 

#2번째버전 배포
gcloud app deploy --version=two --no-promote --quiet


app engine > versions > 버전 확인 후 two 클릭 > Hello App Engine 가 떠야함

버전2

 


버전 2로 마이그레이션 하려면 split traffic > save > dashboard > 새로고침 > 오른쪽 상단 링크 클릭 > Hello App Engine 가 떠야함

split traffic

 

새로고침 후 오른쪽 상단 파란링크를 다시 누르면

 

버전 2로 마이그레이션됨


작업 3. kubernetes engine에 배포

kubernetes engine > create > GKE standard > 그냥 기본값으로 두고 create > 생성 > 점 세개 눌러 > connect > run in cloud shell 누르면 연결 명령어가 자동으로 입력된 cloud shell이 열림

#클러스터 연결
gcloud container clusters get-credentials cluster-1 --zone us-central1-c --project qwiklabs-gcp-04-ae3db717c42e

#연결 테스트(클러스터 머신 표시)
kubectl get nodes




코드 편집기 > main.py > 타이틀 변경 : Hello Kubernetes Engine. > 같은 폴더에 new file > kubernetes-config.yaml 생성

 

  • kubernetes-config.yaml
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: devops-deployment
  labels:
    app: devops
    tier: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: devops
      tier: frontend
  template:
    metadata:
      labels:
        app: devops
        tier: frontend
    spec:
      containers:
      - name: devops-demo
        image: <YOUR IMAGE PATH HERE>            #여기에 이미지링크 넣기
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: devops-deployment-lb
  labels:
    app: devops
    tier: frontend-lb
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: devops
    tier: frontend

 

 


shell > 

cd ~/gcp-course/training-data-analyst/courses/design-process/deploying-apps-to-gcp


#이미지 빌드, container registry에 저장
gcloud builds submit --tag gcr.io/$DEVSHELL_PROJECT_ID/devops-image:v0.2 .





이미지 이름 복사 > 다시 코드 편집기 > <YOUR IMAGE PATH HERE>에 이미지링크 넣기
IMAGES: gcr.io/qwiklabs-gcp-04-ae3db717c42e/devops-image:v0.2

3. 이미지 형식 출력

shell >

#애플리케이션 배포
kubectl apply -f kubernetes-config.yaml

#인스턴스 생성 확인
kubectl get pods

#로드밸런서 구성 생성 확인
kubectl get services

 

외부 ip가 나올때 까지 확인 > 외부 ip 나오면 새탭 열어서 복붙

external ip 확인

 

3. 이게 나와야 함


작업 4. cloud run에 배포

 

코드 편집기 >

main.py > 타이틀 변경 : Hello Cloud Run

cd ~/gcp-course/training-data-analyst/courses/design-process/deploying-apps-to-gcp

#이미지빌드, 콘테이너 레지스트리에 저장
gcloud builds submit --tag gcr.io/$DEVSHELL_PROJECT_ID/cloud-run-image:v0.1 .


cloud run > create service > Authentication : Allow unauthenticated invocations > service name : hello-cloud-run > 설정값 대로 설정.. > 자동으로 생성된 url 클릭 > 그럼 엔진이 뜬다

 

 

4. create service 1
4. create service 2

 

url을 눌러

 

그러면

이게 뜸

 

 

Comments