Skip to content

Commit

Permalink
added kube init
Browse files Browse the repository at this point in the history
  • Loading branch information
howowi committed Apr 29, 2024
1 parent a3dc7ac commit 220273b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
40 changes: 40 additions & 0 deletions terraform/kube_initialize.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Initialize Kubernetes Cluster ##

## Create Private Endpoint

resource "oci_resourcemanager_private_endpoint" "rms_private_endpoint" {
count = local.should_config_shared_private_subnet ? 1 : 0
compartment_id = var.compartment_ocid
display_name = "rms_private_endpoint"
description = "rms_private_endpoint"
vcn_id = oci_core_vcn.opensearch_redis_vcn[count.index].id
subnet_id = oci_core_subnet.KubernetesAPIendpoint[count.index].id
}

data "oci_resourcemanager_private_endpoint_reachable_ip" "private_endpoint_reachable_ips" {
count = var.should_setup_vm ? 1 : 0
private_endpoint_id = oci_resourcemanager_private_endpoint.rms_private_endpoint.id
private_ip = oci_core_instance.service_instance[count.index].private_ip
}

resource "null_resource" "remote-exec" {
count = var.should_setup_vm ? 1 : 0
depends_on = [oci_core_instance.service_instance[count.index], oci_containerengine_node_pool.pool1]

provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = data.oci_resourcemanager_private_endpoint_reachable_ip.private_endpoint_reachable_ips.ip_address
user = "opc"
private_key = tls_private_key.public_private_key_pair.private_key_pem
}
inline = [
"curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl",
"sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl",
"oci ce cluster create-kubeconfig --cluster-id ${oci_containerengine_cluster.supremo-oke-cluster[count.index].id} --file $HOME/.kube/config --region ${var.region} --token-version 2.0.0 --kube-endpoint PRIVATE_ENDPOINT",
"kubectl create namespace supremo",
"kubectl create secret docker-registry ocir-secret --docker-username='${var.OCIR_USERNAME}' --docker-password='${oci_identity_auth_token.user_auth_token.token}' --docker-server=${var.OCIR_URL}' -n supremo"
]
}
}
14 changes: 14 additions & 0 deletions terraform/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ variableGroups:
- oke_shape_ocpus
- oke_shape_mems
- oke_image_os_id
- OCIR_USERNAME
- OCIR_URL

variables:
region:
Expand Down Expand Up @@ -808,6 +810,18 @@ variables:
operatingSystem: "Oracle Linux"
shape: ${oke_node_shape}

OCIR_USERNAME:
title: "Username for OCI Container Registry"
required: true
type: string
description: "Example for non-federated user - tenancynamespace/[email protected] , Example for federated user - tenancynamespace/oracleidentitycloudservice/[email protected]"

OCIR_URL:
title: "URL of OCI Container Registry"
required: true
type: string
description: "(region_code).ocir.io, eg. sin.ocir.io"

############################
#### OUTPUT
############################
Expand Down
8 changes: 8 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,11 @@ variable "oke_shape_mems" {
variable "oke_image_os_id" {
description = "OS Image OCID of the node pool"
}

variable "OCIR_USERNAME" {
description = "Example for non-federated user - tenancynamespace/[email protected] , Example for federated user - tenancynamespace/oracleidentitycloudservice/[email protected]"
}

variable "OCIR_URL" {
description = "<region_code>.ocir.io, eg. sin.ocir.io"
}

0 comments on commit 220273b

Please sign in to comment.