GCP 上使用 Universal 安装工具的多分域 DC/OS

ENTERPRISE

GCP 上 DC/OS 使用 Universal 安装工具添加远程分域的指南。

This guide expects that you already have a running DC/OS cluster based on Universal Installer 0.2. To learn more about running DC/OS with the Universal Installer have a look into the Guide for DC/OS on GCP using the Universal Installer.

You will learn how to place additional infrastructure into a GCP remote region. Remote regions will be connected to each other by using the peering functionality of GCP VNETs.

Prerequisites

  • A running DC/OS Enterprise cluster set up with Universal Installer 0.2 modules
  • A subnet range for your remote region

Getting started with remote region

We expect your already running DC/OS clusters main.tf will look similar to this example. To deploy a remote region we have to do some changes to your main.tf

  1. provider "google" {
  2. version = "~> 2.0"
  3. region = "us-west1"
  4. }
  5. # Used to determine your public IP for forwarding rules
  6. data "http" "whatismyip" {
  7. url = "http://whatismyip.akamai.com/"
  8. }
  9. module "dcos" {
  10. source = "dcos-terraform/dcos/gcp"
  11. version = "~> 0.2.0"
  12. providers = {
  13. google = "google"
  14. }
  15. cluster_name = "my-dcos-demo"
  16. ssh_public_key_file = "<path-to-public-key-file>"
  17. admin_ips = ["${data.http.whatismyip.body}/32"]
  18. num_masters = 3
  19. num_private_agents = 2
  20. num_public_agents = 1
  21. dcos_version = "1.13.3"
  22. dcos_variant = "ee"
  23. dcos_license_key_contents = "${file("./license.txt")}"
  24. # Make sure to set your credentials if you do not want the default EE
  25. # dcos_superuser_username = "superuser-name"
  26. # dcos_superuser_password_hash = "${file("./dcos_superuser_password_hash.sha512")}"
  27. dcos_instance_os = "centos_7"
  28. }
  29. output "masters-ips" {
  30. value = "${module.dcos.masters-ips}"
  31. }
  32. output "cluster-address" {
  33. value = "${module.dcos.masters-loadbalancer}"
  34. }
  35. output "public-agents-loadbalancer" {
  36. value = "${module.dcos.public-agents-loadbalancer}"
  37. }

Remote region provider

The first change we have to apply to your main.tf is adding a specific provider statement for the remote region. In this example we will use us-east1 with the alias us-east1 as our remote region. We also add an alias statement to the provider used deploying our region holding the master instances.

This needs to be done so our modules know which account credentials to use.

Note: Some resources have name length limitations which is the reason we shorten our region name.

  1. provider "google" {
  2. version = "~> 2.0"
  3. region = "us-west1"
  4. alias = "master"
  5. }
  6. provider "google" {
  7. version = "~> 2.0"
  8. region = "us-east1"
  9. alias = "us-east1"
  10. }
  11. # ...

Shared config options

To create the remote region and its infrastructure we will use the same underlying modules as in our master region. This also means there will be some information needed for both infrastructures like cluster_name, admin_ips and ssh_public_key_file. To make the operation easier you should define local variables in your main.tf that will be used in every module.

  1. #...
  2. // lets define variables which are shared between all regions
  3. locals {
  4. ssh_public_key_file = "~/.ssh/id_rsa.pub"
  5. cluster_name = "my-dcos-demo"
  6. admin_ips = ["${data.http.whatismyip.body}/32"]
  7. }
  8. #...

Internal subnetworks

Part of the shared information is which internal subnets are used in your infrastructure. If you did not specify subnet_range, terraform uses the default which is 172.16.0.0/16. The remote region we want to specify needs its own subnet.

IMPORTANT: You should not take the next free network of 172.16/12 as 172.17.0.0/16 is dockers internal network default which will lead to problems.

To have a clear separation between our master and our remote regions we will take 10.128.0.0/16 as our remote regions subnet. Also, we will use a map variable to assign the networks to regions. This will make it easier when adding additional regions in the future.

The locals section will now look like this

  1. #...
  2. // lets define variables which are shared between all regions
  3. locals {
  4. ssh_public_key_file = "~/.ssh/id_rsa.pub"
  5. cluster_name = "my-dcos-demo"
  6. admin_ips = ["${data.http.whatismyip.body}/32"]
  7. region_networks = {
  8. // dont use 172.17/26 as its used by docker.
  9. "master" = "172.16.0.0/16" // this is the default
  10. "us-west1" = "10.65.0.0/16" // default agent network, keep it for the firewall rules
  11. "us-east1" = "10.128.0.0/16"
  12. }
  13. }
  14. #...

The remote region

Before we start changing values within the dcos module we will append the infrastructure definition of the remote region to your main.tf. In our example case we only want to have private agents in our remote region, and both private and public agents can be put in a remote region.

IMPORTANT: Running master instances in remote regions is not supported.

To only start private agents we will set num_bootstrap = 0, num_masters = 0 and num_public_agents = 0. Due to some internal limitation we also have to tell the infrastructure module not preparing load balancers for masters and public agents with lb_disable_public_agents and lb_disable_masters

Another important topic to mention is naming. To distinguish between instances of your main and your remote region we introduced the name_prefix variable which allows you to add a prefix to the name of every resource. In this example we set the name_prefix to the short name of the remote region.

In the following example you will also find the shared config options being used in the module call referenced by e.g. local.ssh_public_key_file.

  1. #...
  2. module "dcos-use1" {
  3. source = "dcos-terraform/infrastructure/gcp"
  4. version = "~> 0.2.0"
  5. providers = {
  6. google = "google.us-east1"
  7. }
  8. admin_ips = ["${local.admin_ips}"]
  9. name_prefix = "use1"
  10. cluster_name = "${local.cluster_name}"
  11. accepted_internal_networks = "${values(local.region_networks)}"
  12. num_bootstrap = 0
  13. num_masters = 0
  14. num_private_agents = 1
  15. num_public_agents = 0
  16. lb_disable_public_agents = true
  17. lb_disable_masters = true
  18. ssh_public_key_file = "${local.ssh_public_key_file}"
  19. subnet_range = "${local.region_networks["us-east1"]}"
  20. }

Peering to the main DC/OS region

We now need to establish a connection between the two infrastructures. The Universal Installer provides a module for this task. In this module we reference data from both infrastructures the main region holding DC/OS masters and the remote region holding your remote private agents.

The only information this module needs to receive is the output of our dcos and dcos-use1 modules. We will append this module to the end of your main.tf

Here is the example network-connection-section

  1. #...
  2. module "network-connection-master-use1" {
  3. source = "dcos-terraform/network-peering/gcp"
  4. version = "~> 0.2.0"
  5. providers = {
  6. google.local = "google.master"
  7. google.remote = "google.us-east1"
  8. }
  9. cluster_name = "${local.cluster_name}"
  10. local_network_name = "master"
  11. local_network_self_link = "${module.dcos.infrastructure.network_self_link}"
  12. remote_network_name = "use1"
  13. remote_network_self_link = "${module.dcos-use1.network_self_link}"
  14. }

Changes to dcos module

At this point its time to do changes to your dcos module so it knows about the remote region and is able to install the remote agents.

  1. Choose a subnet range. In general this change is not needed but we wanted to make your example pretty specific.
  1. `subnet_range = "${local.region_networks["master"]}"`
  1. Add accepted internal networks. Same as in the remote region we need to specify the internal networks to allow internal traffic flow.
  1. `accepted_internal_networks = "${values(local.region_networks)}"`
  1. Change the cluster_name. As this is a shared resource we will make use of the local variable.
  1. `cluster_name = "${local.cluster_name}"`
  1. List the SSH key. This is also a shared resource and we can make use of the local variable
  1. `ssh_public_key_file = "${local.ssh_public_key_file}"`
  1. Add the admin IPs following the same pattern.
  1. `admin_ips = ["${local.admin_ips}"`]
  1. Add the private agents. This nearly the most important new variable. This tells the DC/OS installation module which other agents need to be installed.

    additional_private_agent_ips = ["${module.dcos-use1.private_agents.private_ips}"]

  2. Update the providers section. As we change to explicit alias providers we have to point our dcos module to this specific provider.

    1. providers = {
    2. google = "google.master"
    3. }

Example dcos module

After the changes above got applied your dcos module should look like this

  1. module "dcos" {
  2. source = "dcos-terraform/dcos/gcp"
  3. version = "~> 0.2.0"
  4. providers = {
  5. google = "google.master"
  6. }
  7. cluster_name = "${local.cluster_name}"
  8. ssh_public_key_file = "${local.ssh_public_key_file}"
  9. admin_ips = ["${local.admin_ips}"]
  10. subnet_range = "${local.region_networks["master"]}"
  11. num_masters = 3
  12. num_private_agents = 2
  13. num_public_agents = 1
  14. dcos_version = "1.13.3"
  15. dcos_variant = "ee"
  16. dcos_license_key_contents = "${file("./license.txt")}"
  17. # Make sure to set your credentials if you do not want the default EE
  18. # dcos_superuser_username = "superuser-name"
  19. # dcos_superuser_password_hash = "${file("./dcos_superuser_password_hash.sha512")}"
  20. dcos_instance_os = "centos_7"
  21. accepted_internal_networks = "${values(local.region_networks)}"
  22. additional_private_agent_ips = ["${module.dcos-use1.private_agents.private_ips}"]
  23. }

Full main.tf example

Here is the complete main.tf you should see once you completed this guide.

  1. provider "google" {
  2. version = "~> 2.0"
  3. region = "us-west1"
  4. alias = "master"
  5. }
  6. provider "google" {
  7. version = "~> 2.0"
  8. region = "us-east1"
  9. alias = "us-east1"
  10. }
  11. # Used to determine your public IP for forwarding rules
  12. data "http" "whatismyip" {
  13. url = "http://whatismyip.akamai.com/"
  14. }
  15. // lets define variables which are shared between all regions
  16. locals {
  17. ssh_public_key_file = "~/.ssh/id_rsa.pub"
  18. cluster_name = "my-dcos-demo"
  19. admin_ips = ["${data.http.whatismyip.body}/32"]
  20. region_networks = {
  21. // dont use 172.17/26 as its used by docker.
  22. "master" = "172.16.0.0/16" // this is the default
  23. "us-east1" = "10.128.0.0/16"
  24. }
  25. }
  26. module "dcos" {
  27. source = "dcos-terraform/dcos/gcp"
  28. version = "~> 0.2.0"
  29. providers = {
  30. google = "google.master"
  31. }
  32. cluster_name = "${local.cluster_name}"
  33. ssh_public_key_file = "${local.ssh_public_key_file}"
  34. admin_ips = ["${local.admin_ips}"]
  35. subnet_range = "${local.region_networks["master"]}"
  36. num_masters = 3
  37. num_private_agents = 2
  38. num_public_agents = 1
  39. dcos_version = "1.13.3"
  40. dcos_variant = "ee"
  41. dcos_license_key_contents = "${file("./license.txt")}"
  42. # Make sure to set your credentials if you do not want the default EE
  43. # dcos_superuser_username = "superuser-name"
  44. # dcos_superuser_password_hash = "${file("./dcos_superuser_password_hash.sha512")}"
  45. dcos_instance_os = "centos_7"
  46. accepted_internal_networks = "${values(local.region_networks)}"
  47. additional_private_agent_ips = ["${module.dcos-use1.private_agents.private_ips}"]
  48. }
  49. output "masters-ips" {
  50. value = "${module.dcos.masters-ips}"
  51. }
  52. output "cluster-address" {
  53. value = "${module.dcos.masters-loadbalancer}"
  54. }
  55. output "public-agents-loadbalancer" {
  56. value = "${module.dcos.public-agents-loadbalancer}"
  57. }
  58. module "dcos-use1" {
  59. source = "dcos-terraform/infrastructure/gcp"
  60. version = "~> 0.2.0"
  61. providers = {
  62. google = "google.us-east1"
  63. }
  64. admin_ips = ["${local.admin_ips}"]
  65. name_prefix = "use1"
  66. cluster_name = "${local.cluster_name}"
  67. accepted_internal_networks = "${values(local.region_networks)}"
  68. num_bootstrap = 0
  69. num_masters = 0
  70. num_private_agents = 1
  71. num_public_agents = 0
  72. lb_disable_public_agents = true
  73. lb_disable_masters = true
  74. ssh_public_key_file = "${local.ssh_public_key_file}"
  75. subnet_range = "${local.region_networks["us-east1"]}"
  76. }
  77. module "network-connection-master-use1" {
  78. source = "dcos-terraform/network-peering/gcp"
  79. version = "~> 0.2.0"
  80. providers = {
  81. google.local = "google.master"
  82. google.remote = "google.us-east1"
  83. }
  84. cluster_name = "${local.cluster_name}"
  85. local_network_name = "master"
  86. local_network_self_link = "${module.dcos.infrastructure.network_self_link}"
  87. remote_network_name = "use1"
  88. remote_network_self_link = "${module.dcos-use1.network_self_link}"
  89. }