1.18.12. 페더레이션 메시로 서비스 가져오기
서비스를 가져오면 서비스 메시 내에서 다른 메시에서 내보낸 서비스를 명시적으로 지정할 수 있습니다.
![서비스 메시 페더레이션 가져오기 서비스 그림](https://access.redhat.com/webassets/avalon/d/OpenShift_Container_Platform-4.6-Service_Mesh-ko-KR/images/6734470c6e6ae1ee919aa3b9463c0332/ossm-federation-import-service.png)
ImportedServiceSet
리소스를 사용하여 가져올 서비스를 선택합니다. 메시 피어에서 내보내고 명시적으로 가져온 서비스만 메시에 사용할 수 있습니다. 명시적으로 가져오지 않는 서비스는 메시 내에서 사용할 수 없습니다.
- 네임스페이스 또는 이름으로 서비스를 선택할 수 있습니다.
- 예를 들어 와일드카드를 사용하여 서비스를 선택하여 네임스페이스로 내보낸 모든 서비스를 가져올 수 있습니다.
- 메시에 전역적일 수도 있고 특정 멤버 네임스페이스로 범위가 지정된 라벨 선택기를 사용하여 내보내기에 사용할 서비스를 선택할 수 있습니다.
-
별칭을 사용하여 서비스를 가져올 수 있습니다. 예를 들어
custom-ns/bar 서비스를
로 가져올 수 있습니다.other-mesh/bar
-
정규화된 도메인 이름에 대해 가져온 서비스의
name.namespace
에 추가할 사용자 정의 도메인 접미사를 지정할 수 있습니다(예:bar.other-mesh.imported.local
).
다음 예는 red
의 예입니다.
-mesh
에서 내보낸 서비스를 가져오기 위한 green-mesh
ImportedServiceSet의 예
kind: ImportedServiceSet apiVersion: federation.maistra.io/v1 metadata: name: red-mesh #name of mesh that exported the service namespace: green-mesh-system #mesh namespace that service is being imported into spec: importRules: # first matching rule is used # import ratings.bookinfo as ratings.bookinfo - type: NameSelector importAsLocal: false nameSelector: namespace: bookinfo name: ratings alias: # service will be imported as ratings.bookinfo.svc.red-mesh-imports.local namespace: bookinfo name: ratings
매개변수 | 설명 | 값 |
---|---|---|
metadata: name: | 서비스를 연결된 메시에 내보낸 ServiceMeshPeer의 이름입니다. | |
metadata: namespace: | ServiceMeshPeer 리소스(메서드 시스템 네임스페이스)가 포함된 네임스페이스의 이름입니다. | |
spec: importRules: - type: | 서비스의 가져오기를 제어하는 규칙 유형입니다. 서비스에 대해 첫 번째로 일치하는 규칙이 가져오기에 사용됩니다. |
|
spec: importRules: - type: NameSelector nameSelector: namespace: name: |
| |
spec: importRules: - type: NameSelector importAsLocal: |
로컬 서비스가 있는 원격 엔드포인트를 집계하려면 |
|
spec: importRules: - type: NameSelector nameSelector: namespace: name: alias: namespace: name: |
서비스에 대한 별칭을 사용하는 |
red-mesh에서 blue-mesh로 "bookinfo/ratings" 서비스를 가져옵니다.
kind: ImportedServiceSet apiVersion: federation.maistra.io/v1 metadata: name: red-mesh namespace: blue-mesh-system spec: importRules: - type: NameSelector importAsLocal: false nameSelector: namespace: bookinfo name: ratings
red-mesh의 west-data-center 네임스페이스에서 green-mesh로 모든 서비스를 가져옵니다. 이러한 서비스는 <name>.west-data-center.svc.red-mesh-imports.local로 액세스할 수 있습니다.
kind: ImportedServiceSet apiVersion: federation.maistra.io/v1 metadata: name: red-mesh namespace: green-mesh-system spec: importRules: - type: NameSelector importAsLocal: false nameSelector: namespace: west-data-center name: "*"
1.18.12.1. ImportedServiceSet 생성
ImportedServiceSet
리소스를 생성하여 메시로 가져올 서비스를 명시적으로 선언합니다.
서비스는 이름이 <exported-name>.<exported-namespace>.svc.<ServiceMeshPeer.name>.remote
로 가져옵니다. 이 서비스는 송신 게이트웨이 네임스페이스 내에만 표시되며 내보낸 서비스의 호스트 이름과 연결됩니다. 서비스는 <export-name>.<export-namespace>.<domainSuffix>
로 로컬에서 사용할 수 있습니다. 여기서 domainSuffix
는 기본적으로 svc.<ServiceMeshPeer.name>-imports.local
입니다. importAsLocal
을 true
로 설정하지 않는 한 domainSuffix
는 svc.cluster.local
입니다. importAsLocal
을 false로 설정하면
가져오기 규칙의 도메인 접미사가 적용됩니다. 로컬 가져오기를 메시의 다른 서비스와 마찬가지로 처리할 수 있습니다. 내보내기된 서비스의 원격 이름으로 리디렉션되는 송신 게이트웨이를 통해 자동으로 라우팅됩니다.
사전 요구 사항
-
클러스터 및
ServiceMeshControlPlane
은 메시 페더레이션을 위해 구성되었습니다. -
cluster-admin
역할이 있는 계정.
아직 내보낸 적이 없는 경우에도 가져오기 서비스를 구성할 수 있습니다. ImportedServiceSet에 지정된 값과 일치하는 서비스가 배포되고 내보내면 자동으로 가져옵니다.
CLI의 프로세스
다음 절차에 따라 명령줄에서 ImportedServiceSet
을 생성합니다.
cluster-admin
역할의 사용자로 OpenShift Container Platform CLI에 로그인합니다. 다음 명령을 입력합니다. 메시지가 표시되면 사용자 이름과 암호를 입력합니다.$ oc login --username=<NAMEOFUSER> <API token> https://<HOSTNAME>:6443
Service Mesh Control Plane을 설치한 프로젝트(예:
green-mesh-system
)로 변경합니다.$ oc project green-mesh-system
다음 예제를 기반으로
ImportedServiceSet
파일을 만듭니다. 여기서green-mesh
가 이전에red-mesh
에서 내보낸 서비스를 가져옵니다.red-mesh에서 green-mesh로 ImportedServiceSet 리소스의 예
kind: ImportedServiceSet apiVersion: federation.maistra.io/v1 metadata: name: red-mesh namespace: green-mesh-system spec: importRules: - type: NameSelector importAsLocal: false nameSelector: namespace: bookinfo name: red-ratings alias: namespace: bookinfo name: ratings
다음 명령을 실행하여 green-mesh-system 네임스페이스에
ImportedServiceSet
리소스를 업로드하고 만듭니다.$ oc create -n <ControlPlaneNamespace> -f <ImportedServiceSet.yaml>
예를 들면 다음과 같습니다.
$ oc create -n green-mesh-system -f import-from-red-mesh.yaml
-
페더레이션 메시의 각 메시 피어에 필요한 대로 추가로
ImportedServiceSet
리소스를 만듭니다. 가져온 서비스를
녹색 메시로 확인하려면 다음 명령을 실행합니다
.$ oc get importedserviceset <PeerMeshImportedInto> -o yaml
예를 들면 다음과 같습니다.
$ oc get importedserviceset green-mesh -o yaml
다음 명령을 실행하여 메시로 가져온 서비스의 유효성을 검사합니다.
$ oc get importedserviceset <PeerMeshImportedInto> -o yaml
'green-mesh-system 네임스페이스에서 importserviceset/red-mesh' 오브젝트의 status 섹션을 사용하여 빨간색 메시에서 내보낸 서비스를 녹색 메시로 가져왔는지 검증의
예는 다음과 같습니다.$ oc -n green-mesh-system get importedserviceset/red-mesh -o yaml
status: importedServices: - exportedName: red-ratings.bookinfo.svc.green-mesh-exports.local localService: hostname: ratings.bookinfo.svc.red-mesh-imports.local name: ratings namespace: bookinfo - exportedName: reviews.red-mesh-bookinfo.svc.green-mesh-exports.local localService: hostname: "" name: "" namespace: ""
앞의 예제에서는
localService
아래의 채워진 필드에 표시된 대로 ratings 서비스만 가져옵니다. Review 서비스는 가져오기에 사용할 수 있지만ImportedServiceSet
오브젝트의importRules
와 일치하지 않기 때문에 현재는 가져오지 않습니다.