alicloud_edas_k8s_slb_attachment

更新时间:

Binds SLBs to an EDAS k8s application.

For information about EDAS k8s slb attachment and how to use it, see What is k8s slb attachment.

-> NOTE: Available since v1.194.0.

Example Usage

Basic Usage


variable "name" {
  default = "tf-example"
}
data "alicloud_zones" "default" {
  available_resource_creation = "VSwitch"
}
data "alicloud_images" "default" {
  name_regex  = "^ubuntu_18.*64"
  most_recent = true
  owners      = "system"
}
data "alicloud_instance_types" "default" {
  availability_zone    = data.alicloud_zones.default.zones.0.id
  cpu_core_count       = 4
  memory_size          = 8
  kubernetes_node_role = "Worker"
}

resource "alicloud_vpc" "default" {
  vpc_name   = var.name
  cidr_block = "10.4.0.0/16"
}
resource "alicloud_vswitch" "default" {
  vswitch_name = var.name
  cidr_block   = "10.4.0.0/24"
  vpc_id       = alicloud_vpc.default.id
  zone_id      = data.alicloud_zones.default.zones.0.id
}

resource "alicloud_cs_managed_kubernetes" "default" {
  name_prefix          = var.name
  cluster_spec         = "ack.pro.small"
  worker_vswitch_ids   = [alicloud_vswitch.default.id]
  new_nat_gateway      = true
  pod_cidr             = cidrsubnet("10.0.0.0/8", 8, 36)
  service_cidr         = cidrsubnet("172.16.0.0/16", 4, 7)
  slb_internet_enabled = true
}

resource "alicloud_cs_kubernetes_node_pool" "default" {
  name                 = var.name
  cluster_id           = alicloud_cs_managed_kubernetes.default.id
  vswitch_ids          = [alicloud_vswitch.default.id]
  instance_types       = [data.alicloud_instance_types.default.instance_types.0.id]
  system_disk_category = "cloud_efficiency"
  system_disk_size     = 40
  desired_size         = 2
}
resource "alicloud_edas_k8s_cluster" "default" {
  cs_cluster_id = alicloud_cs_kubernetes_node_pool.default.cluster_id
}

resource "alicloud_edas_k8s_application" "default" {
  application_name        = var.name
  cluster_id              = alicloud_edas_k8s_cluster.default.id
  package_type            = "FatJar"
  package_url             = "http://edas-bj.oss-cn-beijing.aliyuncs.com/prod/demo/SPRING_CLOUD_PROVIDER.jar"
  jdk                     = "Open JDK 8"
  replicas                = 2
  readiness               = "{\"failureThreshold\": 3,\"initialDelaySeconds\": 5,\"successThreshold\": 1,\"timeoutSeconds\": 1,\"tcpSocket\":{\"port\":18081}}"
  liveness                = "{\"failureThreshold\": 3,\"initialDelaySeconds\": 5,\"successThreshold\": 1,\"timeoutSeconds\": 1,\"tcpSocket\":{\"port\":18081}}"
  application_descriotion = var.name
}

resource "alicloud_edas_k8s_slb_attachment" "default" {
  app_id = alicloud_edas_k8s_application.default.id
  slb_configs {
    type      = "internet"
    scheduler = "rr"
    port_mappings {
      loadbalancer_protocol = "TCP"
      service_port {
        port        = 80
        protocol    = "TCP"
        target_port = 8080
      }
    }
  }
}

Argument Reference

The following arguments are supported:

  • app_id - (Required, ForceNew) The ID of the EDAS k8s application to which you want to bind SLB instances.
  • slb_configs - (Optional) The configurations of SLB attachment, which is supported for multiple configurations. See slb_configs below.

slb_configs

  • type - (Required) The type of SLB instance, values can be 'internet' or 'intranet'.
  • name - (Optional) The name of this SLB configuration, empty for auto-generated by EDAS server.
  • scheduler - (Required) The scheduler policy of SLB configuration, values can be 'rr'(round-robin) or 'wrr'(weighted round-robin).
  • specification - (Optional) The instance specification of SLB, values can be found here, empty for 'slb.s1.small'.
  • slb_id - (Optional) The ID of your SLB instance, if value is empty which means EDAS will purchase an SLB instance with 'specification' field.
  • port_mappings - (Required) The port configuration for SLB instance, which is supported for multiple configurations. See port_mappings below.

slb_configs-port_mappings

  • cert_id - (Optional) The ID of your tls certification, this is used for 'HTTPS' protocol only.
  • loadbalancer_protocol - (Required) The protocol of SLB instance configuration, values can be 'TCP', 'HTTP' or 'HTTPS'.
  • service_port - (Required) The backend k8s service configuration for SLB instance, which is supported for multiple configurations. See service_port below.

slb_configs-port_mappings-service_port

  • port - (Required) The port of k8s service, values should be within range [1, 65535].
  • protocol - (Required) The protocol of k8s service, values can be 'TCP' or 'UDP'.
  • target_port - (Required) The port of k8s pod, values should be within range [1, 65535].

Attributes Reference

The following attributes are exported:

  • id - The resource ID in terraform of an EDAS k8s application, which is in the format of UUID.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 mins) Used when bind the slb to the EDAS k8s application.
  • delete - (Defaults to 30 mins) Used when unbind the slb to the EDAS k8s application.
  • update - (Defaults to 30 mins) Used when update the slb to the EDAS k8s application.

Import

Slb information of EDAS k8s application can be imported using the ID of an EDAS k8s application. e.g.

$ terraform import alicloud_edas_k8s_slb_attachment.example <EDAS k8s app id>