Skip to content

Commit

Permalink
Add oke and nlb to managed cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
vcscsvcscs committed Mar 3, 2024
1 parent 114f0ce commit 0ca08d2
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 9 deletions.
24 changes: 24 additions & 0 deletions oci-managed/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,27 @@ module "snet" {
vcn_nat_route_id = module.vcn.vcn_nat_route_table_id
vcn_ig_route_id = module.vcn.vcn_ig_route_table_id
}

module "oke" {
source = "./oke"

compartment_ocid = var.compartment_ocid
cluster_name = var.cluster_name
environment = var.environment

vcn_id = module.vcn.vcn_id
vcn_public_subnet_id = module.snet.public_subnet_id
vcn_private_subnet_id = module.snet.private_subnet_id
node_availability_domains = [var.availability_domain]
node_pool_size = var.node_pool_size
ssh_public_key = var.public_key_path
}

module "nlb" {
source = "./nlb"

compartment_ocid = var.compartment_ocid
cluster_ocid = module.oke.cluster_ocid
cluster_public_endpoint = module.oke.public_endpoint
values_file = "traefik-values.yaml"
}
8 changes: 8 additions & 0 deletions oci-managed/nlb/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data "oci_containerengine_cluster_kube_config" "cluster_kube_config" {
#Required
cluster_id = var.cluster_ocid

#Optional
endpoint = var.cluster_public_endpoint
token_version = "2.0.0"
}
Empty file added oci-managed/nlb/output.tf
Empty file.
5 changes: 5 additions & 0 deletions oci-managed/nlb/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
}
20 changes: 20 additions & 0 deletions oci-managed/nlb/traefik.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "helm_release" "traefik" {
namespace = "traefik-loadbalancer"
create_namespace = true
name = "traefik"
repository = "https://traefik.github.io/charts"
chart = "traefik"
version = var.traefik_chart_version

# Helm chart deployment can sometimes take longer than the default 5 minutes
timeout = var.timeout_seconds

# If values file specified by the var.values_file input variable exists then apply the values from this file
# else apply the default values from the chart
values = [fileexists("${path.root}/${var.values_file}") == true ? file("${path.root}/${var.values_file}") : ""]

set {
name = "deployment.replicas"
value = var.replica_count
}
}
41 changes: 41 additions & 0 deletions oci-managed/nlb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
variable "compartment_ocid" {}
variable "environment" {
default = "prod"
}
variable "cluster_ocid" {
type = string
}
variable "cluster_public_endpoint" {
type = string
}

variable "namespace" {
description = "Namespace to install traefik chart into"
type = string
default = "traefik"
}

variable "traefik_chart_version" {
description = "Version of Traefik chart to install"
type = string
default = "21.1.0" # See https://artifacthub.io/packages/helm/traefik/traefik for latest version(s)
}

# Helm chart deployment can sometimes take longer than the default 5 minutes
variable "timeout_seconds" {
type = number
description = "Helm chart deployment can sometimes take longer than the default 5 minutes. Set a custom timeout here."
default = 800 # 10 minutes
}

variable "replica_count" {
description = "Number of replica pods to create"
type = number
default = 1
}

variable "values_file" {
description = "The name of the traefik helmchart values file to use"
type = string
default = "values.yaml"
}
23 changes: 23 additions & 0 deletions oci-managed/oke/cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource "oci_containerengine_cluster" "k8s_cluster" {
compartment_id = var.compartment_ocid
kubernetes_version = var.kubernetes_version
name = "${var.cluster_name}-${var.environment}-cluster"
vcn_id = var.vcn_id

endpoint_config {
is_public_ip_enabled = true
subnet_id = var.vcn_public_subnet_id
}

options {
add_ons {
is_kubernetes_dashboard_enabled = var.kubernetes_dashboard_enabled
is_tiller_enabled = var.tiller_enabled
}
kubernetes_network_config {
pods_cidr = "10.244.0.0/16"
services_cidr = "10.96.0.0/16"
}
service_lb_subnet_ids = [var.vcn_public_subnet_id]
}
}
14 changes: 14 additions & 0 deletions oci-managed/oke/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
data "oci_identity_availability_domains" "ads" {
compartment_id = var.compartment_ocid
}

data "oci_core_images" "latest_image" {
compartment_id = var.compartment_ocid
operating_system = "Oracle Linux"
operating_system_version = "8.8"
filter {
name = "display_name"
values = ["^.*aarch64-.*$"]
regex = true
}
}
34 changes: 34 additions & 0 deletions oci-managed/oke/node_pool.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
resource "oci_containerengine_node_pool" "k8s_node_pool" {
cluster_id = oci_containerengine_cluster.k8s_cluster.id
compartment_id = var.compartment_ocid
kubernetes_version = var.kubernetes_version
name = "${var.cluster_name}-${var.environment}-arm-node-pool"
node_config_details {
dynamic "placement_configs" {
for_each = var.node_availability_domains
content {
availability_domain = placement_configs.value
subnet_id = var.vcn_private_subnet_id
}
}
size = var.node_pool_size
}
node_shape = "VM.Standard.A1.Flex"

node_shape_config {
memory_in_gbs = 12
ocpus = 2
}

node_source_details {
image_id = data.oci_core_images.latest_image.images.0.id
source_type = "image"
}

initial_node_labels {
key = "name"
value = "${var.cluster_name}-${var.environment}-cluster"
}

ssh_public_key = file(var.ssh_public_key)
}
7 changes: 7 additions & 0 deletions oci-managed/oke/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "cluster_ocid" {
value = oci_containerengine_cluster.k8s_cluster.id
}

output "public_endpoint" {
value = one(oci_containerengine_cluster.k8s_cluster.endpoints)
}
37 changes: 37 additions & 0 deletions oci-managed/oke/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
variable "compartment_ocid" {}
variable "cluster_name" {
type = string
}
variable "environment" {
default = "prod"
}

variable "kubernetes_version" {
default = "v1.28.2"
}
variable "ssh_public_key" {
type = string
}
variable "node_availability_domains" {
type = list(string)
default = data.oci_identity_availability_domains.ads.availability_domains[*].name
}
variable "node_pool_size" {
type = number
default = 2
}
variable "kubernetes_dashboard_enabled" {
default = false
}
variable "tiller_enabled" {
default = false
}

variable "vcn_id" {}
variable "vcn_public_subnet_id" {
type = string
}
variable "vcn_private_subnet_id" {
type = string
}

14 changes: 9 additions & 5 deletions oci-managed/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ terraform {
source = "oracle/oci"
version = ">= 5.30.0"
}
helm = {
source = "hashicorp/helm"
version = ">= 2.12.1"
}
}
}

provider "oci" {
tenancy_ocid = var.tenancy_ocid
user_ocid = var.user_ocid
private_key_path = pathexpand(var.private_key_path)
fingerprint = var.fingerprint
region = var.region
tenancy_ocid = var.tenancy_ocid
user_ocid = var.user_ocid
private_key_path = pathexpand(var.private_key_path)
fingerprint = var.fingerprint
region = var.region
retry_duration_seconds = 120
}
7 changes: 7 additions & 0 deletions oci-managed/snet/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "public_subnet_id" {
value = oci_core_subnet.vcn_public_subnet.id
}

output "private_subnet_id" {
value = oci_core_subnet.vcn_private_subnet.id
}
Empty file added oci-managed/traefik-values.yml
Empty file.
6 changes: 2 additions & 4 deletions oci-managed/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ variable "certmanager_email_address" {}
variable "region" {}
variable "public_key_path" {}

variable "k3s_server_pool_size" {
default = 2
}
variable "k3s_worker_pool_size" {
variable "node_pool_size" {
default = 2
}

variable "k3s_extra_worker_node" {
default = false
}
Expand Down

0 comments on commit 0ca08d2

Please sign in to comment.