This is a creation in Article, where the information may have evolved or changed. In the previous article, we briefly introduced the user interface and the Web client, and how to use the Micro-toolkit RPC Proxy to interact with our newly created RPC service. This article discusses how to create a cloud environment to host our services. We'll use TerraForm to build our cloud cluster on the Google cloud platform. This should be a fairly short article, but it's also important. # # Why Choose TerraForm? I've used several different cloud provisioning solutions, but for me, Hashicorps terraform feel easiest to use and get the best support. In recent years a term has emerged: ' Infrastructure as code '. Why do you want your infrastructure as code? Well, the infrastructure is complex, and it describes a lot of moving parts. It is also important to track changes to the infrastructure and versioning changes. TerraForm the perfect thing to do. They have actually created their own DSL (domain-specific language), which allows you to describe what your infrastructure should look like. TerraForm also allows you to make atomic changes. So in the event of a failure, it will return everything and return it to its original state. TerraForm even allows you to preview changes by executing a go-out schedule. This will accurately describe what your changes will do to your infrastructure. This gives you a lot of confidence that once was a horrible prospect. So let's get started! # # Create your cloud plan go to Google Cloud and create a new project. If you have not used it before, you may find that you have a free trial of £ 300. That's great! Anyway, you should see a blank new item. Now on your left, you should see a iam&admin Tabb, and then create a new service key there. Make sure that provide a new key is selected, and then make sure that you select the JSON type. Safe custody, we need later. This allows the program to perform changes to the Google Cloud API on your behalf. Now we should be in control of everything we need to get started. [] (https://raw.githubusercontent.com/studygolang/gctt-images/master/go-micro/ Screen-shot-2018-02-10-at-10.58.07.png) So create a new repo. I call it my shippy-infrastructure. # # Describe our infrastructure create a new file named VARIABLES.TF. This will contain basic information about our project. Here we have our project ID and IOur project name and our platform name. The region is the data center that we want the cluster to run. The zone is an available zone within the region. The project name is the project ID of our Google project, and finally, the platform name is the name of our cluster. ' cvariable ' gcloud-region ' {default = ' Europe-west2 '}variable ' gcloud-zone ' {default = ' europe-west2-a '}variable ' GC Loud-project "{default =" Shippy-freight "}variable" platform-name "{default =" Shippy-platform "}" to create a named PROVIDERS.TF New file, which is a specific part of Google: "CProvider" google "{credentials =" ${file ("Google-cred.json")} "project =" ${var.gcloud-project "Region =" ${var.gcloud-region} "}" Now let's create a file named GLOBAL.TF. Here is a part of our setup: "C # creates a network Layerresource" Google_compute_network "" shippy-network "{name =" ${ Var.platform-name} "}# creates a firewall with some sane defaults, allowing ports, + 443 to being open# this is ssh, h TTP and Https.resource "Google_compute_firewall" "ssh" {name = "${var.platform-name}-ssh" network = "${google_compute_ Network.shippy-network.name} "Allow {protocol =" ICMP "}allow {protocol =" TCP "ports = [" "", "" + "," 443 "]} source_ranges = ["0.0.0.0/0"]} # Creates a new DNS Zoneresource "Google_dns_managed_zone" "shippy-freight" {name = "shippyfreight-com" DNS_name = "Shippyfr Eight.com. " Description = "shippyfreight.com DNS zone"}# creates a new subnet for we platform within our selected Regionresource "Goo Gle_compute_subnetwork "" Shippy-freight "{name =" Dev-${var.platform-name}-${var.gcloud-region} "Ip_cidr_range =" 10.1.2.0/24 "network =" ${google_compute_network.shippy-network.self_link} "region =" ${var.gcloud-region} "}# Creates A container cluster called ' Shippy-freight-cluster ' # attaches new cluster to our network and we subnet,# ensures at least One instance is Runningresource "Google_container_cluster" "Shippy-freight-cluster" {name = "Shippy-freight-cluster" Network = "${google_compute_network.shippy-network.name}" subnetwork = "${google_compute_ Subnetwork.shippy-freight.name} "zone =" ${var.gcloud-zone} "Initial_node_count = 1master_auth {username = <redacted >password = <redacted>}node_config {# defines the type/size insTance to use#-a sensible starting Pointmachine_type = "N1-standard-1" # Grants OAuth access to the following AP I ' s within the clusteroauth_scopes = ["Https://www.googleapis.com/auth/projecthosting", "https://www.googleapis.com/ Auth/devstorage.full_control "," https://www.googleapis.com/auth/monitoring "," https://www.googleapis.com/auth/ Logging.write "," Https://www.googleapis.com/auth/compute "," Https://www.googleapis.com/auth/cloud-platform "]}}# Creates a new DNS range for Clusterresource "Google_dns_record_set" "dev-k8s-endpoint-shippy-freight" {name = "k8s.dev.${ Google_dns_managed_zone.shippy-freight.dns_name} "type =" A "ttl = 300managed_zone =" ${google_dns_managed_ Zone.shippy-freight.name} "Rrdatas = [" ${google_container_cluster.shippy-freight-cluster.endpoint} "]}" Now move the key you created earlier to the root of the project and name it Google-cred.json. You should have everything right now. You need to create a new cluster! But let's not go crazy, you should test first and check that everything is OK. Run ' $ terraform init '-This will download any missing supplied providers/plugins. This will find that we are using the Google Cloud module and automatically get these dependencies. Now, if you run the ' $ TerraForm ' program, it willShows you the changes it will make. It's almost like doing ' git diff ' on your entire infrastructure. It's cool now! After browsing the deployment plan, I think it's good. > $ terraform Apply Note: You may be asked to enable some APIs to do this, OK, click the link, make sure to enable them and rerun ' $ terraform apply '. If you want to save time, go to the API section of the Google Cloud console and enable the Dns,kubernetes and compute engine APIs. This may take some time, but that's because a lot of things have happened. But once you're done, you should be able to see your new cluster if you go to the Kubernetes engine or the compute engine segment in the menu on the right side of the Google Cloud console. Note: If you do not use the free trial period, this will immediately start spending your money. Be sure to check the instance pricing list. Oh, and I've started my strength between the jobs I've been working on. This does not incur charges, as these charges are based on resource usage. [] (https://raw.githubusercontent.com/studygolang/gctt-images/master/go-micro/Screen-Shot-2018-02-10-at-12.25.11-1.png) only! We have a fully functioning CLUSTER/VM, ready for us to start deploying our containers. The next section of this series describes kubernetes, and how to set up and deploy containers to kubernetes. If you find this series useful, and you use an ad blocker (who can blame you). Please consider donating a few dollars for my time and effort. Cheers! Https://monzo.me/ewanvalentine
via:https://ewanvalentine.io/microservices-in-golang-part-7/
Author: Ewan Valentine Translator: zhangyang9 proofreading: polaris1119
This article by GCTT original compilation, go language Chinese network honor launches
This article was originally translated by GCTT and the Go Language Chinese network. Also want to join the ranks of translators, for open source to do some of their own contribution? Welcome to join Gctt!
Translation work and translations are published only for the purpose of learning and communication, translation work in accordance with the provisions of the CC-BY-NC-SA agreement, if our work has violated your interests, please contact us promptly.
Welcome to the CC-BY-NC-SA agreement, please mark and keep the original/translation link and author/translator information in the text.
The article only represents the author's knowledge and views, if there are different points of view, please line up downstairs to spit groove
571 Reads