[Kubernetes in Google Cloud] - Lecture2. Kubernetes Engine: Qwik Start

윰진·2023년 4월 24일
0

빅데이터특화과정

목록 보기
2/8

GOAL

  • GKE로 컨테이너화된 애플리케이션을 배포하는 방법 학습
  • GKE에서 container를 생성하고 애플리케이션을 배포하는 연습

GKE 소개
GKE는 구글의 인프라를 사용하여 컨테이너화된 애플리케이션을 scaling, managing, deploying 에 대한 환경관리 등을 제공한다.

Kubernetes Engine 환경은 container cluster 형태로 그룹화된 여러 개의 Compute Engine 으로 구성되어 있다.

GKE는 Compute Engine에 대한 로드 밸런싱, 추가적인 유연성을 위한 클러스터 내의 노드들의 subset을 위한 Node pools, 클러스터의 node instance couunt의 Automatic Scaling, 클러스터의 node software를 위한 Automatic upgrades, node의 health와 사용 가능성을 유지하기 위한 Node auto-repair, cluster로의 유입을 모니터링 하기 위한 Logging and Monitoring 을 제공한다.

  • GKE는 로드 밸런싱, 노드 풀, 오토 스케일링, 오토 업그레이드, 노드 오토 리페어, 로깅과 모니터링을 제공함

1. Set a default compute zone

  • Compute Zone : Cluster와 자원이 위치한 대략적인 위치
    • us-central1-aus-central1 지역에 있는 zone이다.

1 ) Default Compute Region 설정하기

  gcloud config set compute/region assigned_at_lab_start

output : Updated property [compute/region].

2 ) Default Compute Zone 설정하기

gcloud config set compute/zone assigned_at_lab_start

output : Updated property [compute/region].

2. Create a GKE cluster

하나 이상의 cluster master machine 과 노드로 불리는 여러 개의 worker로 구성된 cluster를 구성해보자.

참고 : 클러스터의 이름의 시작과 끝은 꼭 영숫자여야 하고, 40자 이하

1 ) Cluster 생성

Warning이 발생해도 괜찮다. 수분 걸릴 수 있음

gcloud container clusters create --machine-type=e2-medium --zone=assigned_at_lab_start lab-cluster

output

3. Get authentication credentials for the cluster

Cluster에 자격 권한 부여하기

1 ) Cluster에 권한 부여하기

gcloud container clusters get-credentials lab-cluster

output :
Fetching cluster endpoint and auth data.
kubeconfig entry generated for lab-cluster.

4. Deploy an application to the cluster

클러스터에 컨테이너화된 애플리케이션을 배포해보자!

  • GKE는 cluster의 자원을 생성하고 관리하기 위해 Kubernetes를 사용한다.
    • 웹 서버와 같은 무상태 애플리케이션을 배포하기 위해 제공되는 Deployment kbject
    • 애플리케이션으로의 접근에 대한 로드 밸런싱과 룰을 정의하는 Service object

1 ) hello-app 컨테이너 이미지로부터 새 deployment인 hello-server 생성하기 : kubectl create

hello-server를 표현하는 Deployment object를 생성

  • --image는 배포를 위한 container image를 특정한다.
  • Container Registry에서 example image를 당겨온다.
  • gcr.io/google-samples/hello-app:1.0은 당겨올 이미지의 특정 버전을 가리킨다.
    • 버전이 지정되지 않았으면 최신 버전을 가져온다.
kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0 

output:
deployment.apps/hello-server created

2 ) 애플리케이션을 외부 트래픽에 노출시키기 위한 Kubernetes Resource인 Kubernetes Service 만들기 : kubectl expose

  • --port는 컨테이너가 노출되는 포트를 특정한다.
  • type=LoadBalancer는 컨테이너를 위한 Compute Engine load balancer를 생성한다.
kubectl expose deployment hello-server --type=LoadBalancer --port 8080

output:
service/hello-server exposed

3 ) hello-service inspect 하기 : kubectl get

External IP 주소 생성까지는 몇 분이 걸린다. 만약 EXTERNAL-IP 컬럼이 pending 상태라면 커맨드를 다시 실행해보자.

kubectl get service

output

4 ) 실행 확인

http://[EXTERNAL-IP]:8080

5 ) 클러스터 지우기

gcloud container clusters delete lab-cluster  

output
Deleting cluster lab-cluster...done.
Deleted [https://container.googleapis.com/v1/projects/qwiklabs-gcp-03-ff71ff4f0bbb/zones/us-central1-f/clusters/lab-cluster].

구글 퀵랩 Kubernetes in Google Cloud를 학습하고 정리한 내용입니다.

0개의 댓글