Skip to content

Commit 8426404

Browse files
authored
Merge pull request #31 from junior/example-using-existent-network
Example using existent network
2 parents 0361416 + f2cfcb1 commit 8426404

16 files changed

+236
-98
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $${\color{red}OKE \space Cluster \space deployment \space yet.}$$
1818

1919
This module handles opinionated Oracle Container Engine for [Kubernetes][kubernetes_101] ([OKE][oke]) cluster creation on Oracle Cloud Infrastructure ([OCI][oci]). This module is designed to be used with the [OCI Resource Manager][oci_rm] to deploy a cluster in a single step. The module can also be used with the [OCI Terraform Provider][oci_tf_provider] to deploy a cluster using local or CloudShell Terraform cli.
2020

21-
>Note: This project is an alternative to easily create an OKE cluster without the need to use external workarounds and do not need to create compute bastions or jump servers, even if deploying using private endpoints. This is a __NO__(`null_resource` ,`remote_exec`, `operator instance`, `bastion_or_jump_server`, `out_of_tf_state_sh_scripts`) project
21+
>__Note__: This project is an alternative to easily create an OKE cluster without the need to use external workarounds and do not need to create compute bastions or jump servers, even if deploying using private endpoints. This is a __NO__(`null_resource` ,`remote_exec`, `operator instance`, `bastion_or_jump_server`, `out_of_tf_state_sh_scripts`) project
2222
2323
Sub modules are provided to create a cluster with a single node pool, or a cluster with multiple node pools. Enables Cluster Autoscaler, OCI Vault(KMS) for customer-managed encryption keys for secrets, block volumes. The module also provides a sub module to create a cluster with a single node pool and a private endpoint to Oracle Resource Manager (ORM).
2424

@@ -75,7 +75,7 @@ module "oke-quickstart" {
7575

7676
## Deploy Using Oracle Resource Manager
7777

78-
> **_NOTE:_** If you aren't already signed in, when prompted, enter the tenancy and user credentials. Review and accept the terms and conditions.
78+
> ___NOTE:___ If you aren't already signed in, when prompted, enter the tenancy and user credentials. Review and accept the terms and conditions.
7979
8080
1. Click to deploy the stack
8181

@@ -103,7 +103,7 @@ Note: An example [tfvars file](examples/terraform.tfvars.example) is included fo
103103
preferred way to run the stack from the CLI, because of the large number of variables to manage.
104104

105105
To use this file just copy the example [tfvars file](examples/terraform.tfvars.example) and save it in the outermost directory.
106-
Next, rename the file to **terraform.tfvars**. You can override the example values set in this file.
106+
Next, rename the file to __terraform.tfvars__. You can override the example values set in this file.
107107

108108
### Clone the Module
109109

@@ -139,7 +139,7 @@ terraform destroy -refresh=false
139139

140140
## Terraform Variables
141141

142-
A complete listing of the Terraform variables used in this stack are referenced [here](VARIABLES.md).
142+
A complete listing of the Terraform variables used in this stack are referenced [here](VARIABLES.md).
143143
<!-- This document is automatically generated
144144
using the [terraform-docs](https://github.com/terraform-docs/terraform-docs) with the following command:
145145

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.12
1+
0.8.15

defaults.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2022-2023 Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33
#
44

@@ -42,7 +42,7 @@ locals {
4242
node_pools = concat(local.node_pool_1, local.extra_node_pools, var.extra_node_pools)
4343
create_new_vcn = (var.create_new_oke_cluster && var.create_new_vcn) ? true : false
4444
vcn_display_name = "[${local.app_name}] VCN for OKE (${local.deploy_id})"
45-
create_subnets = (var.create_new_oke_cluster || var.create_subnets) ? true : false
45+
create_subnets = (var.create_subnets) ? true : false
4646
subnets = concat(local.subnets_oke, local.extra_subnets, var.extra_subnets)
4747
route_tables = concat(local.route_tables_oke, var.extra_route_tables)
4848
security_lists = concat(local.security_lists_oke, var.extra_security_lists)

examples/5G-NF-Infra/networking.tf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ resource "oci_core_vnic_attachment" "vnic_attachment_5gc_signalling" {
301301
defined_tags = {}
302302
freeform_tags = { "Network" : "5GC-Signalling" }
303303
}
304-
display_name = "5GC-Signalling vnic Attachment"
305-
instance_id = data.oci_containerengine_node_pool.node_pool_1.nodes[count.index].id
304+
display_name = "5GC-Signalling vnic Attachment"
305+
instance_id = data.oci_containerengine_node_pool.node_pool_1.nodes[count.index].id
306306
}
307307
resource "oci_core_vnic_attachment" "vnic_attachment_5gc_oam" {
308308
count = var.node_pool_initial_num_worker_nodes_1
@@ -313,8 +313,8 @@ resource "oci_core_vnic_attachment" "vnic_attachment_5gc_oam" {
313313
defined_tags = {}
314314
freeform_tags = { "Network" : "5GC-OAM" }
315315
}
316-
display_name = "5GC-OAM vnic Attachment"
317-
instance_id = data.oci_containerengine_node_pool.node_pool_1.nodes[count.index].id
316+
display_name = "5GC-OAM vnic Attachment"
317+
instance_id = data.oci_containerengine_node_pool.node_pool_1.nodes[count.index].id
318318

319319
depends_on = [oci_core_vnic_attachment.vnic_attachment_5gc_signalling]
320320
}
@@ -327,8 +327,8 @@ resource "oci_core_vnic_attachment" "vnic_attachment_5g_ran" {
327327
defined_tags = {}
328328
freeform_tags = { "Network" : "5G RAN" }
329329
}
330-
display_name = "5G RAN vnic Attachment"
331-
instance_id = data.oci_containerengine_node_pool.node_pool_1.nodes[count.index].id
330+
display_name = "5G RAN vnic Attachment"
331+
instance_id = data.oci_containerengine_node_pool.node_pool_1.nodes[count.index].id
332332

333333
depends_on = [oci_core_vnic_attachment.vnic_attachment_5gc_oam]
334334
}
@@ -341,8 +341,8 @@ resource "oci_core_vnic_attachment" "vnic_attachment_5g_legal_intercept" {
341341
defined_tags = {}
342342
freeform_tags = { "Network" : "5G Legal Intercept" }
343343
}
344-
display_name = "5G Legal Intercept vnic Attachment"
345-
instance_id = data.oci_containerengine_node_pool.node_pool_1.nodes[count.index].id
344+
display_name = "5G Legal Intercept vnic Attachment"
345+
instance_id = data.oci_containerengine_node_pool.node_pool_1.nodes[count.index].id
346346

347347
depends_on = [oci_core_vnic_attachment.vnic_attachment_5g_ran]
348348
}
@@ -355,8 +355,8 @@ resource "oci_core_vnic_attachment" "vnic_attachment_5g_epc" {
355355
defined_tags = {}
356356
freeform_tags = { "Network" : "5G-EPC" }
357357
}
358-
display_name = "5G-EPC vnic Attachment"
359-
instance_id = data.oci_containerengine_node_pool.node_pool_1.nodes[count.index].id
358+
display_name = "5G-EPC vnic Attachment"
359+
instance_id = data.oci_containerengine_node_pool.node_pool_1.nodes[count.index].id
360360

361361
depends_on = [oci_core_vnic_attachment.vnic_attachment_5g_legal_intercept]
362362
}

examples/basic-cluster/oke.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
15
module "oke-quickstart" {
2-
source = "github.com/oracle-quickstart/terraform-oci-oke-quickstart?ref=0.8.3"
6+
source = "github.com/oracle-quickstart/terraform-oci-oke-quickstart?ref=0.8.15"
37

48
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
59
tenancy_ocid = var.tenancy_ocid
@@ -22,4 +26,4 @@ module "oke-quickstart" {
2226

2327
# VCN for OKE arguments
2428
vcn_cidr_blocks = "10.22.0.0/16"
25-
}
29+
}

examples/basic-cluster/providers.tf

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ terraform {
99
source = "oracle/oci"
1010
version = "~> 4, < 5"
1111
# https://registry.terraform.io/providers/oracle/oci/
12-
configuration_aliases = [oci.home_region, oci.current_region]
1312
}
1413
kubernetes = {
1514
source = "hashicorp/kubernetes"
@@ -38,65 +37,3 @@ terraform {
3837
}
3938
}
4039
}
41-
42-
# provider "oci" {
43-
# tenancy_ocid = var.tenancy_ocid
44-
# region = var.region
45-
# }
46-
47-
# provider "oci" {
48-
# alias = "home_region"
49-
# tenancy_ocid = var.tenancy_ocid
50-
# region = lookup(data.oci_identity_regions.home_region.regions[0], "name")
51-
52-
# user_ocid = var.user_ocid
53-
# fingerprint = var.fingerprint
54-
# private_key_path = var.private_key_path
55-
# }
56-
57-
# provider "oci" {
58-
# alias = "current_region"
59-
# tenancy_ocid = var.tenancy_ocid
60-
# region = var.region
61-
62-
# user_ocid = var.user_ocid
63-
# fingerprint = var.fingerprint
64-
# private_key_path = var.private_key_path
65-
# }
66-
67-
# New configuration to avoid Terraform Kubernetes provider interpolation. https://registry.terraform.io/providers/hashicorp/kubernetes/2.2.0/docs#stacking-with-managed-kubernetes-cluster-resources
68-
# Currently need to uncheck to refresh (--refresh=false) when destroying or else the terraform destroy will fail
69-
70-
# # https://docs.cloud.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengdownloadkubeconfigfile.htm#notes
71-
# provider "kubernetes" {
72-
# host = local.cluster_endpoint
73-
# cluster_ca_certificate = local.cluster_ca_certificate
74-
# exec {
75-
# api_version = "client.authentication.k8s.io/v1beta1"
76-
# args = ["ce", "cluster", "generate-token", "--cluster-id", local.cluster_id, "--region", local.cluster_region]
77-
# command = "oci"
78-
# }
79-
# }
80-
81-
# # https://docs.cloud.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengdownloadkubeconfigfile.htm#notes
82-
# provider "helm" {
83-
# kubernetes {
84-
# host = local.cluster_endpoint
85-
# cluster_ca_certificate = local.cluster_ca_certificate
86-
# exec {
87-
# api_version = "client.authentication.k8s.io/v1beta1"
88-
# args = ["ce", "cluster", "generate-token", "--cluster-id", local.cluster_id, "--region", local.cluster_region]
89-
# command = "oci"
90-
# }
91-
# }
92-
# }
93-
94-
# locals {
95-
# # cluster_endpoint = (var.cluster_endpoint_visibility == "Private") ? (
96-
# # "https://${module.oke.orm_private_endpoint_oke_api_ip_address}:6443") : (
97-
# # yamldecode(module.oke.kubeconfig)["clusters"][0]["cluster"]["server"])
98-
# cluster_endpoint = yamldecode(module.oke.kubeconfig)["clusters"][0]["cluster"]["server"]
99-
# cluster_ca_certificate = base64decode(yamldecode(module.oke.kubeconfig)["clusters"][0]["cluster"]["certificate-authority-data"])
100-
# cluster_id = yamldecode(module.oke.kubeconfig)["users"][0]["user"]["exec"]["args"][4]
101-
# cluster_region = yamldecode(module.oke.kubeconfig)["users"][0]["user"]["exec"]["args"][6]
102-
# }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
5+
# OCI authentication
6+
tenancy_ocid = "ocid1.tenancy....."
7+
fingerprint = "" # e.g.: "5f:53:..." or leave blank if using CloudShell
8+
user_ocid = "" # e.g.: "ocid1.user..." or leave blank if using CloudShell
9+
private_key_path = "" # e.g.: "/users/user/.oci/oci_api_key.pem" or leave blank if using CloudShell
10+
11+
# Deployment compartment
12+
compartment_ocid = "ocid1.compartment...."
13+
14+
# region
15+
region = "us-ashburn-1"

examples/basic-cluster/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
15
# OCI Provider
26
variable "tenancy_ocid" {}
37
variable "compartment_ocid" {}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
5+
module "oke-quickstart" {
6+
source = "github.com/oracle-quickstart/terraform-oci-oke-quickstart?ref=0.8.15"
7+
8+
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
9+
tenancy_ocid = var.tenancy_ocid
10+
compartment_ocid = var.compartment_ocid
11+
region = var.region
12+
13+
# Note: Just few arguments are showing here to simplify the basic example. All other arguments are using default values.
14+
# App Name to identify deployment. Used for naming resources.
15+
app_name = "Basic with Existent Network"
16+
17+
# Freeform Tags + Defined Tags. Tags are applied to all resources.
18+
tag_values = { "freeformTags" = { "Environment" = "Development", "DeploymentType" = "basic", "QuickstartExample" = "basic-with-existing-network" }, "definedTags" = {} }
19+
20+
# OKE Node Pool 1 arguments
21+
node_pool_cni_type_1 = "FLANNEL_OVERLAY" # Use "OCI_VCN_IP_NATIVE" for VCN Native PODs Network. If the node pool 1 uses the OCI_VCN_IP_NATIVE, the cluster will also be configured with same cni
22+
cluster_autoscaler_enabled = true
23+
node_pool_initial_num_worker_nodes_1 = 3 # Minimum number of nodes in the node pool
24+
node_pool_max_num_worker_nodes_1 = 10 # Maximum number of nodes in the node pool
25+
node_pool_instance_shape_1 = { "instanceShape" = "VM.Standard.E4.Flex", "ocpus" = 2, "memory" = 64 } # If not using a Flex shape, ocpus and memory are ignored
26+
27+
# VCN for OKE arguments
28+
create_new_vcn = false
29+
existent_vcn_ocid = "ocid1.vcn.oc1.iad.amaaaaaadoggtjaat6nl5pla7kw52nbxpu73erej3nbd4shjhjczn2tfeadq"
30+
existent_vcn_compartment_ocid = "" # Optional. Specify if want to create terraform to create the subnets and the VCN is in a different compartment than the OKE cluster
31+
32+
# Subnet for OKE arguments
33+
create_subnets = false
34+
existent_oke_k8s_endpoint_subnet_ocid = "ocid1.subnet.oc1.iad.aaaaaaaakwyp2rkytg3yepvx7qzytff7estok277lda7gjjso3k4wnz6dpoa"
35+
existent_oke_nodes_subnet_ocid = "ocid1.subnet.oc1.iad.aaaaaaaack6edaxj6vxdxvbgw4ae232to3ou7rpfmv6lyscpbzcetjkeifiq"
36+
existent_oke_load_balancer_subnet_ocid = "ocid1.subnet.oc1.iad.aaaaaaaao6j4ixl23bcp6367he7l5qytuvmm74hrmg4ajiqyfzxowrbrx3pa"
37+
existent_oke_vcn_native_pod_networking_subnet_ocid = ""
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
5+
# Deployment outputs
6+
output "deploy_id" {
7+
value = module.oke-quickstart.deploy_id
8+
}
9+
10+
# OKE Outputs
11+
output "comments" {
12+
value = module.oke-quickstart.comments
13+
}
14+
output "deployed_oke_kubernetes_version" {
15+
value = module.oke-quickstart.deployed_oke_kubernetes_version
16+
}
17+
output "deployed_to_region" {
18+
value = module.oke-quickstart.deployed_to_region
19+
}
20+
output "kubeconfig" {
21+
value = module.oke-quickstart.kubeconfig
22+
sensitive = true
23+
}
24+
output "kubeconfig_for_kubectl" {
25+
value = module.oke-quickstart.kubeconfig_for_kubectl
26+
description = "If using Terraform locally, this command set KUBECONFIG environment variable to run kubectl locally"
27+
}
28+
output "dev" {
29+
value = module.oke-quickstart.dev
30+
}
31+
### Important Security Notice ###
32+
# The private key generated by this resource will be stored unencrypted in your Terraform state file.
33+
# Use of this resource for production deployments is not recommended.
34+
# Instead, generate a private key file outside of Terraform and distribute it securely to the system where Terraform will be run.
35+
output "generated_private_key_pem" {
36+
value = module.oke-quickstart.generated_private_key_pem
37+
sensitive = true
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
5+
terraform {
6+
required_version = ">= 1.1"
7+
required_providers {
8+
oci = {
9+
source = "oracle/oci"
10+
version = "~> 4, < 5"
11+
# https://registry.terraform.io/providers/oracle/oci/
12+
}
13+
kubernetes = {
14+
source = "hashicorp/kubernetes"
15+
version = "~> 2"
16+
# https://registry.terraform.io/providers/hashicorp/kubernetes/
17+
}
18+
helm = {
19+
source = "hashicorp/helm"
20+
version = "~> 2"
21+
# https://registry.terraform.io/providers/hashicorp/helm/
22+
}
23+
tls = {
24+
source = "hashicorp/tls"
25+
version = "~> 4"
26+
# https://registry.terraform.io/providers/hashicorp/tls/
27+
}
28+
local = {
29+
source = "hashicorp/local"
30+
version = "~> 2"
31+
# https://registry.terraform.io/providers/hashicorp/local/
32+
}
33+
random = {
34+
source = "hashicorp/random"
35+
version = "~> 3"
36+
# https://registry.terraform.io/providers/hashicorp/random/
37+
}
38+
}
39+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
5+
# OCI authentication
6+
tenancy_ocid = "ocid1.tenancy....."
7+
fingerprint = "" # e.g.: "5f:53:..." or leave blank if using CloudShell
8+
user_ocid = "" # e.g.: "ocid1.user..." or leave blank if using CloudShell
9+
private_key_path = "" # e.g.: "/users/user/.oci/oci_api_key.pem" or leave blank if using CloudShell
10+
11+
# Deployment compartment
12+
compartment_ocid = "ocid1.compartment...."
13+
14+
# region
15+
region = "us-ashburn-1"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# OCI Provider
2+
variable "tenancy_ocid" {}
3+
variable "compartment_ocid" {}
4+
variable "region" {}
5+
variable "user_ocid" {
6+
default = ""
7+
}
8+
variable "fingerprint" {
9+
default = ""
10+
}
11+
variable "private_key_path" {
12+
default = ""
13+
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ locals {
620620
}, {
621621
description = "Allow Pods to communicate with Worker Nodes"
622622
destination = lookup(local.network_cidrs, "NODES-REGIONAL-SUBNET-CIDR")
623-
destination_type = "SERVICE_CIDR_BLOCK"
623+
destination_type = "CIDR_BLOCK"
624624
protocol = local.security_list_ports.tcp_protocol_number
625625
stateless = false
626626
tcp_options = { max = -1, min = -1, source_port_range = null }

oci-networking.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33
#
44

5-
# File Version: 0.8.0
5+
# File Version: 0.9.0
66

77
# Dependencies:
88
# - defaults.tf file

0 commit comments

Comments
 (0)