LAB 42 ‐ Three Tier Architecture & Setup - gautam-amitesh/OCI GitHub Wiki
In OCI, a three-tier architecture is a logical design that divides an application into three layers: the Presentation Tier, the Application (Logic/Business) Tier, and the Database (Data) Tier. Each tier is isolated within its own subnet inside a VCN. To ensure security and controlled network access, Security Lists, Network Security Groups (NSGs), and Route Tables are configured and applied to the corresponding subnets.
This architecture proposes the creation of two separate application compartments: a HUB compartment for Network and Security Administrators, and a SPOKE compartment for Application Teams and Database Administrators.
Within the HUB compartment, a HUB VCN is created that contains a public subnet hosting a Bastion (Jump) Server. Within the SPOKE compartment, a SPOKE VCN is created that contains the following subnets:
- WEB Subnet (Public Subnet): Responsible for receiving incoming user traffic through the Internet Gateway (IGW), filtering traffic using Load Balancers, delivering UI assets such as HTML, CSS, and JavaScript to users, and routing HTTP/HTTPS requests to the backend application tier.
- APP Subnet (Private Subnet): Responsible for executing business logic using a Compute Instance Pool. Instances in this subnet cannot be accessed directly from the public internet. Administrative access is restricted to the Bastion Server through the DRG, while outbound connectivity for software updates and patching is provided through the NAT Gateway, and private access to OCI services (Object Storage, Vault, Streaming) over Oracle's internal network fabric is provided via Service Gateway.
- DB Subnet (Private Subnet): Responsible for storing and retrieving data using Autonomous Database and Base Database Service. Databases in this subnet accept connections and queries only from the Application Tier, ensuring secure access to backend data resources. To enable private database backups directly to OCI Object Storage and access to OCI Vault for encryption keys without routing through the public internet, Service Gateway is used.
This compartmentalized and tiered design enhances security, simplifies administration, and provides clear separation of responsibilities between networking, security, application, and database teams.
Create Compartments
-
Create the
hub2_compartmentwithin therootcompartment, and create thehub2_network_compartmentandhub2_compute_and_storage_compartmentwithin thehub2_compartment. -
Create the
spoke2_compartmentwithin therootcompartment, and create thespoke2_network_compartmentandspoke2_compute_and_storage_compartmentwithin thespoke2_compartment.
Create VCNs & Subnets
-
Create a
hub2_vcnand apublic_subnetwithin thehub2_network_compartment. -
Create a
spoke2_vcnwith three subnets,web_subnet(public),app_subnet(private), anddb_subnet(private), within thespoke2_network_compartment.
HUB: Create, Configure, and Attach SL
-
Create a security list named
public_subnet-SLfor thepublic_subnetinhub2_vcn. Configure an ingress rule to permit SSH access from a specific IP address and an egress rule allowing all destinations and all protocols. Attach the security list to the subnet and remove the default security list association.
HUB: Create IGW and DRG
-
Create an Internet Gateway named
hub2_vcn-IGWin thehub2_vcnVCN. -
Create a Dynamic Routing Gateway (DRG) named
hub2-spoke2_DRGin thehub2_network_compartment, and then create the corresponding VCN attachments.
HUB: Create, Configure, and Attach RT
-
Create a route table named
public_subnet-RT, configure route rules for both the Internet Gateway and the DRG, and associate the route table with thepublic_subnet.
SPOKE: Create, Configure, and Attach SL
-
Create security lists named
web_subnet-SL,app_subnet-SL, anddb_subnet-SLforweb_subnet,app_subnet, anddb_subnetrespectively inspoke2_vcn. -
In
web_subnet-SLallow inbound TCP connections on port 80 from any source and allow outbound TCP connections to app_subnet on destination port 80. Attach the security list to theweb_subnetand remove the default security list association. -
In
app_subnet-SLallow inbound TCP connections fromweb_subneton port 80, allow inbound SSH access from thepublic_subnetofhub2_vcn, allow inbound TCP connections on port 80 and ICMP connections from thepublic_subnetofhub2_vcn, and an egress rule allowing all destinations and all protocols. Attach the security list to theapp_subnetand remove the default security list association. -
In
db_subnet-SLallow inbound TCP connections from app_subnet on port 1521 and allow outbound TCP connection to All IAD Services In Oracle Services Network on all ports. Attach the security list to thedb_subnetand remove the default security list association.
SPOKE: Create IGW, NAT, and SGW
-
Verify DRG Attachment to VCN and create an Internet Gateway named
spoke2_vcn-IGWin thespoke2_vcnVCN -
Create a NAT Gateway named
spoke2_vcn-NATin thespoke2_vcnVCN -
Create a Service Gateway named
spoke2_vcn-SGWin thespoke2_vcnVCN
SPOKE: Create, Configure, and Attach RT
-
For a standard three-tier SPOKE VCN, only two route tables are typically required: a Public Route Table for the
web_subnetand a Private Route Table for theapp_subnetanddb_subnet. However, to maximize security and completely isolate the database subnet from the public internet, a dedicated route table should be used for the database tier. Create three route tables namedweb_subnet-RT,app_subnet-RT, anddb_subnet-RTfor theweb_subnet,app_subnet, anddb_subnet, respectively. Configure Internet Gateway route rules inweb_subnet-RT, configure NAT Gateway, Service Gateway, and DRG route rules inapp_subnet-RT, and configure only a Service Gateway route rule indb_subnet-RT. Finally, associate each route table with its corresponding subnet:web_subnet-RTwithweb_subnet,app_subnet-RTwithapp_subnet, anddb_subnet-RTwithdb_subnet.