Skip to content

Commit

Permalink
add two variables to control WD service and NLB behaviour
Browse files Browse the repository at this point in the history
k8s_svc_spec and k8s_svc_annotations
  • Loading branch information
givanovexpe committed Oct 3, 2024
1 parent b243ea6 commit 0da9055
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).


## [4.5.4] - 2024-10-03
### Added
- Added variables to control Waggledance k8s Service and NLB configuration

## [4.5.3] - 2024-07-01
### Added
- Added support for setting the TCP keepalive settings of Waggledance.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ For more information please refer to the main [Apiary](https://github.com/Expedi
| k8s_docker_registry_secret | Docker Registry authentication K8s secret name. | string | `` | no |
| k8s_replica_count | Initial Number of k8s pod replicas to create. | number | `3` | no |
| k8s_max_replica_count | Max Number of k8s pod replicas to create. | number | `10` | no |
| k8s_svc_spec | Waggledance Kubernetes service settings. All inner fields are optional and if unset the kubernetes default values are applied. | object | `-` | no |
| k8s_svc_annotations | Custom annotations for the Waggledance Kubernetes service.. | map(string) | `"service.beta.kubernetes.io/aws-load-balancer-type" = "nlb"` | no |
| local_metastores | List of federated Metastore endpoints directly accessible on the local network. See section [`local_metastores`](#local_metastores) for more info. | list | `<list>` | no |
| memory | The amount of memory (in MiB) used to allocate for the Waggle Dance container. Valid values: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html | string | `4096` | no |
| memory_limit | The amount of memory limit (in MiB) used to allocate for the Waggle Dance container, it will use `memory` * 1.25 if the limit is not specified. Valid values: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html | string | `null` | no |
Expand Down
15 changes: 11 additions & 4 deletions k8s.tf
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,13 @@ resource "kubernetes_service" "waggle_dance" {
metadata {
name = local.instance_alias
namespace = var.k8s_namespace

annotations = {
"service.beta.kubernetes.io/aws-load-balancer-internal" = "true"
"service.beta.kubernetes.io/aws-load-balancer-type" = "nlb"
for key, value in var.k8s_svc_annotations :
key => value
}
}

spec {
selector = {
name = local.instance_alias
Expand All @@ -198,8 +200,13 @@ resource "kubernetes_service" "waggle_dance" {
port = local.wd_port
target_port = local.wd_port
}
type = "LoadBalancer"
load_balancer_source_ranges = var.ingress_cidr
type = "LoadBalancer"
load_balancer_source_ranges = var.ingress_cidr
external_traffic_policy = var.k8s_svc_spec.external_traffic_policy
internal_traffic_policy = var.k8s_svc_spec.internal_traffic_policy
allocate_load_balancer_node_ports = var.k8s_svc_spec.allocate_load_balancer_node_ports
load_balancer_class = var.k8s_svc_spec.load_balancer_class
health_check_node_port = var.k8s_svc_spec.health_check_node_port
}
}

Expand Down
34 changes: 34 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,40 @@ variable "k8s_max_replica_count" {
default = 10
}

variable "k8s_svc_spec" {
description =<<EOF
Waggledance Kubernetes service settings. All fields are optional.
external_traffic_policy = "Denotes if this Service desires to route external traffic to node-local or cluster-wide endpoints. Local preserves the client source IP and avoids a second hop for LoadBalancer and Nodeport type services, but risks potentially imbalanced traffic spreading. Cluster obscures the client source IP and may cause a second hop to another node, but should have good overall load-spreading."
internal_traffic_policy = "Specifies if the cluster internal traffic should be routed to all endpoints or node-local endpoints only. Cluster routes internal traffic to a Service to all endpoints. Local routes traffic to node-local endpoints only, traffic is dropped if no node-local endpoints are ready. The default value is 'Cluster'"
allocate_load_balancer_node_ports = "Defines if NodePorts will be automatically allocated for services with type LoadBalancer. It may be set to false if the cluster load-balancer does not rely on NodePorts. If the caller requests specific NodePorts (by specifying a value), those requests will be respected, regardless of this field. This field may only be set for services with type LoadBalancer. Default is 'true'"
load_balancer_class = "The class of the load balancer implementation this Service belongs to. By default this service is handled by the built-in Cloud Controller Manager. To use AWS Load Balancer Controller, set this to 'service.k8s.aws/nlb'"
health_check_node_port = "Specifies the Healthcheck NodePort for the service. Only effects when service type is set to 'LoadBalancer' and k8s_svc_external_traffic_policy is set to 'Local'"
EOF

type = object({
external_traffic_policy = optional(string)
internal_traffic_policy = optional(string)
allocate_load_balancer_node_ports = optional(bool)
load_balancer_class = optional(string)
health_check_node_port = optional(string)
})
default = {}
}

variable "k8s_svc_annotations" {
description =<<EOF
Custom annotations for the Waggledance Kubernetes service. You can use this variable to add extra annotations for configuring the AWS NLB for this service. If var.k8s_svc_lb_controller_type is "nlb-ip" or "external" it means you want to offload
the NLB management to an external controller like AWS Load Balancer Controller. The annotations that are accepted are defined here - https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/guide/service/annotations/
If the var.k8s_svc_lb_controller_type is "nlb" or any other value, then you are using the Legacy AWS Cloud controller and you can see the accepted values here - https://github.com/kubernetes/cloud-provider-aws/blob/master/docs/service_controller.md
EOF

type = map(string)
default = {
"service.beta.kubernetes.io/aws-load-balancer-internal" = "true"
"service.beta.kubernetes.io/aws-load-balancer-type" = "nlb"
}
}

variable "vpc_id" {
description = "VPC ID."
type = string
Expand Down
1 change: 1 addition & 0 deletions version.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

terraform {
experiments = [module_variable_optional_attrs]
required_version = "> 0.15.0, < 1.0.0"
required_providers {
aws = {
Expand Down

0 comments on commit 0da9055

Please sign in to comment.