Home > other >  OCI: Create nodes in Kubernetes nodepool with bastion agent configured
OCI: Create nodes in Kubernetes nodepool with bastion agent configured

Time:06-06

I'm trying to deploy a Kubernetes cluster in Oracle Cloud Infrastructure using Terraform.

I want that every node deployed (in private subnet) has the Bastion agent plugin activate in Cloud Agent.

But I cannot see how to define the details of the instance (setting agent_config in the node pool instances).

My code, until now is:



resource "oci_containerengine_cluster" "generated_oci_containerengine_cluster" {
    compartment_id = var.cluster_compartment
    endpoint_config {
        is_public_ip_enabled = "true"
        subnet_id = oci_core_subnet.oke_public_api.id
    }
    kubernetes_version = var.kubernetes_version
    name = "josealbarran_labcloudnative_oke"
    options {
        kubernetes_network_config {
            pods_cidr = "10.244.0.0/16"
            services_cidr = "10.96.0.0/16"
        }
        service_lb_subnet_ids = [oci_core_subnet.oke_public_lb.id]
    }
    vcn_id = var.cluster_vcn
}

# Check doc: https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/containerengine_node_pool
resource "oci_containerengine_node_pool" "node_pool01" {
    cluster_id = "${oci_containerengine_cluster.generated_oci_containerengine_cluster.id}"
    compartment_id = var.cluster_compartment
    initial_node_labels {
        key = "name"
        value = "pool01"
    }
    kubernetes_version = var.kubernetes_version
    name = "lab_cloud_native_oke_pool01"

    node_config_details {
        size = "${length(data.oci_identity_availability_domains.ads.availability_domains)}"
        dynamic "placement_configs" {
            for_each = data.oci_identity_availability_domains.ads.availability_domains[*].name
            content {
                availability_domain = placement_configs.value
                subnet_id = oci_core_subnet.oke_private_worker.id
            }
        }


    }
    node_shape = "VM.Standard.A1.Flex"
    node_shape_config {
        memory_in_gbs = "16"
        ocpus = "1"
    }
    node_source_details {
        image_id = "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaalgodii3qx3mfasp6ai22bja7mabfwsxiwkzxx7lhdfdbbuyqcznq"
        source_type = "IMAGE"
    }
    ssh_public_key = "ssh-rsa AAAAB3xxxxxxxx......."


  timeouts {
      create = "60m"
      delete = "90m"
    }
}

CodePudding user response:

You can use the "cloudinit_config" to run the custom script in OKE node pool in OCI.

second_script_template = templatefile("${path.module}/cloudinit/second.template.sh",{})

More scripts like

data "cloudinit_config" "worker" {
  gzip          = false
  base64_encode = true

  part {
    filename     = "worker.sh"
    content_type = "text/x-shellscript"
    content      = local.worker_script_template
  }

  part {
    filename     = "second.sh"
    content_type = "text/x-shellscript"
    content      = local.second_script_template
  }

  part {
    filename     = "third.sh"
    content_type = "text/x-shellscript"
    content      = local.third_script_template
  }
}

Refer : https://github.com/oracle-terraform-modules/terraform-oci-oke/blob/main/docs/instructions.adoc#14-configuring-cloud-init-for-the-nodepools

If you are looking forward to just edit the default script : https://github.com/oracle-terraform-modules/terraform-oci-oke/blob/main/docs/cloudinit.adoc

  • Related