1.18.12. 페더레이션 메시로 서비스 가져오기
서비스를 가져오면 서비스 메시 내에서 다른 메시에서 내보낸 서비스를 명시적으로 지정할 수 있습니다.
ImportedServiceSet 리소스를 사용하여 가져오기 서비스를 선택합니다. 메시 피어에서 내보낸 서비스만 메시에서 명시적으로 가져올 수 있습니다. 명시적으로 가져오지 않는 서비스는 메시 내에서 사용할 수 없습니다.
- 네임스페이스 또는 이름별로 서비스를 선택할 수 있습니다.
- 와일드카드를 사용하여 서비스를 선택할 수 있습니다(예: 네임스페이스로 내보낸 모든 서비스를 가져올 수 있습니다.
- 레이블 선택기를 사용하여 내보내기를 위한 서비스를 선택할 수 있습니다. 이 서비스는 메시에 전역적으로 적용되거나 특정 멤버 네임스페이스로 범위가 지정될 수 있습니다.
-
별칭을 사용하여 서비스를 가져올 수 있습니다. 예를 들어
custom-ns/bar서비스를other-mesh/bar로 가져올 수 있습니다. -
사용자 정의 도메인 접미사를 지정할 수 있습니다. 이 접미사는 정규화된 도메인 이름에 대해 가져온 서비스의
name.namespace에 추가됩니다(예:bar.other-mesh.imported.local).
다음 예제는 green-mesh 에서 red-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:
|
서비스에 대한 별칭을 사용하는 |
빨간색-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에 지정된 값과 일치하는 서비스가 배포되고 내보내지면 자동으로 가져옵니다.
프로세스
명령줄에서 ImportedServiceSet 을 생성하려면 다음 절차를 따르십시오.
cluster-admin역할의 사용자로 AWS CLI에서 Red Hat OpenShift Service에 로그인합니다. 다음 명령을 입력합니다. 메시지가 표시되면 사용자 이름과 암호를 입력합니다.$ oc login --username=<NAMEOFUSER> <API token> https://<HOSTNAME>:6443Service Mesh Control Plane을 설치한 프로젝트(예:
green-mesh-system)로 변경합니다.$ oc project green-mesh-systemgreen-mesh가 이전에red-mesh에서 내보낸 서비스를 가져오는 다음 예제를 기반으로ImportedServiceSet파일을 만듭니다.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리소스를 생성합니다.
검증
다음 명령을 실행하여 서비스가
green-mesh로 가져왔는지 확인합니다.$ oc get importedserviceset <PeerMeshImportedInto> -o yaml예를 들어, 빨간색 메시에서 내보낸 서비스가 'green-mesh-
system 네임 스페이스에서 importedserviceset/red-mesh' 오브젝트의 status 섹션을 사용하여 녹색 메시로 가져왔는지 확인하는 예$ oc -n green-mesh-system get importedserviceset/red-mesh -o yamlstatus: 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 서비스만 가져옵니다. reviews 서비스는 가져오기에 사용할 수 있지만ImportedServiceSet오브젝트의importRules와 일치하지 않기 때문에 현재 가져온 것은 아닙니다.