Cloud Service Mesh 워크로드에서 Compute Engine VM으로 트래픽 라우팅
이 페이지에서는 GKE의 Cloud Service Mesh 워크로드에서 BackendService가 프런트엔드인 Compute Engine VM으로 네트워크 트래픽을 안전하게 라우팅하는 방법을 보여줍니다.
GKE에서 Compute Engine VM으로 트래픽을 라우팅할 때 Compute Engine VM 또는 BackendService가 Cloud Service Mesh에 가입할 필요는 없습니다. 하지만 Compute Engine VM과 BackendService는 Cloud Service Mesh GKE 클러스터와 동일한 프로젝트에 있어야 합니다. 이 제한사항은 이 기능이 공개 미리보기 버전으로 제공되는 동안 적용됩니다. Compute Engine VM에서 MTLS가 지원되지 않음
시작하기 전에
다음 섹션에서는 다음 사항을 충족했다고 가정합니다.
또는 다음 명령어를 실행하여 BackendService가 프런트엔드인 샘플 Compute Engine VM을 배포할 수 있습니다.
샘플 Compute Engine VM 및 BackendService를 배포합니다.
gcloud compute instance-templates create td-httpd-vm-template \ --scopes=https://www.googleapis.com/auth/cloud-platform \ --tags=http-td-server \ --image-family=debian-11 \ --image-project=debian-cloud \ --metadata=startup-script="#! /bin/bash sudo apt-get update -y sudo apt-get install apache2 -y sudo service apache2 restart echo '<!doctype <html><body><h1>'\`$(/bin/hostname)\`'</h1></body></html>' | sudo tee /var/www/html/index.html" gcloud compute instance-groups managed create http-td-mig-us-east1 \ --zone=VM_ZONE \ --size=2 \ --template=td-httpd-vm-template gcloud compute health-checks create http http-helloworld-health-check gcloud compute firewall-rules create http-vm-allow-health-checks \ --network=default \ --action=ALLOW \ --direction=INGRESS \ --source-ranges=0.0.0.0/0 \ --target-tags=http-td-server \ --rules=tcp:80 gcloud compute backend-services create helloworld \ --global \ --load-balancing-scheme=INTERNAL_SELF_MANAGED \ --protocol=HTTP \ --health-checks http-helloworld-health-check gcloud compute backend-services add-backend helloworld \ --instance-group=http-td-mig-us-east1 \ --instance-group-zone=VM_ZONE \ --global
각 항목의 의미는 다음과 같습니다.
- VM_ZONE은 Compute Engine VM을 배포할 영역입니다.
Compute Engine VM을 GCPBackend로 구성
이 섹션에서는 GCPBackend를 사용하여 Compute Engine VM을 GKE 워크로드에 노출합니다. GCPBackend는 다음으로 구성됩니다.
- 프런트엔드 정보 - 특히 GKE 워크로드가 이 GCPBackend를 호출하는 데 사용할 호스트 이름과 포트입니다.
- 백엔드 정보 - 서비스 이름, 위치, 프로젝트 번호와 같은 BackendService 세부정보
GCPBackend에는 호스트 이름 및 포트 세부정보와 BackendService 세부정보 (서비스 이름, 위치, 프로젝트 번호)가 포함됩니다. GKE 워크로드는 HTTP 요청에서 GCPBackend 호스트 이름과 포트를 사용하여 Compute Engine VM에 액세스해야 합니다.
클러스터 내에서 호스트 이름 DNS를 확인할 수 있도록 하려면 (기본적으로 확인할 수 없음) 선택한 호스트 이름 아래의 모든 호스트를 임의의 IP 주소로 확인하도록 DNS를 구성해야 합니다. Google Cloud 이 DNS 항목을 구성할 때까지 요청이 실패합니다. DNS 구성은 맞춤 도메인당 일회성 설정입니다. Google Cloud
관리형 영역을 만듭니다.
gcloud dns managed-zones create prod \ --description="zone for gcpbackend" \ --dns-name=gcpbackend \ --visibility=private \ --networks=default
이 예에서 DNS 이름은 gcpbackend이고 VPC 네트워크는 default입니다.
도메인을 확인할 수 있도록 레코드를 설정합니다.
gcloud beta dns record-sets create *.gcpbackend \ --ttl=3600 --type=A --zone=prod \ --rrdatas=10.0.0.1
이전 도메인 아래에 호스트 이름이 있는 GCPBackend를 만듭니다.
cat <<EOF > gcp-backend.yaml apiVersion: networking.gke.io/v1 kind: GCPBackend metadata: name: vm-gcp-backend namespace: NAMESPACE spec: type: "BackendService" hostname: hello-world.gcpbackend backendservice: name: helloworld location: global EOF kubectl apply -f gcp-backend.yaml
이 예에서 GCP_BACKEND_NAME는
vm-gcp-backend
입니다.GKE와 Compute Engine VM 간의 연결을 확인하기 위한 테스트 팟을 만듭니다.
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Pod metadata: name: testcurl namespace: default spec: containers: - name: curl image: curlimages/curl command: ["sleep", "3000"] EOF kubectl exec testcurl -c curl -- curl http://hello-world.gcpbackend:80
이제 GKE 워크로드는 hello-world.gcpbackend:80에 HTTP 요청을 전송하여 Compute Engine VM에 액세스할 수 있습니다.
기존 Kubernetes 서비스 또는 Istio 서비스 항목과의 충돌을 방지하려면 GCPBackend에 고유한 이름을 사용해야 합니다. 충돌하는 경우 우선순위 순서 (높음에서 낮음)는 Kubernetes 서비스, istio ServiceEntry, GCPBackend입니다.
가상 서비스와 GCPBackend는 동일한 네임스페이스에 있어야 하며 Compute Engine VM은 Cloud Service Mesh GKE 클러스터와 동일한 프로젝트에 있어야 합니다.