반응형

Tasks

Check that there is a tagged image in gcr.io for echo-app:v2
Echo-app:v2 is running on the Kubernetes cluster
The Kubernetes cluster deployment reports 2 replicas.
The application must respond to web requests with V2.0.0

 

1. 파일 압축 풀기 및 Docker Build

 

- 압축 풀기

tar -xvzf resources-ehco-web-v2.tar.gz

- PROJECT_ID 환경변수 등록

export PROJECT_ID=$(gcloud info --format='value(config.project)')

- Image 를 Google Container Registry 에 push

 

2. Version 수정

- echo-web-deployment.yml 파일 수정

아래에 있는 1.0 을  v2 로 변경한다.

- Image push

docker push gcr.io/${PROJECT_ID}/echo-web:v2

그리고 나서 화면에서 Action 에 있는 Rolling update 를 클릭한다.

Rolling Update 에서 image 는 조금전에 push 한 v2 이미지를 사용한다. 그리고 Update 클릭

 

- Scale 변경

Action  메뉴에서 Scale 을 클릭한후 Replicas 값을 2 로 입력한다.

완료가 되면 위에 보이는 Replicas 정보가 아래와 같이 변경된다.

 

Deployment Details 화면에 있는 yaml 탭에 가서 파일 내용을 살펴보면 spec.replicas 가 2 로 변경 되어 있는것을 볼 수 있다.

 

728x90
반응형
반응형

Tasks

An application image with a v1 tag has been pushed to the gcr.io repository
A new Kubernetes cluster exists (zone: us-central1-a)
Check that an application has been deployed to the cluster
Test that a service exists that responds to requests like Echo-app

 

1. 클러스터 생성


gcloud beta container --project "qwiklabs-gcp-00-337f72711928" clusters create "echo-cluster" --zone "us-central1-a" --no-enable-basic-auth --cluster-version "1.14.10-gke.17" --machine-type "n1-standard-2" --image-type "COS" --disk-type "pd-standard" --disk-size "100" --metadata disable-legacy-endpoints=true --scopes "
https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --num-nodes "3" --enable-stackdriver-kubernetes --enable-ip-alias --network "projects/qwiklabs-gcp-00-337f72711928/global/networks/default" --subnetwork "projects/qwiklabs-gcp-00-337f72711928/regions/us-central1/subnetworks/default" --default-max-pods-per-node "110" --addons HorizontalPodAutoscaling,HttpLoadBalancing --enable-autoupgrade --enable-autorepair

 

클러스터 생성은 Cloud Console 에서 직접 하면 된다.

name 은 "echo-cluster" , machine-type 은 "n1-standard-2" 로 만들어 준다.

 

2. tar file 을 Google Cloud Storage 에서 복사한 후 압축을 푼다.

 

- Google Cloud Strage 에서 복사

gsutil cp gs://qwiklabs-gcp-00-337f72711928/echo-web.tar.gz .

- 압축 풀기
tar -xvfz echo-web.tar

 

 

3. Docker Build 및 Image Push

- Docker Build

- Image 확인

echo-app 이 생성된 것을 확인할 수 있다.

 

- GCR(Google Cloud Registry) 에 push 하기 위해서 Tag 를 변경해준다. 

export PROJECT_ID=$(gcloud info --format='value(config.project)')

docker tag echo-app:v1 gcr.io/${PROJECT_ID}/echo-app:v1

- Image 를 Cloud Registry 에 push

중간에 나는 project id 를 그대로 써줬는데 위에서 export 를 했기 때문에 ${PROEJCT_ID} 로 써줘도 된다.

 

4. GKE 에 Deploy 하기

Cloud Console  의 Container Registry 를 확인해 보면 위와 같이 push한 이미지를 확인 할 수 있다.

오른쪽에 ... 메뉴를 눌러보면 Deploy to GKE 버튼을 볼수 있다. 그걸 클릭한다. 

 

Image 는 "Exsiting conatiner images" 를 선택하고 좀전에 생성한 이미지를 선택해준다.

 

Application name 은 "echo-web" 이라고 해준다.

라벨에도 key에 app, value 에 echo-web 이라고 넣어준다.

Cluster 는 위에서 생성한 "echo-cluster" 를 선택한다.

그리고 "Deploy" 클릭.

 

5. 외부에서 접속 할수 있도록 expose 하기

 

Cloud Console 에서 Kubernetes Engine > Workloads 메뉴로 가면 echo-web 의 detail 정보로 들어가면 위와 같이 화면이 나온다.

화면 상단에 있는 Expose 버튼을 누른다.

 

port 를 80 으로 넣어주고 Target port 를 8080 으로 넣고 Expose 버튼을 누른다.

 

Expose 가 완료되면 위와같이 External endpoint 가 나타난다.

 

주소로 접속을 하게 되면 위와 같이 결과를 볼 수 잇다.

Cloud console 메뉴를 이용해서 만들었는데 직접 kubectl 명령어를 활용해서 만들어 보는것도 좋은 공부가 될것 같다.

 

 

 

 

728x90
반응형
반응형

Tasks 

A new non-default VPC has been created
The new VPC contains a new non-default subnet within it
A firewall rule exists that allows TCP port 3389 traffic ( for RDP )
A Windows compute instance called vm-bastionhost exists that has a public ip-address to which the TCP port 3389 firewall rule applies.
A Windows compute instance called vm-securehost exists that does not have a public ip-address
The vm-securehost is running Microsoft IIS web server software.

 

1. Network 및 subnet 생성 

Network 와 subnet 이름은 둘다 securenetwork 로 한다.

 

- Network 생성

gcloud compute --project=qwiklabs-gcp-02-79731d4c62ae networks create securenetwork --subnet-mode=custom

 

- Subnet 생성

gcloud compute --project=qwiklabs-gcp-02-79731d4c62ae networks subnets create securenetwork --network=securenetwork --region=us-central1 --range=192.168.1.0/24

 

2. Firewall 생성

gcloud compute firewall-rules create myfirewalls --network securenetwork --allow=tcp:3389 --target-tags=rdp


target-tags 를 지정해야 나중에 instance의 network tag 를 지정할때 사용할 수 있다.

 

3. vm-securehost Instance 생성

gcloud beta compute --project=qwiklabs-gcp-02-46d92a9845e4 instances create vm-securehost --zone=us-central1-a --machine-type=n1-standard-2 --subnet=securenetwork --no-address --maintenance-policy=MIGRATE --service-account=365821737857-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --image=windows-server-2016-dc-v20200211 --image-project=windows-cloud --boot-disk-size=50GB --boot-disk-type=pd-standard --boot-disk-device-name=vm-securehost --reservation-affinity=any

 

Instance 생성은 GCP 화면 에서 하는것이 더 편할 수도 있다. 위 스크립트도 화면에서 설정한 다음 command line 스크립트를 복사해 놓은 것이다.

 

4. vm-bastionhost Instance 생성

gcloud beta compute --project=qwiklabs-gcp-02-46d92a9845e4 instances create vm-bastionhost --zone=us-central1-a --machine-type=n1-standard-2 --subnet=securenetwork --network-tier=PREMIUM --maintenance-policy=MIGRATE --service-account=365821737857-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --tags=rdp --image=windows-server-2016-dc-v20200211 --image-project=windows-cloud --boot-disk-size=50GB --boot-disk-type=pd-standard --boot-disk-device-name=vm-bastionhost --reservation-affinity=any

 

각각 Instance 생성시 주의 할 점은 vm-bastionhost 는 Network tag 에 위에서 firewall 생성시 썼던 target-tag 를 적어줘야 한다.

instance type 은 기본으로 선택되어있는 최소 사양이 아닌 다음 것으로 해주는게 좋다. 최소 사양은 나중에 구동시에 리소스가 부족해서 안되는 경우도 있다. 

 

5. 윈도우의 접속  ID 및 Password 는 화면에 나온대로 실행을 해준다.

그리고 나중에 securehost 접속시에도 위와 동일하게 vm-bastionhost 를 vm-securehost 로 번경해서 username 과 password 를 확인한 뒤 접속하면 된다.

 

728x90
반응형
반응형

Qwiklab 에 있는 코스중 하나인 Challenge: GCP ArchitectureConfigure a Firewall and a Startup Script with Deployment Manager 를 진행했다. 

 

그렇게 어렵지 않았는데 결과적으로 채점시스템의 오류로 인해서 거의 3시간의 시간을 투자했다.

처음에 하다가 오류를 못찾아서 타임오버나고, 두번째에도 동일한 곳에서 진행이 안되서 끙끙대다가 서비스데스크에 문의한 결과 채점시스템의 오류였다. (내시간... ㅠㅠ)

 

Task 목록은 아래와 같다. 

  • A new Deployment Manager deployment has been created
  • The deployment includes a virtual machine that has an embedded startup-script 
  • The virtual machine that has a startup-script also has a tag item called http
  • A firewall rule exists that allows port 80 (http) traffic and is applied using a tag with a value of http 
  • The virtual machine responds to web requests using the Apache web server
  • Check that Deployment manager includes startup script and firewall resources

1. Cloud Shell 에 project 를 설정한다. 

gcloud config set project [PROJECT_ID]

 

2. qwiklabs.yaml 파일 수정

 

- startup-script 추가

    metadata:
      items:
      - key: startup-script
        value: |
            #!/bin/bash
            sudo su -
            apt-get update
            apt-get install -y apache2
            cat <<EOF > /var/www/html/index.html
            <html><h1>Hello World</h1></html>
            EOF   

 

- tag 추가

    tags:
      items: ["http"]

 

- 방화벽에 tag 추가

- type: compute.v1.firewall
  name: default-allow-http
  properties:
    targetTags: ["http"]
    allowed:
    - IPProtocol: tcp
      ports: ["80"]
    sourceRanges: ["0.0.0.0/0"]

- 추가수정

instance 이름을 꼭 lab-monitor 라고 해야 한다.

그렇지 않으면 위 Task 중 아래 Task 를 완료할 수 없다. ㅡㅡ;

  • The virtual machine responds to web requests using the Apache web server

- 최종본

resources:
- type: compute.v1.instance
  name: lab-monitor
  properties:
    zone: {{ properties["zone"] }}
    machineType: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/zones/{{ properties["zone"] }}/machineTypes/f1-micro
    # For examples on how to use startup scripts on an instance, see:
    #   https://cloud.google.com/compute/docs/startupscript
    tags:
      items: ["http"]
    metadata:
      items:
      - key: startup-script
        value: |
            #!/bin/bash
            sudo su -
            apt-get update
            apt-get install -y apache2
            cat <<EOF > /var/www/html/index.html
            <html><h1>Hello World</h1></html>
            EOF      
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        diskName: disk-{{ env["deployment"] }}
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/global/networks/default
      # Access Config required to give the instance a public IP address
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT
- type: compute.v1.firewall
  name: default-allow-http
  properties:
    targetTags: ["http"]
    allowed:
    - IPProtocol: tcp
      ports: ["80"]
    sourceRanges: ["0.0.0.0/0"]

3. deployment 생성

gcloud deployment-manager deployments create myvm --config=qwiklabs.yaml

 

728x90
반응형

+ Recent posts