본문 바로가기

[Cloud]/[GCP]

[Qwiklabs] Google Cloud Essentials:Challenge Lab

728x90

솔직히 Challenge Lab 하나에 essential에서 진행했던 실습 내용들이 전부 녹아 있기 때문에 이 Lab 하나만 실습해 봐도 전반적인 GCP에 대한 기초적인 내용들을 알 수 있다고 생각한다. challenge lab의 과제내용들은 다음과 같다.

  • Create an instance.(task 1)
  • Create a 3 node Kubernetes cluster and run a simple service.(task 2)
  • Create an HTTP(s) Load Balancer in front of two web servers.(task 3)

정리하면 instance 생성방법, 3개의 Kubernetes cluster 생성, 그리고 HTTP Load balancer를 만들어 보는 것이다. 각각의 task에 대해 좀 더 자세한 요구사함들을 알아보도록 하자.

Task 1: Create a project jumphost instance

As soon as you sit down at your desk and open your new laptop you receive several requests from the Nucleus team. Read through each description, then create the resources.

  • name the instance nucleus-jumphost
  • use the machine type of f1-micro
  • use the default image type (Debian Linux)
Task 2: Create a Kubernetes service cluster

The team is building an application that will use a service. This service will run on Kubernetes

  • Create a cluster (in the us-east1 region) to host the service
  • Use the Docker container hello-app (`gcr.io/google-samples/hello-app:2.0`) as a place holder, the team will replace the container with their own work later
  • Expose the app on port 8080
Task 3: Setup an HTTP load balancer

We will serve the site via nginx web servers, but we want to ensure we have a fault tolerant environment, so please create an HTTP load balancer with a managed instance group of two nginx web servers. Use the following to configure the web servers, the team will replace this with their own configuration later.

You have a limit to the resources you are allowed to create in your project, so do not create more than two instances in your managed instance group or the lab might exit and you might get banned.

cat << EOF > startup.sh
#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/'
/var/www/html/index.nginx-debian.html
EOF

You need to:

  • Create an instance template
  • Create a target pool
  • Create a managed instance group
  • Create a firewall rule to allow traffic (80/tcp)
  • Create a health check
  • Create a backend service and attach the manged instance group
  • Create a URL map and target HTTP proxy to route requests to your URL map
  • Create a forwarding rule

그럼 각각의 내용에 대해 실습을 진행해 보도록 하자.

 


[ Task 1 ]

Task 1: Create a project jumphost instance

As soon as you sit down at your desk and open your new laptop you receive several requests from the Nucleus team. Read through each description, then create the resources.

  • name the instance nucleus-jumphost
  • use the machine type of f1-micro
  • use the default image type (Debian Linux)

인스턴스를 생성하는 파라미터들에는 굉장히 다양한 내용이 있었다. 이는 CLI를 통해 원하는 VM인스턴스를 간편하게 생성할 수 있다는 뜻이다. 인스턴스를 생성하는 명령어는 다음과 같았다.

gcloud compute instances create gcelab2 --machine-type n1-standard-2 --zone [your_zone]

 gcloud compute instances create --help 명령어를 사용하면 좀 더 자세한 파라미터를 추가할 수 있다. 요구조건에 따라 인스턴스 명은 nucleus-jumphost, machine type은 fi-micro, image type은 default 를 사용하자.


[ Task 2 ]

Task 2: Create a Kubernetes service cluster

The team is building an application that will use a service. This service will run on Kubernetes

  • Create a cluster (in the us-east1 region) to host the service
  • Use the Docker container hello-app (`gcr.io/google-samples/hello-app:2.0`) as a place holder, the team will replace the container with their own work later
  • Expose the app on port 8080

 Kubernetes service cluster를 생성하는 내용의 실습이다. Kubernetes engine cluster는 cluster management system open-source인 kubernetes에 의해 구동되는 engine cluster이다. cluster는 여러대의 일반 워크스테이션을 네트워크로 연결하여 하나의 시스템으로 관리하는 것을 말하는데, kubernetes engine cluster를 사용하면 load-balancing, node-pool과 같은 다양한 이점이 있다. 

cluster와 그 resource들이 위치할 compute zone을 지정한 다음, cluster를 생성한다. 명령어는 다음과 같이 수행하면 된다. 

gcloud config set compute/zone us-east1
gcloud container clusters create [CLUSTER-NAME]

그 다음에는 cluster에 관한 권한을 얻어준다.

gcloud container clusters get-credentials [CLUSTER-NAME]

 

다음은 Docker container hello-app을 place-holder로서 생성하는 것이다. hello-app container에서 kubectl명령어를 이용해 배포한다.

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

이후에 8080포트를 노출시켜준다. type-loadbalancer는 컨테이너에 컴퓨트 엔진 로드벨런서를 만들어준다.

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


[ Task 3 ]

Task 3: Setup an HTTP load balancer

We will serve the site via nginx web servers, but we want to ensure we have a fault tolerant environment, so please create an HTTP load balancer with a managed instance group of two nginx web servers. Use the following to configure the web servers, the team will replace this with their own configuration later.

You have a limit to the resources you are allowed to create in your project, so do not create more than two instances in your managed instance group or the lab might exit and you might get banned.

cat << EOF > startup.sh 
#! /bin/bash 
apt-get update 
apt-get install -y nginx 
service nginx start 
sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/' 
/var/www/html/index.nginx-debian.html 
EOF

You need to:

  • Create an instance template
  • Create a target pool
  • Create a managed instance group
  • Create a firewall rule to allow traffic (80/tcp)
  • Create a health check
  • Create a backend service and attach the manged instance group
  • Create a URL map and target HTTP proxy to route requests to your URL map
  • Create a forwarding rule

요구사항 항목에 따른 과정은 다음과 같다.  

먼저 multiple web server instances를 만들어 줘야 한다. 

<create an instance template>

gcloud compute instance-templates create nginx-template \
         --metadata-from-file startup-script=startup.sh

<create a target pool> : target pool은 로드벨런싱에 필요하며, 그룹내의 모든 인스턴스들에 대해 single access point를 제공한다. 

gcloud compute target-pools create nginx-pool

<create a managed instance group>

gcloud compute instance-groups managed create nginx-group \
         --base-instance-name nginx \
         --size 2 \
         --template nginx-template \
         --target-pool nginx-pool

이를 통해 nginx로 시작하는 두개의 인스턴스가 생성되었다.

gcloud compute instances list

위의 명령어로 생성된 instances들을 볼 수 있다. 

<create a firewall rule to allow traffic (80/tcp)> 다음으로 외부IP에서 포트 80을 통해 각 machine들로 연결될 수 있도록 firewall을 설정해준다.  

gcloud compute firewall-rules create www-firewall --allow tcp:80

 

다음은 HTTP(s) Load Balancer를 만드는 과정이다. 

<create a health check> : health check는 vm-instance가 트레픽에 제대로 응답하는지를 확인하는 상태 메커니즘을 제공한다.

gcloud compute http-health-checks create http-basic-check

이어서 http 서비스를 정의하고 인스턴스 그룹의 포트에 매핑을 해준다.

gcloud compute instance-groups managed \
       set-named-ports nginx-group \
       --named-ports http:80

 

<create a backend service and attatch the managed instance group>

gcloud compute backend-services create nginx-backend \
      --protocol HTTP --http-health-checks http-basic-check --global

백엔드 서비스에 인스턴스 그룹을 추가해 준다.

gcloud compute backend-services add-backend nginx-backend \
    --instance-group nginx-group \
    --instance-group-zone us-east1-b \
    --global

 

<create a URL map and target HTTP proxy to route requests to your URL map>

gcloud compute url-maps create web-map \
    --default-service nginx-backend
gcloud compute target-http-proxies create http-lb-proxy \
    --url-map web-map

 

<create a forwarding rule>

gcloud compute forwarding-rules create http-content-rule \
        --global \
        --target-http-proxy http-lb-proxy \
        --ports 80

 

 

 

 

728x90