
오라클 클라우드에서 계정(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 이미지도 있어서 다운받아서 사용할 수 있다.

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
귀찮은 작업은 커맨드가 해주지만, 계정 정보를 입력해줘야 동작한다.
계정(Tenancy)가 달라도 상관없다. Region이 같은 연결할 두개의 VCN이 필요하다.
두 VCN의 OCID는 아래 사진의 OCID 위치를 참고하면 얻을 수 있다.
연결하고자 하는 두 VCN에서 모든 subnet들의 CIDR이 겹치면 안된다.
설정 없이 생성하면 10.0.0.0/16이 기본값으로 잡히기 때문에 둘 중 하나의 CIDR를 바꿔야한다.
아래 사진에서 보이는 CIDR값이 달라야한다.

자동화 커맨드가 API를 통해서 조작하려면 API Key가 필요하다.
공식 문서를 참고하면 API Key를 추가하고 설정값을 가져올 수 있다.
먼저 첫번째 계정에서 아래 사진 화면일 때 Generate API Key Pair로 인증서 생성 후에 public key를 다운받고, 두번째 계정에서는 Choose Public Key File로 첫번째 계정에서 받은 public key를 업로드하면된다.

하나의 LPG가 다른 LPG에 연결을 요청하면, 요청을 받는 쪽에서 수락해야 연결이 만들어진다.
requestor: 연결을 요청하는 쪽acceptor: 연결을 수락하는 쪽VCN: http://taewan.kim/oci_docs/10_quickstart/vcn/Route Table: https://docs.oracle.com/en-us/iaas/Content/Network/Tasks/managingroutetables.htmusage: 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~/.oci/config 파일이다--requestor-vcn-ocidocid1.vcn.oc1.ap-seoul-1.jnladfnl,,, 같은 형태이다peer_oracle_vcn list_vcn으로 profile에 있는 VCN 이름과 OCID를 확인할 수 있다--acceptor-vcn-ocid--requestor-vcn-ocid와 동일함--requestor-group-ocidpeer_oracle_vcn list_group으로 profile이 속한 Group 이름과 OCID를 확인할 수 있다--requestor-route-table-ocidpeer_oracle_vcn list_route_table으로 profile이 속한 Route Table 이름과 OCID를 확인할 수 있다--acceptor-route-table-ocid--requestor-route-table-ocid와 동일함--requestor-cidr--acceptor-cidr--requestor-cidr와 동일하다--requestor-profile, --acceptor-profile--api-config-file 파일에서 각각 Requestor와 Acceptor의 profile 이름모두 필수 파라미터인데, 자동으로 입력해주는 것들이 있으니 일단 아래 커맨드로 실행해보고 에러가 나면 이유를 보고 파라미터를 입력해보자
~/.oci에 저장함~/.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
위의 가정과 맞지 않다면 에러가 발생할것이고, 에러 메시지를 보고 필요한 파라미터를 설정해주면 된다.
Free-tier는 계정내 VCN 개수 제한이 1이라서 테스트해보지는 못했다.
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과 대부분 동일하다. 대신 자동으로 값을 채워주는 기능은 없고, 모든 파라미터값을 꼭 채워줘야한다.