GKE용 서비스 디렉터리 구성

이 페이지에서는 Google Kubernetes Engine (GKE)로 서비스 디렉터리를 구성하고 GKE 클러스터를 서비스 디렉터리에 자동으로 등록하는 방법을 설명합니다. Autopilot GKE 클러스터 또는 Standard GKE 클러스터로 GKE용 서비스 디렉터리를 구성할 수 있습니다. 두 모드에 대한 자세한 내용은 GKE 작업 모드 선택을 참고하세요.

GKE용 서비스 디렉터리에 대해 자세히 알아보려면 GKE용 서비스 디렉터리 개요를 참고하세요.

제한사항

GKE용 서비스 디렉터리에는 다음과 같은 제한사항이 있습니다.

  • 서비스 디렉터리-GKE 통합을 사용해서만 서비스를 등록할 수 있습니다. Service Directory API를 사용하여 인그레스, 게이트웨이, 기타 리소스를 수동으로 등록해야 합니다.
  • 해당 클러스터의 서비스를 서비스 디렉터리에 동기화하려면 먼저 Fleet을 사용하여 GKE 클러스터를 등록해야 합니다. GKE 클러스터 등록 방법에 대한 자세한 내용은 클러스터 등록을 참고하세요.
  • 모든 서비스 디렉터리 리소스는 클러스터의 프로젝트가 아닌 Fleet 프로젝트에 등록됩니다.
  • 이 통합을 사용하여 등록된 서비스 디렉터리 항목은 수정할 수 없습니다. 변경사항이 서비스 디렉터리에 전파되도록 GKE 서비스 리소스 자체를 모두 변경해야 합니다.

시작하기 전에

  • Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
  • In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  • Verify that billing is enabled for your Google Cloud project.

  • In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  • Verify that billing is enabled for your Google Cloud project.

  • GKE 클러스터를 Fleet에 등록해야 합니다. GKE 클러스터를 등록하려면 클러스터 등록의 안내를 따르세요.

GKE 클러스터 설정

GKE 클러스터를 설정하려면 다음 단계를 따르세요.

  • Service Directory GKE Fleet 기능을 사용 설정합니다.
  • 서비스 디렉터리 등록 정책을 구성합니다.
  • GKE 서비스를 배포합니다.

Service Directory GKE Fleet 기능 사용 설정

서비스 디렉터리 GKE fleet 기능을 사용 설정하려면 gcloud container hub 명령어를 실행합니다.

gcloud

gcloud alpha container hub service-directory enable

서비스의 서비스 디렉터리 등록 정책 구성

등록 정책은 GKE 내에서 서비스 디렉터리에 의해 자동으로 가져오는 서비스의 종류를 정의합니다. 다음 목록에는 이 정책에 대해 구성할 수 있는 옵션이 나와 있습니다.

  • resources: 가져온 GKE 리소스의 유형입니다. 리소스 유형을 여러 개 지정할 수 있습니다. 리소스는 GroupKind로 식별됩니다. Group의 기본값은 core입니다. Kind: service만 사용할 수 있습니다.
  • selector: GKE 리소스에 적용된 key:value 라벨과 일치하는 GKE 라벨 선택기입니다. 기본적으로 선택된 리소스가 없습니다.
  • annotationsToSync: 서비스 디렉터리에 동기화되는 리소스의 주석 키입니다. 이 목록이 비어 있으면 리소스가 주석 없이 서비스 디렉터리에 동기화됩니다.

각 네임스페이스는 단일 정책을 정의해야 합니다. 이 정책에는 name: "default"이 있어야 합니다. 컨트롤러는 다른 이름을 허용하거나 조정하지 않습니다.

ServiceDirectoryRegistrationPolicy를 구성합니다.

다음 매니페스트는 ServiceDirectoryRegistrationPolicy를 설명합니다.

apiVersion: networking.gke.io/v1alpha1
kind: ServiceDirectoryRegistrationPolicy
metadata:
    # Only the name "default" is allowed.
    name: default
    # The ServiceDirectoryRegistrationPolicy is a namespaced resource
    namespace: NAMESPACE
spec:
  resources:
    # Kind specifies the types of Kubernetes resources that can be synced into Service Directory.
    - kind: Service
      # Selector is a label selector for the resource types specified in Kind.
      selector:
        matchLabels:
          LABELS
      # annotationsToSync specifies the annotations that are matched and imported.
      # Any annotations that do not match this set of keys will not be imported into Service Directory.
      annotationsToSync:
      - ANNOTATIONS
      

다음을 바꿉니다.

  • NAMESPACE: 네임스페이스의 이름 네임스페이스에는 ServiceDirectoryRegistrationPolicy이 하나만 있을 수 있습니다. 단일 네임스페이스에 정책이 여러 개 있는 경우 GKE는 활성 정책으로 사용할 정책을 하나 선택하고 나머지는 비활성으로 표시합니다.
  • LABELS: 라벨 선택기(예: sd-import: "true") 이 값은 종류에 지정된 리소스에 적용됩니다. 기본적으로 리소스는 선택되지 않습니다.
  • ANNOTATIONS: 일치하고 가져온 주석 목록입니다(예: - cloud.google.com/load-balancer-type). 선택한 GKE 리소스에 목록의 주석 중 하나가 있으면 주석과 값이 리소스와 함께 서비스 디렉터리에 동기화됩니다. 이 목록이 비어 있으면 리소스가 주석 없이 서비스 디렉터리에 동기화됩니다.

매니페스트를 registration_policy.yaml로 저장합니다.

클러스터에 매니페스트를 적용합니다.

클러스터에 매니페스트를 적용하려면 kubectl apply -f 명령어를 실행합니다.

kubectl apply -f registration_policy.yaml

GKE 서비스 배포

리전의 GKE 클러스터에 GKE 외부 패스 스루 네트워크 부하 분산기 서비스와 애플리케이션을 배포합니다. 예를 들어 리전이 us-central1인 경우 GKE 클러스터 gke-us-central1에 배포합니다.

이렇게 하면 GKE 서비스가 서비스 디렉터리로 가져와집니다.

YAML 파일을 만들고 다른 GKE 리소스와 마찬가지로 적용합니다. LoadBalancer 유형 서비스의 매니페스트는 다음과 같습니다.

apiVersion: v1
kind: Service
metadata:
  name: hello-app-service
  labels:
    sd-import: "true"
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
spec:
  type: LoadBalancer
  selector:
    app: hello
  ports:
  - name: tcp-port
    protocol: TCP
    port: 80
    targetPort: 8080

Deployment의 매니페스트는 다음과 같습니다.

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: hello
  name: hello-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - image: gcr.io/google-samples/hello-app:1.0
        name: hello
        ports:
        - containerPort: 8080
          protocol: TCP

확인하려면 gcloud service-directory services resolve 명령어를 사용하여 서비스의 서비스 디렉터리 쿼리를 실행합니다.

gcloud

gcloud beta service-directory services resolve SERVICE_NAME \
  --location=LOCATION \
  --namespace=NAMESPACE

다음을 바꿉니다.

  • SERVICE_NAME: 서비스의 이름 또는 정규화된 식별자입니다(예: hello-app-service).
  • LOCATION: 서비스의 리전 이름입니다(예: us-central1).
  • NAMESPACE: 서비스의 네임스페이스 이름입니다(예: default).

출력에 서비스가 표시되며 다음과 비슷합니다.

service:
  endpoints:
  - address: 10.140.0.5
    metadata:
      cloud.google.com/load-balancer-type: "Internal"
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app-service/endpoints/my-cluster-12345
    port: 80
    network: projects/123456789/locations/global/networks/default
  name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app-service

결제

서비스 디렉터리는 GKE 통합으로 생성된 리소스에 대해 요금을 청구하지 않습니다. 하지만 API 호출에는 요금이 청구됩니다. 가격 세부정보는 서비스 디렉터리 가격 책정을 참고하세요.

다음 단계

  • 서비스 디렉터리 개요는 서비스 디렉터리 개요를 참고하세요.
  • Service Directory를 사용할 때 발생할 수 있는 일반적인 문제에 대한 해결책을 찾으려면 문제 해결을 참고하세요.