On Compute Cloud@Customer, you can use Terraform scripts to automate the
creation of OKE network resources.
You can use the following Terraform scripts in your Terraform environment to automate the
creation of the network resources that are required by OKE. For detailed information
about Terraform, see Terraform. (Alternatively, you can create the network resources individually. See Configuring OKE Network Resources Individually)
Most of the values shown in these scripts, such as resource display names and CIDRs, are
examples. Some ports must be specified as shown (see Workload Cluster Network Ports), and the OKE control plane subnet must be named
control-plane. See Workload Cluster Network CIDR Ranges for comments about CIDR
values.
This file creates several variables that are used to configure OKE network resources. Many of these variables
aren't assigned values in this file. One port and five CIDRs are assigned values.
The kubernetes_api_port, port 6443, is the port used to access the
Kubernetes API. See also Workload Cluster Network Ports. The five CIDRs that are defined in this file
are for the OKE VCN, worker subnet, worker load
balancer subnet, control plane subnet, and control plane load balancer subnet.
Copy
variable "oci_config_file_profile" {
type = string
default = "DEFAULT"
}
variable "tenancy_ocid" {
description = "tenancy OCID"
type = string
nullable = false
}
variable "compartment_id" {
description = "compartment OCID"
type = string
nullable = false
}
variable "vcn_name" {
description = "VCN name"
nullable = false
}
variable "kube_client_cidr" {
description = "CIDR of Kubernetes API clients"
type = string
nullable = false
}
variable "kubernetes_api_port" {
description = "port used for kubernetes API"
type = string
default = "6443"
}
variable "worker_lb_ingress_rules" {
description = "traffic allowed to worker load balancer"
type = list(object({
source = string
port_min = string
port_max = string
}))
nullable = false
}
variable "worker_ingress_rules" {
description = "traffic allowed directly to workers"
type = list(object({
source = string
port_min = string
port_max = string
}))
nullable = true
}
#
# IP network addressing
#
variable "vcn_cidr" {
default = "172.31.252.0/23"
}
# Subnet for KMIs where kube-apiserver and other control
# plane applications run
variable "kmi_cidr" {
description = "K8s control plane subnet CIDR"
default = "172.31.252.224/28"
}
# Subnet for KMI load balancer
variable "kmilb_cidr" {
description = "K8s control plane LB subnet CIDR"
default = "172.31.252.240/28"
}
# Subnet for worker nodes, max 128 nodes
variable "worker_cidr" {
description = "K8s worker subnet CIDR"
default = "172.31.253.0/24"
}
# Subnet for worker load balancer (for use by CCM)
variable "workerlb_cidr" {
description = "K8s worker LB subnet CIDR"
default = "172.31.252.0/25"
}
terraform.tfvars 🔗
This file assigns values to some of the variables that were created in
variables.tf. It also defines security list rules for accessing
the worker nodes and the worker load balancer.
Copy
# Name of the profile to use from $HOME/.oci/config
oci_config_file_profile = "DEFAULT"
# Tenancy OCID from the oci_config_file_profile profile.
tenancy_ocid = "ocid1.tenancy.unique_ID"
# Compartment in which to build the OKE cluster.
compartment_id = "ocid1.compartment.unique_ID"
# Display name for the OKE VCN.
vcn_name = "oketest"
# CIDR of clients that are allowed to contact Kubernetes API server.
kube_client_cidr = "10.0.0.0/8"
# Security list rules for who is allowed to contact the worker load balancer.
# Adjust these values for your applications.
worker_lb_ingress_rules = [
{
source = "10.0.0.0/8"
port_min = 80
port_max = 80
},
{
source = "10.0.0.0/8"
port_min = 443
port_max = 443
},
]
# Security list rules for who is allowed to contact worker nodes directly.
# This example allows 10.0.0.0/8 to contact the default nodeport range.
worker_ingress_rules = [
{
source = "10.0.0.0/8"
port_min = 30000
port_max = 32767
},
]
provider.tf 🔗
This file is required to use the OCI provider. The file initializes the OCI module
using the OCI profile configuration file.
This file defines a VCN, NAT gateway, internet gateway, private route table, and
public route table. The private route table is the default route table for the VCN.
This file defines the security lists for both the worker subnet and the worker load
balancer subnet. The rules for these security lists were defined in other Terraform
files in this set.
This file defines the security lists for the control plane and control plane load
balancer subnets. This file also defines updates to make to the default security
list for the VCN.