Background
The environment configuration for the demo in this document is as follows.
The Kubernetes cluster version is v1.22.5.
The Nginx add-on version is v1.2.0.
The Nginx instance version is v1.1.3.
Step 1. Install Terraform
You can run the following command to download and install Terraform.
wget https://releases.hashicorp.com/terraform/1.4.6/terraform_1.4.6_linux_amd64.zip
Step 2. Install Nginx Add-on in the Cluster
First, install the Nginx add-on, which is an installation management tool for Nginx. Then, install the Nginx instance by using this add-on.
A sample provider.tf file is as follows.
# Tencent Cloud provider
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
version = "1.80.6"
}
}
}
# Tencent Cloud information (change the key pair "secret_id" and "secret_key")
provider "tencentcloud" {
secret_id = "********"
secret_key = "********"
region = "ap-shanghai"
}
# Install the Nginx add-on (change the cluster ID "cluster_id")
resource "tencentcloud_kubernetes_addon_attachment" "addon_ingressnginx" {
cluster_id = "cls-xxxxxxxx"
name = "ingressnginx"
request_body = "{\\"kind\\":\\"App\\",\\"spec\\":{\\"chart\\":{\\"chartName\\":\\"ingressnginx\\",\\"chartVersion\\":\\"1.2.0\\"}}}"
}
Step 3. Declarative Installation of the Nginx Instance
For more information about Kubernetes Provider configuration, see the Official Document. The Nginx instance configuration can be modified as needed.
IngressClass configuration (demo is used in the sample)
HPA configuration
Requests/limits configuration
A sample provider.tf file is as follows.
provider "kubernetes" {
config_path = "~/.kube/config"
}
resource "kubernetes_manifest" "nginxingress_demo" {
manifest = {
"apiVersion" = "cloud.tencent.com/v1alpha1"
"kind" = "NginxIngress"
"metadata" = {
"name" = "demo"
}
"spec" = {
"ingressClass" = "demo"
"service" = {
"annotation" = {
"service.kubernetes.io/service.extensiveParameters" = "{\\"InternetAccessible\\":{\\"InternetChargeType\\":\\"TRAFFIC_POSTPAID_BY_HOUR\\",\\"InternetMaxBandwidthOut\\":10}}"
}
"type" = "LoadBalancer"
}
"workLoad" = {
"hpa" = {
"enable" = true
"maxReplicas" = 2
"metrics" = [
{
"pods" = {
"metricName" = "k8s_pod_rate_cpu_core_used_limit"
"targetAverageValue" = "80"
}
"type" = "Pods"
},
]
"minReplicas" = 1
}
"template" = {
"affinity" = {}
"container" = {
"image" = "ccr.ccs.tencentyun.com/paas/nginx-ingress-controller:v1.1.3"
"resources" = {
"limits" = {
"cpu" = "0.5"
"memory" = "1024Mi"
}
"requests" = {
"cpu" = "0.25"
"memory" = "256Mi"
}
}
}
}
"type" = "deployment"
}
}
}
}
Was this page helpful?