반응형

Tasks

Check that there is a Cloud SQL instance
Check that there is a user database on the Cloud SQL instance
Check that the blog instance is authorized to access Cloud SQL
Check that wp-config.php points to the Cloud SQL instance
Check that the blog still responds to requests

 

1. Create Cloud SQL

 

2. MySql dump 를 export 한다.


참고 )
https://cloud.google.com/solutions/migrating-mysql-to-cloudsql-concept
https://cloud.google.com/sql/docs/mysql/import-export/creating-sqldump-csv#std

 

- 실행 명령어

mysqldump --databases [DATABASE_NAME] -h [INSTANCE_IP] -u [USERNAME] -p \
--hex-blob --skip-triggers --single-transaction --set-gtid-purged=OFF \
--ignore-table [VIEW_NAME1] [...] --default-character-set=utf8mb4 > [SQL_FILE].sql

 

- 조건 

The existing database for the blog is provided by MySQL running on the same server. 
The existing MySQL database is called wordpress and the user called blogadmin with password Password1*, which provides full access to that database.

 

- 실행

위 조건에 맞춰서 다음과 같이 실행을 한다. password 는 위 조건에서 처럼 Password1* 를 넣어주면 된다.

 

3. Cloud Bucket 생성 및 dump 를 gcs 로 복사한다.

 

export PROJECT_ID=$(gcloud info --format='value(config.project)')
gsutil mb gs://$PROJECT_ID
gsutil cp wordpress.sql gs://$PROJECT_ID

 

4. SQL 로 import 한다.

 

참고)

https://cloud.google.com/sql/docs/mysql/import-export/importing

 

명령어를 사용해도 되고 아래와 같이 화면에서 간단히 import 하면 더 편하다.

5. User 추가

 

SQL > Users 탭에서 Create user account 를 클릭한다.

blogadmin 계정을 만들어 준다.

다 된줄 알았는데 아래와 같이 에러가 나온다. ㅡㅡ;

SQL>Connections 탭을 가보면 아래 화면과 같이 Network 설정을 할 수 있다.

Network 설정을 해줘야 하는데 위와같은 range 를 만족해야 한다.

아래 사이트를 가면 쉽게 CIDR range 를 구할 수 있다.

https://www.ipaddressguide.com/cidr

 

CIDR to IPv4 Address Range Utility Tool | IPAddressGuide

Free IP address tool to translate IPv4 address range into CIDR (Classless Inter-Domain Routing) format and vice-versa.

www.ipaddressguide.com

6. wp-config.php 파일을 Cloud SQL Instance 를 사용하도록 수정해준다.

 

wp-config.php 파일에 아래 localhost 를 수정해 하고 주석을 해제 한다. (위치는 /var/www/html/wordpress)

** MySQL hostname

*/ define('DB_HOST', 'localhost');

 

 

7. 이제 재기동 한다. 

sudo service apache2 restart

 

728x90
반응형
반응형

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
반응형

+ Recent posts