tencent cloud

文档反馈

通过 Terraform 安装 Nginx 插件和实例

最后更新时间:2023-06-09 15:27:07

    前言

    本文示例使用的环境信息如下:
    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
    v1.4.6版本 Release 地址为 https://releases.hashicorp.com/terraform/1.4.6/,您可以根据系统选择对应安装包。

    步骤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"
    }
    }
    }
    }
    
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持