프록시리스 gRPC 서비스 메시 설정

이 가이드에서는 프록시리스 gRPC 서비스 메시를 구성하는 방법을 보여줍니다.

이 구성은 미리보기 고객에게 지원되지만 새 Cloud Service Mesh 사용자에게는 권장되지 않습니다. 자세한 내용은 Cloud Service Mesh 개요를 참조하세요.

시작하기 전에

Envoy 사이드카 자동 삽입이 사용 설정된 네임스페이스에 프록시리스 gRPC 서비스 메시를 만들지 마세요. 사이드카 삽입이 사용 설정되었는지 확인하려면 다음 명령어를 실행합니다.

kubectl get namespace default --show-labels

사이드카 자동 삽입이 사용 설정된 경우 다음 명령어를 실행하여 라벨을 삭제합니다.

kubectl label namespace default istio-injection-

gRPC 서비스 배포

이 섹션에서는 gRPC helloworld 예시 서비스를 배포합니다. helloworld 예시 서비스는 gRPC 클라이언트 요청에 대한 응답으로 간단한 메시지를 반환하는 gRPC 서버 애플리케이션입니다. helloworld 서비스는 클러스터의 포트 8080에서 gRPC 서비스를 노출합니다.

  1. grpc-td-helloworld.yaml 파일에 다음을 저장합니다.

    apiVersion: v1
    kind: Service
    metadata:
      name: helloworld
      namespace: default
    spec:
      ports:
      - port: 8080
        name: helloworld
        protocol: TCP
        targetPort: 50051
      selector:
        run: app1
      type: ClusterIP
    
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        run: app1
      name: app1
      namespace: default
    spec:
      selector:
        matchLabels:
          run: app1
      replicas: 2
      template:
        metadata:
          labels:
            run: app1
          annotations:
            sidecar.istio.io/inject: "false"
        spec:
          containers:
          - image: grpc/java-example-hostname:1.37.0
            name: app1
            ports:
            - protocol: TCP
              containerPort: 50051
    
  2. grpc-td-helloworld.yaml 파일을 적용합니다.

    kubectl apply -f grpc-td-helloworld.yaml
    
  3. helloworld 서비스가 만들어졌는지 확인합니다.

    kubectl get svc -n default
    

    출력은 다음과 비슷합니다.

    NAME           TYPE        CLUSTER-IP   EXTERNAL-IP   PORT (S)   AGE
    helloworld     ClusterIP   10.71.9.71   <none>        8080/TCP  41m
    [..skip..]
    
  4. 애플리케이션 포드가 실행 중인지 확인합니다.

    kubectl get pods -n default
    
  5. 출력 포드는 다음과 비슷하게 표시됩니다.

    NAME                        READY     STATUS    RESTARTS   AGE
    app1-6db459dcb9-zvfg2   1/1       Running   0          6m
    app1-6db459dcb9-hlvhj   1/1       Running   0          6m
    [..skip..]
    

gRPC 서비스 메시 구성

이 섹션에서는 간단한 gRPC 서비스 메시를 구성합니다.

  1. td-grpc-mesh.yaml 파일에 다음 mesh 매니페스트를 저장합니다.

    kind: TDMesh
    apiVersion: net.gke.io/v1alpha1
    metadata:
      name: td-grpc-mesh
      namespace: default
    spec:
      gatewayClassName: gke-td
      allowedRoutes:
        namespaces:
          from: All
        kinds:
        - group: net.gke.io
          kind: TDGRPCRoute
    
  2. mesh 매니페스트를 gke-1에 적용합니다.

    kubectl apply -f td-grpc-mesh.yaml
    

    TDMesh 예시에서는 TDGRPCRoute 리소스만 연결하도록 허용합니다. 매니페스트는 허용되는 경로 유형을 정의합니다.

  3. td-grpc-mesh 메시가 만들어졌는지 확인합니다.

    kubectl describe tdmesh td-grpc-mesh -n default
    

    출력은 다음과 비슷합니다.

    ...
    Status:
      Conditions:
        Last Transition Time:  2022-04-14T22:22:09Z
        Message:
        Reason:                MeshReady
        Status:                True
        Type:                  Ready
        Last Transition Time:  2022-04-14T22:21:41Z
        Message:
        Reason:                Scheduled
        Status:                True
        Type:                  Scheduled
    Events:
      Type    Reason  Age   From                Message
      ----    ------  ----  ----                -------
      Normal  ADD     79s   mc-mesh-controller  Processing mesh default/td-grpc-mesh
      Normal  UPDATE  79s   mc-mesh-controller  Processing mesh default/td-grpc-mesh
      Normal  SYNC    50s   mc-mesh-controller  SYNC on default/td-grpc-mesh was a success
    
  4. helloworld-route.yaml 파일에 다음 매니페스트를 저장합니다.

    kind: TDGRPCRoute
    apiVersion: net.gke.io/v1alpha1
    metadata:
      name: helloworld-route
      namespace: default
    spec:
      parentRefs:
      - name: td-grpc-mesh
        namespace: default
        group: net.gke.io
        kind: TDMesh
      hostnames:
      - helloworld
      rules:
      - backendRefs:
        - name: helloworld
          port: 8080
          namespace: default
    
  5. helloworld-route.yaml 매니페스트를 gke-1에 적용합니다.

    kubectl apply -f helloworld-route.yaml
    
  6. helloworld-route GRPCRoute 리소스가 만들어졌는지 확인합니다.

    kubectl get tdgrpcroute -n default
    

구성 확인

구성 프로세스가 완료되면 프록시리스 gRPC 클라이언트를 사용하여 helloworld gRPC 서버에 연결할 수 있는지 확인합니다. 이 클라이언트는 Cloud Service Mesh에 연결되어 helloworld 서비스에 대한 정보를 확인하고 이 정보를 사용하여 트래픽을 서비스의 백엔드로 전송합니다.

다음 예시에서는 grpcurl 도구를 사용하여 Cloud Service Mesh가 메시에서 트래픽을 올바르게 라우팅하는지 확인할 수 있습니다. 클라이언트 포드를 만든 후 셸을 열고 셸에서 인증 명령어를 실행합니다.

환경 변수 및 부트스트랩 파일 설정

  1. grpc-client.yaml 파일에 다음 포드 매니페스트를 저장합니다.

    apiVersion: v1
    kind: Pod
    metadata:
      name: static-sleeper
      namespace: default
      annotations:
        sidecar.istio.io/inject: "false"
    spec:
      containers:
      - image: curlimages/curl:7.82.0
        imagePullPolicy: IfNotPresent
        name: sleeper
        command:
        - sleep
        - 365d
        env:
        - name: GRPC_XDS_BOOTSTRAP
          value: "/tmp/grpc-xds/td-grpc-bootstrap.json"
        volumeMounts:
        - name: grpc-td-conf
          mountPath: /tmp/grpc-xds/
      initContainers:
      - args:
        - --config-mesh-experimental
        - "gketd-td-grpc-mesh"
        - --output
        - "/tmp/bootstrap/td-grpc-bootstrap.json"
        image: gcr.io/trafficdirector-prod/td-grpc-bootstrap:0.16.0
        imagePullPolicy: IfNotPresent
        name: grpc-td-init
        volumeMounts:
        - name: grpc-td-conf
          mountPath: /tmp/bootstrap/
      volumes:
      - name: grpc-td-conf
        emptyDir:
          medium: Memory
    
  2. gke-1에서 포드 매니페스트를 적용합니다.

    kubectl apply -f grpc-client.yaml
    
  3. 포드가 준비되면 셸을 클라이언트 포드로 엽니다.

    kubectl exec -it static-sleeper -- /bin/sh
    

grpcurl 도구를 프록시리스 gRPC 클라이언트로 사용할 수 있습니다. grpcurl 도구는 환경 변수와 부트스트랩 정보를 사용하여 Cloud Service Mesh에 연결합니다. 그런 다음 이 도구는 Cloud Service Mesh로 구성된 helloworld 서비스에 대해 학습합니다.

grpcurl 도구를 사용하여 구성을 확인하려면 다음 안내를 따르세요.

  1. grpcurl 도구를 다운로드하고 설치합니다.

    cd /home/curl_user
    curl -L https://github.com/fullstorydev/grpcurl/releases/download/v1.8.1/grpcurl_1.8.1_linux_x86_64.tar.gz | tar -xz
    
  2. xds:///helloworld를 서비스 URI로, helloworld.Greeter/SayHello를 호출할 서비스 이름과 메서드로 사용하여 grpcurl 도구를 실행합니다. SayHello 메서드에 대한 매개변수는 -d 옵션을 사용하여 전달합니다.

    ./grpcurl --plaintext \
      -d '{"name": "world"}' \
      xds:///helloworld helloworld.Greeter/SayHello
    

    출력은 다음과 비슷합니다. 여기서 INSTANCE_HOST_NAME은 포드의 호스트 이름입니다.

    Greetings: Hello world, from INSTANCE_HOST_NAME
    

출력은 프록시리스 gRPC 클라이언트가 Cloud Service Mesh에 성공적으로 연결되었고 xds 이름 리졸버를 사용하여 helloworld 서비스의 백엔드에 대해 학습했는지 확인합니다. 클라이언트는 IP 주소 정보를 확인하거나 DNS 변환을 수행할 필요 없이 서비스의 백엔드 중 하나에 요청을 보냈습니다.

다음 단계