前言
本文示例使用的环境信息如下:
TKE 集群 Kubernetes 版本:v1.22.5
安装 Nginx 插件版本:v1.2.0
安装 Nginx 实例版本:v1.1.3
步骤1:安装 Terraform
您可以通过以下命令下载并安装 Terraform:
wget https://releases.hashicorp.com/terraform/1.4.6/terraform_1.4.6_linux_amd64.zip
步骤2:在集群中安装 Nginx Addon
Nginx Addon 插件是一个 Nginx 的安装管理工具。首先安装 Addon 插件,然后再使用插件安装 Nginx 实例。
provider.tf 示例文件如下:
# 腾讯云 provider
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
version = "1.80.6"
}
}
}
# 腾讯云 相关信息(更换密钥对 "secret_id"、"secret_key")
provider "tencentcloud" {
secret_id = "********"
secret_key = "********"
region = "ap-shanghai"
}
# 安装Nginx插件(更换集群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\\"}}}"
}
步骤3:声明式安装 Nginx 实例
有关 Kubernetes Provider 的更多配置信息,请参见 官方文档。 Nginx 实例的相关配置可以根据需要进行修改。
IngressClass 配置(示例中使用的是 demo)
HPA 配置
requests/limits 配置
provider.tf 示例文件如下:
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"
}
}
}
}
本页内容是否解决了您的问题?