Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi az for azure #179

Merged
merged 25 commits into from
Aug 24, 2020
Merged

Multi az for azure #179

merged 25 commits into from
Aug 24, 2020

Conversation

tei-k
Copy link
Contributor

@tei-k tei-k commented Aug 11, 2020

Description

https://scalar-labs.atlassian.net/browse/DLT-6944

Done

  • Support multi az (add locations )
  • Add natgateway only for internal standard lb.
  • Delete unnecessary lifecycle in azure subnet.

Remark

Update ref after merge following pr.
scalar-labs/terraform-azurerm-compute#7

@tei-k tei-k self-assigned this Aug 11, 2020
@tei-k tei-k force-pushed the multi-az-for-azure branch from 5e4685d to fcde56d Compare August 12, 2020 06:54
domain_name_label = "envoy-${local.network_name}"
location = local.location
sku = length(local.locations) > 0 ? "Standard" : "Basic"
# zones = length(local.locations) > 0 ? [local.locations[count.index]] : null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Standard SKU Public IP Addresses that do not specify a zone are zone redundant by default.
https://www.terraform.io/docs/providers/azurerm/r/public_ip.html#zones

Comment on lines 78 to 103
resource "azurerm_public_ip" "envoy_nat_ip" {
count = local.envoy.enable_nlb && local.envoy.nlb_internal && length(local.locations) > 0 ? 1 : 0

name = "envoy-natip"
location = local.location
resource_group_name = local.network_name
allocation_method = "Static"
sku = "Standard"
}

resource "azurerm_nat_gateway" "envoy_natgw" {
count = local.envoy.enable_nlb && local.envoy.nlb_internal && length(local.locations) > 0 ? 1 : 0

name = "envoy-natgw"
location = local.location
resource_group_name = local.network_name
public_ip_address_ids = [azurerm_public_ip.envoy_nat_ip[count.index].id]
sku_name = "Standard"
idle_timeout_in_minutes = 10
}

resource "azurerm_subnet_nat_gateway_association" "envoy_natgw_assoc" {
count = local.envoy.enable_nlb && local.envoy.nlb_internal && length(local.locations) > 0 ? 1 : 0

subnet_id = local.envoy.subnet_id
nat_gateway_id = azurerm_nat_gateway.envoy_natgw[count.index].id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Need outbound NAT when using internal standard lb. (NAT associated with private subnet that include monitoring server)
https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-outbound-connections

@tei-k tei-k force-pushed the multi-az-for-azure branch from 6fa9766 to 5d97c84 Compare August 18, 2020 02:04
@tei-k tei-k changed the title [WIP] Multi az for azure Multi az for azure Aug 18, 2020
@tei-k tei-k requested review from ymorimo and feeblefakie August 18, 2020 02:44
@feeblefakie feeblefakie requested a review from penpyt August 18, 2020 08:48
@penpyt
Copy link
Contributor

penpyt commented Aug 19, 2020

Kubernetes modules work well with a bit of modification => reimport master to this branch for fix region

I have 2 questions:

  • only one bastion has a public IP, so if the AZ who holds the bastion going down, we need to reattach the public IP to the available bastion, maybe better to have both have a public IP (each bastion should have a public IP)?
  • should we chain the locations to kubernetes_cluster_availability_zones like Cassandra or should we do it another PR? see below

locals.tf in Kubernetes examples

locals {
  network = {
    name     = data.terraform_remote_state.network.outputs.network_name
    dns      = data.terraform_remote_state.network.outputs.dns_zone_id
    id       = data.terraform_remote_state.network.outputs.network_id
    region   = data.terraform_remote_state.network.outputs.region
    locations = join(",", data.terraform_remote_state.network.outputs.locations)

main.tf in Kubernetes examples

module "kubernetes" {
  source = "../../../modules/azure/kubernetes"

  # Required variables (use network remote state)
  network = local.network

  # Required kubernetes variable for AZs
  kubernetes_cluster_availability_zones = local.network.locations

@tei-k
Copy link
Contributor Author

tei-k commented Aug 19, 2020

each bastion should have a public IP

Good point! 👍 Agree ! fixed in e8562ce.

should we chain the locations to kubernetes_cluster_availability_zones like Cassandra or should we do it another PR?

It's a minor correction, so I fixed it directly.
(As with the other modules, we can use the network map variable, don't need specify kubernetes_cluster_availability_zones in main.tf )

Comment on lines -33 to -36

lifecycle {
ignore_changes = [network_security_group_id]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Removed lifecycle because it didn't seem to be necessary.

@tei-k
Copy link
Contributor Author

tei-k commented Aug 19, 2020

(As with the other modules, we can use the network map variable, don't need specify kubernetes_cluster_availability_zones in main.tf )

Refactored the k8s part to use local.locations like the other modules in 5125f06.

@penpyt
Copy link
Contributor

penpyt commented Aug 19, 2020

(As with the other modules, we can use the network map variable, don't need specify kubernetes_cluster_availability_zones in main.tf )

Refactored the k8s part to use local.locations like the other modules in 5125f06.

Great thank you

@@ -9,7 +9,7 @@ module "bastion_cluster" {
vm_hostname = "bastion"
vm_os_simple = var.image_id
vnet_subnet_id = var.subnet_id
nb_public_ip = "1"
nb_public_ip = var.resource_count
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tei-k I try to start 3 bastions and got the following error, we should add a random to the dns for public IP

Error: Error Creating/Updating Public IP "bastion-2-publicIP" (Resource Group "paul-k8s-azure-s9rt0ek"): network.PublicIPAddressesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="DnsRecordInUse" Message="DNS record bastion-paul-k8s-azure-s9rt0ek.westus2.cloudapp.azure.com is already used by another public IP." Details=[]

  on .terraform/modules/network.bastion.bastion_cluster/main.tf line 251, in resource "azurerm_public_ip" "vm":
 251: resource "azurerm_public_ip" "vm" {



Error: Error Creating/Updating Public IP "bastion-3-publicIP" (Resource Group "paul-k8s-azure-s9rt0ek"): network.PublicIPAddressesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="DnsRecordInUse" Message="DNS record bastion-paul-k8s-azure-s9rt0ek.westus2.cloudapp.azure.com is already used by another public IP." Details=[]

  on .terraform/modules/network.bastion.bastion_cluster/main.tf line 251, in resource "azurerm_public_ip" "vm":
 251: resource "azurerm_public_ip" "vm" {

Copy link
Contributor Author

@tei-k tei-k Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@penpyt

Excellent point 👍 👍 Fixed in d02cc64.

e.g. Create different public dns for each bastion.

bastion-1-tei-multi-kclkyfk.japaneast.cloudapp.azure.com
bastion-2-tei-multi-kclkyfk.japaneast.cloudapp.azure.com
bastion-3-tei-multi-kclkyfk.japaneast.cloudapp.azure.com

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, Look good to me !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tei-k one last thing, should we modify the outputs.tf (network modules) as well to include the x number of bastion servers to give the user the public dns in output terraform command.

I say that because Kubernetes must use only one bastion but the tools (helm, kubectl) need to be available on everyone on them.

I propose to keep bastion_ip and create bastions_ip as follow, let's me know what do you think?

output "bastion_ip" {
  value = module.network.bastion_ip
}

output "bastions_ip" {
  [OMIT]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@penpyt

I think it's OK to add it to the output, but also need to fix aws as well, So let me do it in other pr. (may not need it now.)

feeblefakie
feeblefakie previously approved these changes Aug 20, 2020
Copy link
Collaborator

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great work!
Since it is an important PR, I would like to wait for 2 more approvals from Paul and Yusuke.

penpyt
penpyt previously approved these changes Aug 20, 2020
Copy link
Contributor

@penpyt penpyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tei-k tei-k dismissed stale reviews from penpyt and feeblefakie via d202477 August 20, 2020 03:12
Copy link
Contributor

@ymorimo ymorimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Left one minor comment.

Copy link
Contributor

@ymorimo ymorimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@penpyt penpyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@feeblefakie feeblefakie merged commit 7f9456b into master Aug 24, 2020
@feeblefakie feeblefakie deleted the multi-az-for-azure branch August 24, 2020 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants