본문 바로가기
구글 스터디잼 쿠버네티스 입문

Kubernetes Engine: Qwik Start

by 치우치지않는 2022. 7. 17.

Overview

Google Kubernetes Engine (GKE) provides a managed environment for deploying, managing, and scaling your containerized applications using Google infrastructure. The Kubernetes Engine environment consists of multiple machines (specifically Compute Engine instances) grouped to form a container cluster. In this lab, you get hands-on practice with container creation and application deployment with GKE.

 

Google Kubernetes Engine(GKE)은 Google 인프라를 사용하여 컨테이너화된 애플리케이션을 배포, 관리 및 확장하기 위한 관리형 환경을 제공한다. Kubernetes Engine 환경은 컨테이너 클러스터를 형성하기 위해 그룹화된 여러 머신(특히 Compute Engine 인스턴스)으로 구성된다. 실습에서는 GKE를 사용하여 컨테이너 생성 및 애플리케이션 배포를 실습한다!

Cluster orchestration with Google Kubernetes Engine

Google Kubernetes Engine (GKE) clusters are powered by the Kubernetes open source cluster management system. Kubernetes provides the mechanisms through which you interact with your container cluster. You use Kubernetes commands and resources to deploy and manage your applications, perform administrative tasks, set policies, and monitor the health of your deployed workloads.

Kubernetes draws on the same design principles that run popular Google services and provides the same benefits: automatic management, monitoring and liveness probes for application containers, automatic scaling, rolling updates, and more. When you run your applications on a container cluster, you're using technology based on Google's 10+ years of experience with running production workloads in containers.

 

Google Kubernetes Engine을 사용한 클러스터 오케스트레이션

Google Kubernetes Engine(GKE) 클러스터는 Kubernetes 오픈 소스 클러스터 관리 시스템을 기반으로 한다. Kubernetes는 컨테이너 클러스터와 상호 작용하는 메커니즘을 제공한다. Kubernetes 명령 및 리소스를 사용하여 애플리케이션을 배포 및 관리하고, 관리 작업을 수행하고, 정책을 설정하고, 배포된 워크로드의 상태를 모니터링한다.

Kubernetes on Google Cloud

When you run a GKE cluster, you also gain the benefit of advanced cluster management features that Google Cloud provides. These include:

Now that you have a basic understanding of Kubernetes, you will learn how to deploy a containerized application with GKE in less than 30 minutes. Follow the steps below to set up your lab environment.

 

Google Cloud의 Kubernetes

GKE 클러스터를 실행하면 GCP가 제공하는 고급 클러스터 관리 기능의 이점도 얻을 수 있다. 

 

Compute Engine 인스턴스의 부하 분산

추가 유연성을 위해 클러스터 내에서 노드의 하위 집합을 지정하는 노드 풀

클러스터의 노드 인스턴스 수 자동 조정

클러스터의 노드 소프트웨어에 대한 자동 업그레이드

노드 상태 및 가용성을 유지하기 위한 노드 자동 복구

클러스터에 대한 가시성을 위한 Cloud Monitoring으로 로깅 및 모니터링

 

Task 1. Set a default compute zone

Your compute zone is an approximate regional location in which your clusters and their resources live. For example, us-central1-a is a zone in the us-central1 region.

To set your default compute zone to us-central1-a, start a new session in Cloud Shell, and run the following command:

 

태스크1. 기본 컴퓨팅 영역 설정 
컴퓨팅 영역은 클러스터와 해당 리소스가 있는 대략적인 지역 위치이다! 예를 들어 us-central1-a 는 us-central1 지역의 영역이다. 

기본 컴퓨팅 영역을 us-central1-a 로 설정하려면 다음과 같은 명령어를 입력하자!

gcloud config set compute/zone us-central1-a

Expected output:

Updated property [compute/zone].

Task 2. Create a GKE cluster

A cluster consists of at least one cluster master machine and multiple worker machines called nodes. Nodes are Compute Engine virtual machine (VM) instances that run the Kubernetes processes necessary to make them part of the cluster.

Note: Cluster names must start with a letter and end with an alphanumeric, and cannot be longer than 40 characters.

To create a cluster, run the following command, replacing [CLUSTER-NAME] with the name you choose for the cluster (for example:my-cluster).

 

태스크 2. GKE 클러스터 생성

클러스터는 하나 이상의 클러스터 마스터 시스템과 노드라고 하는 여러 작업자 시스템으로 구성된다. 노드는 클러스터의 일부로 만드는 데 필요한 Kubernetes 프로세스를 실행하는 Compute Engine 가상 머신(VM) 인스턴스이다.

 

참고: 클러스터 이름은 문자로 시작하고 영숫자로 끝나야 하며 40자를 초과할 수 없다.

 

클러스터를 생성하려면 다음 명령을 실행하되 [CLUSTER-NAME] 클러스터에 대해 선택한 이름(: my-cluster)으로 바꾼다.

 

gcloud container clusters create [CLUSTER-NAME]

You can ignore any warnings in the output. It might take several minutes to finish creating the cluster.

Expected output:

NAME: my-cluster
LOCATION: us-central1-a
MASTER_VERSION: 1.22.8-gke.202
MASTER_IP: 34.67.240.12
MACHINE_TYPE: e2-medium
NODE_VERSION: 1.22.8-gke.202
NUM_NODES: 3
STATUS: RUNNING

Click Check my progress to verify the objective.

 

Task 3. Get authentication credentials for the cluster

After creating your cluster, you need authentication credentials to interact with it.

To authenticate the cluster, run the following command, replacing [CLUSTER-NAME] with the name of your cluster:

 

작업 3. 클러스터에 대한 인증 자격 증명 가져오기

클러스터를 만든 후 클러스터와 상호 작용하려면 인증 자격 증명이 필요함.

 

클러스터를 인증하려면 다음 명령을 실행하고 [CLUSTER-NAME] 클러스터 이름으로 바꾸기

gcloud container clusters get-credentials [CLUSTER-NAME]

Expected output:

Fetching cluster endpoint and auth data.
kubeconfig entry generated for my-cluster.

Task 4. Deploy an application to the cluster

You can now deploy a containerized application to the cluster. For this lab, you'll run hello-app in your cluster.

GKE uses Kubernetes objects to create and manage your cluster's resources. Kubernetes provides the Deployment object for deploying stateless applications like web servers. Service objects define rules and load balancing for accessing your application from the internet.

 

태스크 4. 클러스터에 애플리케이션 배포

이제 컨테이너화된 애플리케이션을 클러스터에 배포할 수 있다. 클러스터에서 hello-app을 실행하자!

 

GKE Kubernetes 객체를 사용하여 클러스터의 리소스를 만들고 관리한다. Kubernetes 서버와 같은 상태 비저장 애플리케이션을 배포하기 위한 Deployment 개체를 제공한다. 서비스 객체는 인터넷에서 애플리케이션에 액세스하기 위한 규칙과 로드 밸런싱을 정의한다.

 

1. To create a new Deployment hello-server from the hello-app container image, run the following kubectl create command:

kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0

hello-app 컨테이너 이미지에서 새로운 Deployment hello-server 생성하려면 위와 같이 kubectl create 명령을 실행

Expected output:

deployment.apps/hello-server created

This Kubernetes command creates a Deployment object that represents hello-server. In this case, --image specifies a container image to deploy. The command pulls the example image from a Container Registry bucket. gcr.io/google-samples/hello-app:1.0 indicates the specific image version to pull. If a version is not specified, the latest version is used.

 

Kubernetes 명령은 hello-server 나타내는 Deployment 개체를 만든다. 경우 --image 배포할 컨테이너 이미지를 지정한다. 명령은 Container Registry 버킷에서 예시 이미지를 가져온다. gcr.io/google-samples/hello-app:1.0 가져올 특정 이미지 버전을 나타낸다. 버전을 지정하지 않으면 최신 버전이 사용된다.

 

2. To create a Kubernetes Service, which is a Kubernetes resource that lets you expose your application to external traffic, run the following kubectl expose command:

 

애플리케이션을 외부 트래픽에 노출할 있는 Kubernetes 리소스인 Kubernetes 서비스를 생성하려면 다음 kubectl Expo 명령을 실행하기

kubectl expose deployment hello-server --type=LoadBalancer --port 8080
 

In this command:

  • --port specifies the port that the container exposes.
  • type="LoadBalancer" creates a Compute Engine load balancer for your container.

이 명령에서:

 

--port는 컨테이너가 노출하는 포트를 지정

type="LoadBalancer" 컨테이너에 대한 Compute Engine 부하 분산기를 만든다.

 

Expected output:

service/hello-server exposed

3. To inspect the hello-server Service, run kubectl get:

 

hello-server 서비스를 검사하려면 kubectl get 실행하기!

kubectl get service

Expected output:

 

NAME             TYPE            CLUSTER-IP      EXTERNAL-IP     PORT(S)           AGE
hello-server     loadBalancer    10.39.244.36    35.202.234.26   8080:31991/TCP    65s
kubernetes       ClusterIP       10.39.240.1               433/TCP           5m13s

 

Note: It might take a minute for an external IP address to be generated. Run the previous command again if the EXTERNAL-IP column status is pending.

 

external-ip 열 상태가 보류 중인 경우 이전 명령 다시 실행하기. 

 

4. To view the application from your web browser, open a new tab and enter the following address, replacing [EXTERNAL IP] with the EXTERNAL-IP for hello-server.

 

브라우저에서 애플리케이션을 보려면 탭을 열고 다음 주소를 입력하기. [EXTERNAL IP] hello-server EXTERNAL-IP 바꿀 것.

http://[EXTERNAL-IP]:8080

Expected output: The browser tab displays the message Hello, world! as well as the version and hostname.

 

Task 5. Deleting the cluster

1. To delete the cluster, run the following command:

클러스터 삭제하기 

gcloud container clusters delete [CLUSTER-NAME]

2. When prompted, type Y to confirm.

 

Deleting the cluster can take a few minutes. For more information on deleted GKE clusters from the Google Kubernetes Engine (GKE) article, Deleting a cluster.

댓글