EMD Blog

비공개 Uptime Check 구성 본문

Public Cloud/GCP

비공개 Uptime Check 구성

EmaDam 2022. 9. 3. 10:29

외부 IP를 사용해 Uptime Check하는 것은 간단하지만 내부 IP를 사용해 Uptime Check를 할 경우 추가 작업이 필요하다.

내부 IP를 사용해 Uptime Check를 한다는 것은 트래픽이 비공개 네트워크에 액세스 할 수 있어야 한다는 뜻이 된다. 이를 위해서는 VPC 네트워크, Service Directory Project, Google Cloud 서비스 프로젝트를 구성해야 한다.

먼저 Uptime Check 대상인 VM에게 35.199.192.0/19 IP 대역(GCP Cloud DNS IP대역)의 TCP Ingress를 허용해 주어야 한다. 포트는 Uptime Check에 사용 할 포트를 지정해주면 된다.

gcloud compute firewall-rules create <firewall_name> \\
--network="<vpc_name>"  \\
--action=allow \\
--direction=ingress \\
--source-ranges="35.199.192.0/19" \\
--rules=tcp

Service Directory

Service Directory는 MSA,멀티/하이브리드 환경에서 서비스를 검색하거나 게시 할 수 있도록 하는 서비스이다. Service Discovery를 생각하면 된다. 아래 두 문서를 참고.

https://bcho.tistory.com/1252

https://cloud.google.com/service-directory/docs/overview

먼저 네임 스페이스를 생성한다.

gcloud service-directory namespaces create gw-proxy-namespace --location=asia-northeast3

그 다음 서비스를 생성한다.

gcloud service-directory services create gw-proxy-vm-service \\
--namespace gw-proxy-namespace \\
--location=asia-northeast3

마지막으로 엔드포인트를 생성한다.

# Uptime Check 대상이 될 VM의 내부 IP 조회
export INTERNAL_IP=$(gcloud compute instances describe --zone=asia-northeast3-a <vm_name> --format='get(networkInterfaces[0].networkIP)' --project=<target_project_id>)

gcloud service-directory endpoints create gw-proxy-vm-endpoint \\
--location=asia-northeast3 \\
--namespace=gw-proxy-namespace \\
--service=gw-proxy-vm-service \\
--network=projects/<network_project_number>/locations/global/networks/<vpc_name> \\
--address=$INTERNAL_IP \\
--port=80

네임스페이스는 여러 서비스를 포함하고 서비스는 여러 엔드포인트를 포함한다. 용어는 아래 문서 참고.

https://cloud.google.com/service-directory/docs/key-terms

Uptime Check 생성

GCP Console에서 생성해야한다.

Resource 유형으로 Internal IP 선택 후 Service Directory Service를 아래 형식으로 입력해준다.

projects/<project_id>/locations/<region>/namespaces/<namespace>/services/<services>

위 Service 정보는 다음과 같이 CLI로 조회 할 수도 있다. (위 형식처럼 깔끔하게 조회된다.)

gcloud service-directory services list --namespace=<namespace> --location=asia-northeast3

첫 비공개 Uptime Check 생성 시 권한이 없다면서 에러가 날 수 있다. 그럴때는 아래와 같이 권한을 부여해주면 된다.

gcloud projects add-iam-policy-binding <project_id> --member='serviceAccount:service-<project_number>@gcp-sa-monitoring-notification.iam.gserviceaccount.com' --role='roles/servicedirectory.viewer'
gcloud projects add-iam-policy-binding <network_project_id> --member='serviceAccount:service-336892071212@gcp-sa-monitoring-notification.iam.gserviceaccount.com' --role='roles/servicedirectory.pscAuthorizedService'

'Public Cloud > GCP' 카테고리의 다른 글

GCP KMS  (0) 2022.09.03
GCP Pub/Sub + Cloud Functions로 Google Chat 알림 채널 구성  (0) 2022.09.03
GCP GCS 커스텀 도메인 적용  (0) 2022.09.03
GCP Cloud Functions  (0) 2022.09.03
GCP Pub/Sub  (0) 2022.09.03