Skip to content

Commit 313d7c7

Browse files
committed
oke-rm-1.1.1
1 parent d7e783c commit 313d7c7

File tree

10 files changed

+384
-66
lines changed

10 files changed

+384
-66
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
locals {
22
create_bastion = var.create_bastion_subnet && var.create_bastion
3+
# VCN_NATIVE_CNI internally it is mapped as npn
4+
cni = var.cni_type == "vcn_native" ? "npn" : var.cni_type
35
}

app-dev/devops-and-containers/oke/oke-rm/infra/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module "network" {
33
source = "./modules/network"
44
network_compartment_id = var.network_compartment_id
55
region = var.region
6-
cni_type = var.cni_type
6+
cni_type = local.cni
77
# VCN
88
create_vcn = var.create_vcn
99
vcn_id = var.vcn_id

app-dev/devops-and-containers/oke/oke-rm/infra/schema.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
title: OCI Native - Base Infra
2-
description: Basic infrastructure and network rules to start with a Cloud Native project
3-
informationalText: Basic infrastructure
1+
title: OKE RM - Base Network Infrastructure
2+
description: Basic network infrastructure to start with OKE
3+
informationalText: Basic network infrastructure
44
schemaVersion: 1.1.0
55
version: "20190304"
66
locale: "en"
@@ -88,7 +88,7 @@ variables:
8888
description: "CNI to use for the OKE cluster"
8989
type: enum
9090
enum:
91-
- npn
91+
- vcn_native
9292
- flannel
9393
required: true
9494

@@ -210,7 +210,7 @@ variables:
210210
visible:
211211
eq:
212212
- ${cni_type}
213-
- npn
213+
- vcn_native
214214

215215
pod_subnet_cidr:
216216
title: "Pod subnet CIDR"
@@ -222,7 +222,7 @@ variables:
222222
- ${create_pod_subnet}
223223
- eq:
224224
- ${cni_type}
225-
- npn
225+
- vcn_native
226226

227227
pod_subnet_dns_label:
228228
title: "Pod subnet DNS label"
@@ -234,7 +234,7 @@ variables:
234234
- ${create_pod_subnet}
235235
- eq:
236236
- ${cni_type}
237-
- npn
237+
- vcn_native
238238

239239
pod_subnet_name:
240240
title: "Pod subnet name"
@@ -246,7 +246,7 @@ variables:
246246
- ${create_pod_subnet}
247247
- eq:
248248
- ${cni_type}
249-
- npn
249+
- vcn_native
250250

251251
# SERVICE SUBNET
252252

app-dev/devops-and-containers/oke/oke-rm/infra/variable.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ variable "vcn_id" {
1818
}
1919

2020
variable "vcn_name" {
21-
default = "vcn-spoke-1"
21+
default = "vcn-oke-1"
2222
}
2323

2424
variable "vcn_cidr_blocks" {
@@ -27,7 +27,7 @@ variable "vcn_cidr_blocks" {
2727
}
2828

2929
variable "vcn_dns_label" {
30-
default = "spoke1"
30+
default = "oke1"
3131
}
3232

3333
# CP SUBNET
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Add on section, you can also manage addons through Terraform
2+
# To find out add-ons available and configurations, run: oci ce addon-option list --kubernetes-version <OKE_VERSION > addons.json
3+
# See also https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengconfiguringclusteraddons-configurationarguments.htm
4+
5+
locals {
6+
7+
# SET THIS TO TRUE IF YOU WANT TO OVERRIDE THE COREDNS PLUGIN AND MANAGE IT THROUGH TERRAFORM
8+
# REQUIRES AT LEAST 1 NODE IN THE CLUSTER. THAT NODE MUST BE FROM THE SYSTEM NODE POOL IF CLUSTER AUTOSCALER IS ENABLED!
9+
override_coredns = false
10+
11+
coredns_addon_configs_base = {
12+
# Distribute replicas on nodes belonging to different ADs, if possible
13+
topologySpreadConstraints = jsonencode(
14+
yamldecode(
15+
<<-YAML
16+
- maxSkew: "1"
17+
topologyKey: topology.kubernetes.io/zone
18+
whenUnsatisfiable: ScheduleAnyway
19+
labelSelector:
20+
matchLabels:
21+
k8s-app: kube-dns
22+
YAML
23+
)
24+
)
25+
# Try to spread CoreDNS pods across different nodes
26+
affinity = jsonencode(
27+
yamldecode(
28+
<<-YAML
29+
podAntiAffinity:
30+
preferredDuringSchedulingIgnoredDuringExecution:
31+
- podAffinityTerm:
32+
labelSelector:
33+
matchLabels:
34+
k8s-app: "kube-dns"
35+
topologyKey: "kubernetes.io/hostname"
36+
weight: 100
37+
YAML
38+
)
39+
)
40+
# Rolling update configurations for CoreDNS
41+
rollingUpdate = "{\"maxSurge\": \"50%\", \"maxUnavailable\":\"25%\"}"
42+
# For large clusters, it's better to increase this value. The default behaviour is to create a new CoreDNS for every new node. Also, resources for single CoreDNS pods should be increased
43+
nodesPerReplica = "1"
44+
# In case you need to customize the coredns ConfigMap in kube-system
45+
customizeCoreDNSConfigMap = "false"
46+
}
47+
48+
# COREDNS MUST be scheduled to the system node pool in case cluster autoscaler is enabled
49+
coredns_addon_configs = merge(local.coredns_addon_configs_base, local.enable_cluster_autoscaler ? {
50+
nodeSelectors = "{\"role\": \"system\"}"
51+
} : null)
52+
53+
metrics_server_addon_configs_base = {
54+
# At least 3 replicas for high availability
55+
numOfReplicas = "3"
56+
# Spread the replicas across ADs if possible
57+
topologySpreadConstraints = jsonencode(
58+
yamldecode(
59+
<<-YAML
60+
- maxSkew: "1"
61+
topologyKey: topology.kubernetes.io/zone
62+
whenUnsatisfiable: ScheduleAnyway
63+
labelSelector:
64+
matchLabels:
65+
k8s-app: metrics-server
66+
YAML
67+
)
68+
)
69+
}
70+
71+
# METRICS-SERVER MUST be scheduled to the system node pool in case cluster autoscaler is enabled
72+
metrics_server_addon_configs = merge(local.metrics_server_addon_configs_base, local.enable_cluster_autoscaler ? {
73+
nodeSelectors = "{\"role\": \"system\"}"
74+
} : null)
75+
76+
cluster_autoscaler_addon_configs = {
77+
authType = "workload"
78+
# Enable balancing of similar node groups
79+
balanceSimilarNodeGroups = "true"
80+
# We should never group by fault domain when balancing for similarity, only by AD
81+
balancingIgnoreLabel = "oci.oraclecloud.com/fault-domain"
82+
# Supported from OKE v1.30.10, autoscale based on freeform or defined tags in the node pools
83+
# DEFINE HERE YOUR AUTOSCALER POLICY, DEFAULT IS MIN: 0, MAX: 5
84+
nodeGroupAutoDiscovery = "compartmentId:${var.oke_compartment_id},nodepoolTags:cluster_autoscaler=enabled,min:0,max:5"
85+
# Make sure to schedule the cluster autoscaler in a node that it is NOT autoscaled, in the system node pool
86+
nodeSelectors = "{\"role\": \"system\"}"
87+
}
88+
}
89+
90+
91+
resource "oci_containerengine_addon" "oke_cert_manager" {
92+
addon_name = "CertManager"
93+
cluster_id = module.oke.cluster_id
94+
remove_addon_resources_on_delete = true
95+
depends_on = [module.oke]
96+
count = local.enable_cert_manager ? 1 : 0
97+
}
98+
99+
resource "oci_containerengine_addon" "oke_metrics_server" {
100+
addon_name = "KubernetesMetricsServer"
101+
cluster_id = module.oke.cluster_id
102+
remove_addon_resources_on_delete = true
103+
dynamic "configurations" {
104+
for_each = local.metrics_server_addon_configs
105+
content {
106+
key = configurations.key
107+
value = configurations.value
108+
}
109+
}
110+
depends_on = [module.oke, oci_containerengine_addon.oke_cert_manager]
111+
count = local.enable_metrics_server ? 1 : 0
112+
}
113+
114+
resource "oci_containerengine_addon" "oke_coredns" {
115+
addon_name = "CoreDNS"
116+
cluster_id = module.oke.cluster_id
117+
remove_addon_resources_on_delete = false
118+
override_existing = true
119+
dynamic "configurations" {
120+
for_each = local.coredns_addon_configs
121+
content {
122+
key = configurations.key
123+
value = configurations.value
124+
}
125+
}
126+
depends_on = [module.oke]
127+
count = var.cluster_type == "enhanced" && local.override_coredns ? 1 : 0
128+
}
129+
130+
resource "oci_containerengine_addon" "oke_cluster_autoscaler" {
131+
addon_name = "ClusterAutoscaler"
132+
cluster_id = module.oke.cluster_id
133+
remove_addon_resources_on_delete = true
134+
dynamic "configurations" {
135+
for_each = local.cluster_autoscaler_addon_configs
136+
content {
137+
key = configurations.key
138+
value = configurations.value
139+
}
140+
}
141+
depends_on = [module.oke]
142+
count = local.enable_cluster_autoscaler ? 1 : 0
143+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
locals {
2+
is_cp_subnet_private = data.oci_core_subnet.cp_subnet_data.prohibit_public_ip_on_vnic
3+
is_lb_subnet_private = data.oci_core_subnet.lb_subnet_data.prohibit_public_ip_on_vnic
4+
cni = var.cni_type == "vcn_native" ? "npn" : var.cni_type
5+
is_flannel = var.cni_type == "flannel"
6+
enable_cert_manager = var.cluster_type == "enhanced" && var.enable_cert_manager
7+
enable_metrics_server = var.cluster_type == "enhanced" && var.enable_cert_manager && var.enable_metrics_server
8+
enable_cluster_autoscaler = var.cluster_type == "enhanced" && var.enable_cluster_autoscaler
9+
create_autoscaler_policies = var.cluster_type == "enhanced"&& var.enable_cluster_autoscaler && var.create_autoscaler_policies
10+
}

0 commit comments

Comments
 (0)