GCP 上使用通用安装工具的 DC/OS

使用 Universal 安装工具在 GCP 上的 DC/OS 指南

This guide is meant to take an operator through all steps necessary for a successful installation of DC/OS using Terraform. If you are already familiar with the prerequisites, you can jump to Creating a DC/OS Cluster.

Prerequisites

  • Linux, macOS, or Windows
  • command-line shell terminal such as Bash or PowerShell
  • verified Azure Resource Manager account with the necessary permissions

Install Terraform

IMPORTANT: Terraform was updated to 0.12.x. The DC/OS Universal Installer currently only supports Terraform 0.11.x

  1. Visit the Terraform releases page for bundled installations and support for Linux, macOS and Windows. Choose the latest 0.11 version.

    If you’re on a Mac environment with Homebrew installed, simply run the following command:

    1. brew unlink terraform || true
    2. brew install tfenv
    3. tfenv install 0.11.14

    Windows users that have Chocolatey installed, run:

    1. choco install terraform --version 0.11.14 -y

Get Application Default Credentials for authentication

You will need the Application Default CredentialsTerraform Google provider reference.

To receive Application Default Credentials:

  1. Run the following command:
  1. $ gcloud auth application-default login
  1. Verify that you have Application Default Credentials by running the following command:
  1. $ gcloud auth application-default print-access-token
  2. EXMAPLE.EXAMPLE-1llO--ZEvh6gQ-qhpL0I3gHcCeDKG_EXAMPLE7WtAepmpp47c0RCv9e0Oq6QnpQ79RZlHKzOw69XMxI87M2Q

Set the GCP default region and project

The GCP provider requires you to export the Region (desired-gcp-region) and Project (desired-gcp-project) identifiers into environment variables even if those values are set in the gcloud-cli. You can set them easily in your terminal.

  1. export GOOGLE_REGION="us-west1"
  2. export GOOGLE_PROJECT="my-project-id"

Alternatively, they can be inserted into the configuration file you will create. Please keep in mind storing your credentials outside of your version control for security.

  1. provider "google" {
  2. version = "~> 2.0"
  3. credentials = "${file("account.json")}"
  4. project = "my-project-id"
  5. region = "us-west1"
  6. zone = "us-west1-b"
  7. }

Verify you have a license key for Enterprise Edition

DC/OS Enterprise requires a valid license key provided by Mesosphere that will be passed into the main.tf configuration file as dcos_license_key_contents. If you do not set a password, the default superuser and password will be available for log in:

Username: bootstrapuser
Password: deleteme

IMPORTANT: You should NOT use the default credentials in a production environment. When you create or identify an administrative account for the production environment, you also need to generate a password hash for the account.

To set superuser credentials for the first log in, add the following values into your main.tf along with your license key. The password will need to be hashed to SHA-512.

  1. dcos_superuser_username = "superuser-name"
  2. dcos_superuser_password_hash = "${file("./dcos_superuser_password_hash")}

Creating a DC/OS Cluster

  1. Let’s start by creating a local folder and cd’ing into it. This folder will be used as the staging ground for downloading all required Terraform modules and holding the configuration for the cluster you are about to create.

    1. mkdir dcos-demo && cd dcos-demo
  2. Create a file in that folder called main.tf, which is the configuration file that will be called on each time when terraform runs. The name of this file should always be main.tf. Open the file in the code editor of your choice and paste in the following. Notice the copy icon in the upper right hand corner of the code block to copy the code to your clipboard:

    1. provider "google" {
    2. version = "~> 2.0"
    3. region = "us-west1"
    4. }
    5. module "dcos" {
    6. source = "dcos-terraform/dcos/gcp"
    7. version = "~> 0.2.0"
    8. providers = {
    9. google = "google"
    10. }
    11. cluster_name = "my-dcos-demo"
    12. ssh_public_key_file = "<path-to-public-key-file>"
    13. admin_ips = ["${data.http.whatismyip.body}/32"]
    14. num_masters = 3
    15. num_private_agents = 2
    16. num_public_agents = 1
    17. dcos_version = "1.13.3"
    18. # Enterprise users uncomment this section and comment out below
    19. # dcos_variant = "ee"
    20. # dcos_license_key_contents = "${file("./license.txt")}"
    21. # Make sure to set your credentials if you do not want the default EE
    22. # dcos_superuser_password_hash = "${file("./dcos_superuser_password_hash.sha512")}
    23. # dcos_superuser_username = "admin"
    24. dcos_variant = "open"
    25. }
    26. output "masters-ips" {
    27. value = "${module.dcos.masters-ips}"
    28. }
    29. output "cluster-address" {
    30. value = "${module.dcos.masters-loadbalancer}"
    31. }
    32. output "public-agents-loadbalancer" {
    33. value = "${module.dcos.public-agents-loadbalancer}"
    34. }
  3. There is a main variable that must be set to complete the main.tf:

    • ssh_public_key_file = "<path-to-public-key-file>": the path to the public key for your cluster, following our example it would be:

      1. "~/.ssh/gcp-key.pub"
  4. region is a setting that sets the GCP region that this DC/OS cluster will spin up on. While this setting is currently set to “us-west1”, it can be changed to any other region (e.g “us-east1”, “us-central1”, etc).

  5. Enterprise users, uncomment/comment the section for the dcos_variant to look like this, inserting the location to your license key, and adding superuser credentials if needed. Enterprise

    1. dcos_variant = "ee"
    2. dcos_license_key_contents = "${file("./license.txt")}"
    3. # dcos_variant = "open"

You can find additional input variables and their descriptions here.

  1. This sample configuration file will get you started on the installation of an open source DC/OS 1.13.3 cluster with the following nodes:

    • 3 Master
    • 2 Private Agents
    • 1 Public Agent

    If you want to change the cluster name or vary the number of masters/agents, feel free to adjust those values now as well. Cluster names must be unique, consist of alphanumeric characters, ‘-’, ‘_’ or ‘.’, start and end with an alphanumeric character, and be no longer than 24 characters. You can find additional input variables and their descriptions here.

    There are also simple helpers listed underneath the module which find your public ip and specify that the following output should be printed once cluster creation is complete:

    • master-ips A list of Your DC/OS master nodes
    • cluster-address The URL you use to access DC/OS UI after the cluster is setup.
    • public-agent-loadbalancer The URL of your Public routable services.
  2. Check that you have inserted your cloud provider and public key paths to main.tf, changed or added any other additional variables as wanted, then save and close your file.

Initialize Terraform and create a cluster

  1. Now the action of actually creating your cluster and installing DC/OS begins. First, initialize the project’s local settings and data. Make sure you are still working in the same folder where you created your main.tf file, and run the initialization.

    1. terraform init -upgrade
    1. Terraform has been successfully initialized!
    2. You may now begin working with Terraform. Try running "terraform plan" to see
    3. any changes that are required for your infrastructure. All Terraform commands
    4. should now work.
    5. If you ever set or change modules or backend configuration for Terraform,
    6. rerun this command to reinitialize your environment. If you forget, other
    7. commands will detect it and remind you to do so if necessary.

    Note: If terraform is not able to connect to your provider, ensure that you are logged in and are exporting your credentials and necessary region information for your cloud provider.

  2. After Terraform has been initialized, the next step is to run the execution planner and save the plan to a static file - in this case, plan.out.

    1. terraform plan -out=plan.out

    Writing the execution plan to a file allows us to pass the execution plan to the apply command below as well help us guarantee the accuracy of the plan. Note that this file is ONLY readable by Terraform.

    Afterwards, we should see a message like the one below, confirming that we have successfully saved to the plan.out file. This file should appear in your dcos-demo folder alongside main.tf.

    1. Plan: 74 to add, 3 to change, 0 to destroy.
    2. ------------------------------------------------------------------------
    3. This plan was saved to: plan.out
    4. To perform exactly these actions, run the following command to apply:
    5. terraform apply "plan.out"

    Every time you run terraform plan, the output will always detail the resources your plan will be adding, changing or destroying. Since we are creating our DC/OS cluster for the very first time, our output tells us that our plan will result in adding 38 pieces of infrastructure/resources.

  3. The next step is to get Terraform to build/deploy our plan. Run the command below.

    1. terraform apply plan.out

    Sit back and enjoy! The infrastructure of your DC/OS cluster is being created while you watch. This may take a few minutes.

    Once Terraform has completed applying the plan, you should see output similar to the following:

    1. Apply complete! Resources: 74 added, 0 changed, 0 destroyed.
    2. Outputs:
    3. cluster-address = testing-123-958581895.us-east-1.elb.amazonaws.com
    4. masters-ips = [
    5. 3.93.239.91
    6. ]
    7. public-agents-loadbalancer = ext-testing-123-40f11d1227e88057.elb.us-east-1.amazonaws.com

    And congratulations - you’re up and running!

Logging in to DC/OS

  1. To log in and start exploring your cluster, navigate to the cluster-address listed in the output of the CLI. From here you can choose your provider to create the superuser account Open Source, or log in with your specified Enterprise credentials Enterprise.

GCP - 图1

GCP - 图2

Scaling Your Cluster

Terraform makes it easy to scale your cluster to add additional agents (public or private) once the initial cluster has been created. Simply follow the instructions below.

  1. Increase the value for the num_private_agents and/or num_public_agents in your main.tf file. In this example we are going to scale our cluster from 2 private agents to 3, changing just that line, and saving the file.

    1. num_masters = "1"
    2. num_private_agents = "3"
    3. num_public_agents = "1"
  2. Now that we’ve made changes to our main.tf, we need to re-run our new execution plan.

    1. terraform plan -out=plan.out

    Doing this helps us to ensure that our state is stable and to confirm that we will only be creating the resources necessary to scale our Private Agents to the desired number.

    GCP - 图3

    You should see a message similar to above. There will be 3 resources added as a result of scaling up our cluster’s Private Agents (1 instance resource & 2 null resources which handle the DC/OS installation & prerequisites behind the scenes).

  3. Now that our plan is set, just like before, let’s get Terraform to build/deploy it.

    1. terraform apply plan.out

    GCP - 图4

    Once you see an output like the message above, check your DC/OS cluster to ensure the additional agents have been added.

    You should see now 4 total nodes connected like below via the DC/OS UI.

    GCP - 图5

Upgrading Your Cluster

Terraform also makes it easy to upgrade our cluster to a newer version of DC/OS. If you are interested in learning more about the upgrade procedure that Terraform performs, please see the official DC/OS Upgrade documentation.

  1. In order to perform an upgrade, we need to go back to our main.tf and modify the current DC/OS Version (dcos_version) to a newer version, such as 1.13.3 for this example.

    1. dcos_version = "1.13.3"
  2. We also should make sure having the latest version of the Terraform modules. So we tell Terraform to request those from the registry.

    1. terraform get -update
  3. Re-run the execution plan, terraform will notice the change in version and run accordingly.

    1. terraform plan -out=plan.out

    You should see an output like below, with your main.tf now set for normal operations on a new version of DC/OS.

    GCP - 图6

  4. Apply the plan.

    1. terraform apply plan.out

    Once the apply completes, you can verify that the cluster was upgraded via the DC/OS UI.

    GCP - 图7

Deleting Your Cluster

If you want to destroy your cluster, then use the following command and wait for it to complete.

  1. terraform destroy

Important: Running this command will cause your entire cluster and all of its associated resources to be destroyed. Only run this command if you are absolutely sure you no longer need access to your cluster.

You will be required to enter yes to verify.

GCP - 图8

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

ENTERPRISE

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

配置参考 - GCP

使用 Mesosphere Universal 安装工具在 GCP 上配置您的 DC/OS 安装