자동으로 오라클 클라우드에서 계정간 네트워크 공유 설정하기

Byeonghoon Yoo·2021년 8월 23일
1

oci

목록 보기
1/1
post-thumbnail

오라클 클라우드에서 계정(Tenancy)간 혹은 같은 계정이라도 VCN이 다르다면 Private IP로 통신할 수 없다.
물론 (임시) Public IP를 할당받아서 통신할 수 있지만, Kubernetes Cluster를 만드는 것 같이 Private IP로 통신하는게 필요한 경우가 있다.

VCN이 다르면 당연히 Private IP로 통신할 수 없지만, LPG (Local Peering Gateway)를 사용하면 가능해진다.
단 이름부터 Local이기 때문에 같은 Region이어야지만 가능하다. Region이 다르다면 DRG(Dynamic Routing Gateway)를 사용해야한다.

유료 유저라면 더 빠르고 SLO가 보장되는 연결 방법도 있지만, 평생 무료 유저에게는 LPG가 유일한 방법이다.

LPG 공식 가이드 문서를 따라하면 구축할 수 있긴한데, 단계가 많고 여러 페이지를 오가야해서 귀찮다.
그래서 두 계정 정보를 입력하면 자동으로 LPG를 만들고 연결해주는 커맨드를 만들었다. Docker 이미지도 있어서 다운받아서 사용할 수 있다.

LPG 구성 예시

TL;DR

https://github.com/isac322/connect_oracle_vcn

docker run --rm -v ~/.oci:/root/.oci:ro -ti isac322/peer_oracle_vcn \
	lpg_inter_tenant \
	--requestor-profile profile1 \
	--acceptor-profile profile2

준비물

귀찮은 작업은 커맨드가 해주지만, 계정 정보를 입력해줘야 동작한다.

두개의 VCN

계정(Tenancy)가 달라도 상관없다. Region이 같은 연결할 두개의 VCN이 필요하다.
두 VCN의 OCID는 아래 사진의 OCID 위치를 참고하면 얻을 수 있다.

주의

연결하고자 하는 두 VCN에서 모든 subnet들의 CIDR이 겹치면 안된다.
설정 없이 생성하면 10.0.0.0/16이 기본값으로 잡히기 때문에 둘 중 하나의 CIDR를 바꿔야한다.

아래 사진에서 보이는 CIDR값이 달라야한다.

API Key와 OCID들 가져오기

자동화 커맨드가 API를 통해서 조작하려면 API Key가 필요하다.
공식 문서를 참고하면 API Key를 추가하고 설정값을 가져올 수 있다.

계정간 인증서 공유

먼저 첫번째 계정에서 아래 사진 화면일 때 Generate API Key Pair로 인증서 생성 후에 public key를 다운받고, 두번째 계정에서는 Choose Public Key File로 첫번째 계정에서 받은 public key를 업로드하면된다.

실행

용어 정리

하나의 LPG가 다른 LPG에 연결을 요청하면, 요청을 받는 쪽에서 수락해야 연결이 만들어진다.

다른 계정(tenant)간 연결

Command Usage:

usage: peer_oracle_vcn lpg_inter_tenant [-h] [--api-config-file API_CONFIG_FILE] [--requestor-vcn-ocid REQUESTOR_VCN_OCID] [--acceptor-vcn-ocid ACCEPTOR_VCN_OCID] [--requestor-group-ocid REQUESTOR_GROUP_OCID] [--requestor-route-table-ocid REQUESTOR_ROUTE_TABLE_OCID]
                                        [--acceptor-route-table-ocid ACCEPTOR_ROUTE_TABLE_OCID] --requestor-cidr REQUESTOR_CIDR --acceptor-cidr ACCEPTOR_CIDR --requestor-profile REQUESTOR_PROFILE --acceptor-profile ACCEPTOR_PROFILE

optional arguments:
  -h, --help            show this help message and exit
  --api-config-file API_CONFIG_FILE
                        OCI API config file path
  --requestor-vcn-ocid REQUESTOR_VCN_OCID
                        VCN OCID of requestor
  --acceptor-vcn-ocid ACCEPTOR_VCN_OCID
                        VCN OCID of acceptor
  --requestor-group-ocid REQUESTOR_GROUP_OCID
                        Group OCID of requestor
  --requestor-route-table-ocid REQUESTOR_ROUTE_TABLE_OCID
                        Route Table OCID of requestor to register LGP
  --acceptor-route-table-ocid ACCEPTOR_ROUTE_TABLE_OCID
                        Route Table OCID of acceptor to register LGP
  --requestor-cidr REQUESTOR_CIDR
                        CIDR of requestor to add acceptor's Route Table
  --acceptor-cidr ACCEPTOR_CIDR
                        CIDR of acceptor to add requestor's Route Table
  --requestor-profile REQUESTOR_PROFILE
  --acceptor-profile ACCEPTOR_PROFILE
  • --api-config-file
    • API Key 추가를 했다면 보통 ~/.oci/config 파일이다
  • --requestor-vcn-ocid
    • Requestor LPG가 속하는 VCN의 OCID
    • 보통 ocid1.vcn.oc1.ap-seoul-1.jnladfnl,,, 같은 형태이다
    • Requestor profile에 VCN이 하나밖에 없다면 입력하지 않아도 자동으로 찾아준다
    • peer_oracle_vcn list_vcn으로 profile에 있는 VCN 이름과 OCID를 확인할 수 있다
  • --acceptor-vcn-ocid
    • Acceptor LPG가 속하는 VCN의 OCID
    • 나머지는 --requestor-vcn-ocid와 동일함
  • --requestor-group-ocid
    • Requestor가 Acceptor LPG 접근 요청을할 때 필요함
    • Requestor profile에 Group이 하나밖에 없다면 입력하지 않아도 자동으로 찾아준다
    • peer_oracle_vcn list_group으로 profile이 속한 Group 이름과 OCID를 확인할 수 있다
  • --requestor-route-table-ocid
    • LPG 생성과 연결 이후 Route Table에 등록을해야 Instance가 통신이 가능하다. 등록할 Route Table의 OCID
    • Requestor profile에 Route Table 하나밖에 없다면 입력하지 않아도 자동으로 찾아준다
    • peer_oracle_vcn list_route_table으로 profile이 속한 Route Table 이름과 OCID를 확인할 수 있다
  • --acceptor-route-table-ocid
    • LPG이 등록될 Acceptor의 Route Table OCID
    • 나머지는 --requestor-route-table-ocid와 동일함
  • --requestor-cidr
    • Acceptor의 Route Table에 등록될 Requestor의 CIDR
    • Requestor VCN에 CIDR block이 하나밖에 없다면 입력하지 않아도 자동으로 찾아준다
  • --acceptor-cidr
    • Requestor의 Route Table에 등록될 Acceptor의 CIDR
    • 나머지는 --requestor-cidr와 동일하다
  • --requestor-profile, --acceptor-profile
    • --api-config-file 파일에서 각각 Requestor와 Acceptor의 profile 이름

모두 필수 파라미터인데, 자동으로 입력해주는 것들이 있으니 일단 아래 커맨드로 실행해보고 에러가 나면 이유를 보고 파라미터를 입력해보자

사용법

가정
  • OCI API key는 ~/.oci에 저장함
  • requestor profile이름: req_profile
  • acceptor profile이름: act_profile
  • requestor, acceptor 모두 하나의 VCN만 보유
  • 두 VCN에는 각각 하나의 CIDR만 존재
  • 두 VCN에는 각각 하나의 Route Table만 존재

~/.oci/config 예시:

[req_profile]
user=ocid1.user.oc1..aaaaatestid1
fingerprint=xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
tenancy=ocid1.tenancy.oc1..aaaatestid1
region=ap-seoul-1
key_file=/home/ubuntu/.oci/api_key.pem

[act_profile]
user=ocid1.user.oc1..aaaaatestid2
fingerprint=xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
tenancy=ocid1.tenancy.oc1..aaaatestid2
region=ap-seoul-1
key_file=/home/ubuntu/.oci/api_key.pem
커맨드
sudo docker run --rm -v ~/.oci:/root/.oci:ro -ti isac322/peer_oracle_vcn \
	lpg_inter_tenant \
	--requestor-profile req_profile \
	--acceptor-profile act_profile

위의 가정과 맞지 않다면 에러가 발생할것이고, 에러 메시지를 보고 필요한 파라미터를 설정해주면 된다.

같은 계정(tenant)내 연결

Free-tier는 계정내 VCN 개수 제한이 1이라서 테스트해보지는 못했다.

Command Usage:

usage: peer_oracle_vcn lpg_intra_tenant [-h] [--api-config-file API_CONFIG_FILE] [--profile PROFILE] --requestor-vcn-ocid REQUESTOR_VCN_OCID --acceptor-vcn-ocid ACCEPTOR_VCN_OCID --requestor-group-ocid REQUESTOR_GROUP_OCID --requestor-route-table-ocid REQUESTOR_ROUTE_TABLE_OCID --acceptor-route-table-ocid
                                        ACCEPTOR_ROUTE_TABLE_OCID --requestor-cidr REQUESTOR_CIDR --acceptor-cidr ACCEPTOR_CIDR

optional arguments:
  -h, --help            show this help message and exit
  --api-config-file API_CONFIG_FILE
                        OCI API config file path
  --profile PROFILE
  --requestor-vcn-ocid REQUESTOR_VCN_OCID
                        VCN OCID of requestor
  --acceptor-vcn-ocid ACCEPTOR_VCN_OCID
                        VCN OCID of acceptor
  --requestor-group-ocid REQUESTOR_GROUP_OCID
                        Group OCID of requestor
  --requestor-route-table-ocid REQUESTOR_ROUTE_TABLE_OCID
                        Route Table OCID of requestor to register LGP
  --acceptor-route-table-ocid ACCEPTOR_ROUTE_TABLE_OCID
                        Route Table OCID of acceptor to register LGP
  --requestor-cidr REQUESTOR_CIDR
                        CIDR of requestor to add acceptor's Route Table
  --acceptor-cidr ACCEPTOR_CIDR
                        CIDR of acceptor to add requestor's Route Table

lpg_inter_tenant과 대부분 동일하다. 대신 자동으로 값을 채워주는 기능은 없고, 모든 파라미터값을 꼭 채워줘야한다.

0개의 댓글