1.18.11. 페더레이션 메시에서 서비스 내보내기
서비스 내보내기를 통해 메시는 하나 이상의 서비스를 페더레이션 메시의 다른 멤버와 공유할 수 있습니다.
ExportedServiceSet 리소스를 사용하여 페더레이션 메시의 다른 피어에 사용할 수 있는 하나의 메시에서 서비스를 선언합니다. 피어와 공유하려면 각 서비스를 명시적으로 선언해야 합니다.
- 네임스페이스 또는 이름별로 서비스를 선택할 수 있습니다.
- 와일드카드를 사용하여 서비스를 선택할 수 있습니다(예: 네임스페이스의 모든 서비스를 내보내려면).
-
별칭을 사용하여 서비스를 내보낼 수 있습니다. 예를 들어
foo/bar서비스를custom-ns/bar로 내보낼 수 있습니다. -
메시의 시스템 네임스페이스에 표시되는 서비스만 내보낼 수 있습니다. 예를 들어
networking.istio.io/exportTo레이블이 '.'로 설정된 다른 네임스페이스의 서비스는 내보내기 후보가 아닙니다. - 내보낸 서비스의 경우 대상 서비스는 원래 요청자가 아닌 수신 게이트웨이의 트래픽만 볼 수 있습니다(즉, 다른 메시의 송신 게이트웨이 또는 워크로드 또는 요청의 클라이언트 ID를 볼 수 없음).
다음 예제는 red-mesh 가 green-mesh 로 내보내는 서비스에 대한 것입니다.
ExportedServiceSet 리소스의 예
kind: ExportedServiceSet
apiVersion: federation.maistra.io/v1
metadata:
name: green-mesh
namespace: red-mesh-system
spec:
exportRules:
# export ratings.mesh-x-bookinfo as ratings.bookinfo
- type: NameSelector
nameSelector:
namespace: red-mesh-bookinfo
name: red-ratings
alias:
namespace: bookinfo
name: ratings
# export any service in red-mesh-bookinfo namespace with label export-service=true
- type: LabelSelector
labelSelector:
namespace: red-mesh-bookinfo
selector:
matchLabels:
export-service: "true"
aliases: # export all matching services as if they were in the bookinfo namespace
- namespace: "*"
name: "*"
alias:
namespace: bookinfo
| 매개변수 | 설명 | 값 |
|---|---|---|
metadata:
name:
| 이 서비스를 노출하는 ServiceMeshPeer의 이름입니다. |
|
metadata:
namespace:
| 이 리소스가 포함된 프로젝트/네임스페이스의 이름(메쉬의 시스템 네임스페이스여야 함) | |
spec:
exportRules:
- type:
| 이 서비스의 내보내기를 제어하는 규칙 유형입니다. 서비스에 대해 발견된 첫 번째 일치 규칙이 내보내기에 사용됩니다. |
|
spec:
exportRules:
- type: NameSelector
nameSelector:
namespace:
name:
|
| |
spec:
exportRules:
- type: NameSelector
nameSelector:
alias:
namespace:
name:
|
서비스에 대한 별칭을 사용하는 | |
spec:
exportRules:
- type: LabelSelector
labelSelector:
namespace: <exportingMesh>
selector:
matchLabels:
<labelKey>: <labelValue>
|
| |
spec:
exportRules:
- type: LabelSelector
labelSelector:
namespace: <exportingMesh>
selector:
matchLabels:
<labelKey>: <labelValue>
aliases:
- namespace:
name:
alias:
namespace:
name:
|
서비스에 대한 별칭을 사용하는 |
이름이 "ratings"인 서비스를 빨간색-mesh에 있는 모든 네임스페이스에서 blue-mesh로 내보냅니다.
kind: ExportedServiceSet
apiVersion: federation.maistra.io/v1
metadata:
name: blue-mesh
namespace: red-mesh-system
spec:
exportRules:
- type: NameSelector
nameSelector:
namespace: "*"
name: ratings
west-data-center 네임스페이스의 모든 서비스를 green-mesh로 내보냅니다.
kind: ExportedServiceSet
apiVersion: federation.maistra.io/v1
metadata:
name: green-mesh
namespace: red-mesh-system
spec:
exportRules:
- type: NameSelector
nameSelector:
namespace: west-data-center
name: "*"
1.18.11.1. ExportedServiceSet 생성 링크 복사링크가 클립보드에 복사되었습니다!
ExportedServiceSet 리소스를 생성하여 메시 피어에서 사용할 수 있는 서비스를 명시적으로 선언합니다.
서비스는 <export-name>.<export-namespace>.svc.<ServiceMeshPeer.name>-exports.local로 내보내지며 대상 서비스로 자동으로 라우팅됩니다. 내보낸 서비스는 내보낸 메시에서 알려진 이름입니다. 수신 게이트웨이가 이 이름에 대한 요청을 수신하면 내보낼 실제 서비스로 라우팅됩니다. 예를 들어 ratings.red-mesh-bookinfo 라는 서비스가 ratings.bookinfo 로 green-mesh 로 내보내지면 서비스는 ratings.bookinfo.svc.green-mesh-exports.local 에서 내보내지고 해당 호스트 이름에 대해 수신 게이트웨이에서 수신한 트래픽이 ratings.red-mesh-bookinfo 서비스로 라우팅됩니다.
로컬 서비스와 함께 원격 끝점을 집계하려면 importAsLocal 매개변수를 true 로 설정하면 서비스에 대한 별칭을 사용해야 합니다. 매개변수를 false 로 설정하면 별칭이 필요하지 않습니다.
사전 요구 사항
-
메시 페더레이션을 위해 클러스터 및
ServiceMeshControlPlane이 구성되어 있습니다. -
cluster-admin역할이 있는 계정.
아직 존재하지 않는 경우에도 내보내기를 위해 서비스를 구성할 수 있습니다. ExportedServiceSet에 지정된 값과 일치하는 서비스가 배포되면 자동으로 내보내집니다.
CLI의 프로세스
명령줄에서 ExportedServiceSet 을 생성하려면 다음 절차를 따르십시오.
cluster-admin역할의 사용자로 AWS CLI에서 Red Hat OpenShift Service에 로그인합니다. 다음 명령을 입력합니다. 메시지가 표시되면 사용자 이름과 암호를 입력합니다.$ oc login --username=<NAMEOFUSER> <API token> https://<HOSTNAME>:6443Service Mesh Control Plane을 설치한 프로젝트(예:
red-mesh-system)로 변경합니다.$ oc project red-mesh-systemred-mesh가green-mesh로 서비스를 내보내는 다음 예제를 기반으로ExportedServiceSet파일을 만듭니다.red-mesh에서 green-mesh로 ExportedServiceSet 리소스의 예
apiVersion: federation.maistra.io/v1 kind: ExportedServiceSet metadata: name: green-mesh namespace: red-mesh-system spec: exportRules: - type: NameSelector nameSelector: namespace: red-mesh-bookinfo name: ratings alias: namespace: bookinfo name: red-ratings - type: NameSelector nameSelector: namespace: red-mesh-bookinfo name: reviews다음 명령을 실행하여 red-mesh-system 네임스페이스에
ExportedServiceSet리소스를 업로드하고 생성합니다.$ oc create -n <ControlPlaneNamespace> -f <ExportedServiceSet.yaml>예를 들면 다음과 같습니다.
$ oc create -n red-mesh-system -f export-to-green-mesh.yaml-
페더레이션 메시의 각 메시 피어에 대해 필요에 따라 추가
ExportedServiceSets를 생성합니다.
검증
다음 명령을 실행하여 green-mesh와 공유할 red-mesh 내보내기를 서비스에 검증합니다.
$ oc get exportedserviceset <PeerMeshExportedTo> -o yaml예를 들면 다음과 같습니다.
$ oc -n red-mesh-system get exportedserviceset green-mesh -o yaml녹색 메시와 공유되는 빨간색 메시에서 내보낸 서비스 검증의 예.
status: exportedServices: - exportedName: red-ratings.bookinfo.svc.green-mesh-exports.local localService: hostname: ratings.red-mesh-bookinfo.svc.cluster.local name: ratings namespace: red-mesh-bookinfo - exportedName: reviews.red-mesh-bookinfo.svc.green-mesh-exports.local localService: hostname: reviews.red-mesh-bookinfo.svc.cluster.local name: reviews namespace: red-mesh-bookinfostatus.exportedServices배열은 현재 내보낸 서비스(ExportedServiceSet 오브젝트의 내보내기 규칙과 일치)를 나열합니다. 배열의 각 항목은 내보낸 서비스의 이름과 내보낸 로컬 서비스에 대한 세부 정보를 나타냅니다.내보낸 서비스가 누락된 경우 Service 오브젝트가 있는지, 해당 이름 또는 레이블이
ExportedServiceSet오브젝트에 정의된exportRules와 일치하며 Service 오브젝트의 네임스페이스가ServiceMeshMemberRoll또는ServiceMeshMember오브젝트를 사용하여 서비스 메시의 멤버로 구성되어 있는지 확인합니다.