mirror of
https://github.com/vcscsvcscs/OCI-Kubernetes-cluster-with-traefik.git
synced 2025-08-12 13:59:09 +02:00
Add oke and nlb to managed cluster
This commit is contained in:
@@ -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
oci-managed/nlb/data.tf
Normal file
8
oci-managed/nlb/data.tf
Normal file
@@ -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"
|
||||
}
|
0
oci-managed/nlb/output.tf
Normal file
0
oci-managed/nlb/output.tf
Normal file
5
oci-managed/nlb/provider.tf
Normal file
5
oci-managed/nlb/provider.tf
Normal file
@@ -0,0 +1,5 @@
|
||||
provider "helm" {
|
||||
kubernetes {
|
||||
config_path = "~/.kube/config"
|
||||
}
|
||||
}
|
20
oci-managed/nlb/traefik.tf
Normal file
20
oci-managed/nlb/traefik.tf
Normal file
@@ -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
oci-managed/nlb/variables.tf
Normal file
41
oci-managed/nlb/variables.tf
Normal file
@@ -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
oci-managed/oke/cluster.tf
Normal file
23
oci-managed/oke/cluster.tf
Normal file
@@ -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
oci-managed/oke/data.tf
Normal file
14
oci-managed/oke/data.tf
Normal file
@@ -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
oci-managed/oke/node_pool.tf
Normal file
34
oci-managed/oke/node_pool.tf
Normal file
@@ -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
oci-managed/oke/output.tf
Normal file
7
oci-managed/oke/output.tf
Normal file
@@ -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
oci-managed/oke/variables.tf
Normal file
37
oci-managed/oke/variables.tf
Normal file
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
0
oci-managed/traefik-values.yml
Normal file
0
oci-managed/traefik-values.yml
Normal file
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user