github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/docs/installing_deis/gce.rst (about)

     1  :title: Installing Deis on Google Compute Engine
     2  :description: How to provision a multi-node Deis cluster on Google Compute Engine
     3  
     4  .. _deis_on_gce:
     5  
     6  Google Compute Engine
     7  =====================
     8  
     9  Let's build a Deis cluster in Google's Compute Engine!
    10  
    11  Please :ref:`get the source <get_the_source>` and refer to the scripts in `contrib/gce`_
    12  while following this documentation.
    13  
    14  
    15  Prerequisites
    16  -------------
    17  
    18  Let's get a few Google things squared away so we can provision VM instances.
    19  
    20  
    21  Install Google Cloud SDK
    22  ^^^^^^^^^^^^^^^^^^^^^^^^
    23  
    24  Install the `Google Cloud SDK`_. You will then need to login with your Google Account:
    25  
    26  .. code-block:: console
    27  
    28      $ gcloud auth login
    29  
    30  
    31  Create New Project
    32  ^^^^^^^^^^^^^^^^^^
    33  
    34  Create a new project in the `Google Developer Console`_. You should get a project ID like
    35  ``orbital-gantry-285`` back. We'll set it as the default for the SDK tools:
    36  
    37  .. code-block:: console
    38  
    39      $ gcloud config set project orbital-gantry-285
    40  
    41  
    42  Enable Billing
    43  ^^^^^^^^^^^^^^
    44  
    45  .. important::
    46  
    47      You will begin to accrue charges once you create resources such as disks and instances.
    48  
    49  Navigate to the project console and then the *Billing & Settings* section in the browser. Click the
    50  *Enable billing* button and fill out the form. This is needed to create resources in Google's
    51  Compute Engine.
    52  
    53  
    54  Initialize Compute Engine
    55  ^^^^^^^^^^^^^^^^^^^^^^^^^
    56  
    57  Google Computer Engine won't be available via the command line tools until it is initialized in the
    58  web console. Navigate to *COMPUTE* -> *COMPUTE ENGINE* -> *VM Instances* in the project console.
    59  The Compute Engine will take a moment to initialize and then be ready to create resources via
    60  ``gcloud compute``.
    61  
    62  
    63  Cloud Init
    64  ----------
    65  
    66  Create your cloud init file using Deis' ``contrib/gce/create-gce-user-data`` script and a new etcd
    67  discovery URL. First, install PyYAML:
    68  
    69  .. code-block:: console
    70  
    71      $ sudo pip install pyyaml
    72  
    73  Then navigate to the ``contrib/gce`` directory:
    74  
    75  .. code-block:: console
    76  
    77      $ cd contrib/gce
    78  
    79  Finally, create the ``gce-user-data`` file:
    80  
    81  .. code-block:: console
    82  
    83      $ ./create-gce-user-data $(curl -s https://discovery.etcd.io/new)
    84  
    85  We should have a ``gce-user-data`` file ready to launch CoreOS nodes with.
    86  
    87  Launch Instances
    88  ----------------
    89  
    90  Create a SSH key that we will use for Deis host communication:
    91  
    92  .. code-block:: console
    93  
    94      $ ssh-keygen -q -t rsa -f ~/.ssh/deis -N '' -C deis
    95  
    96  Create some persistent disks to use for ``/var/lib/docker``. The default root partition of CoreOS
    97  is only around 4 GB and not enough for storing Docker images and instances. The following creates 3
    98  disks sized at 256 GB:
    99  
   100  .. code-block:: console
   101  
   102      $ gcloud compute disks create cored1 cored2 cored3 --size 256GB --type pd-standard --zone us-central1-c
   103  
   104      NAME   ZONE          SIZE_GB TYPE        STATUS
   105      cored1 us-central1-c 256     pd-standard READY
   106      cored2 us-central1-c 256     pd-standard READY
   107      cored3 us-central1-c 256     pd-standard READY
   108  
   109  Launch 3 instances. You can choose another starting CoreOS image from the listing output of
   110  ``gcloud compute images list``:
   111  
   112  .. code-block:: console
   113  
   114      $ for num in 1 2 3; do
   115        gcloud compute instances create core${num} \
   116        --zone us-central1-c \
   117        --machine-type n1-standard-2 \
   118        --metadata-from-file user-data=gce-user-data,sshKeys=$HOME/.ssh/deis.pub \
   119        --disk name=cored${num},device-name=coredocker \
   120        --tags deis \
   121        --image coreos-stable-766-3-0-v20150908 \
   122        --image-project coreos-cloud;
   123      done
   124  
   125      NAME  ZONE          MACHINE_TYPE  INTERNAL_IP   EXTERNAL_IP    STATUS
   126      core1 us-central1-c n1-standard-2 10.240.10.107 108.59.80.10   RUNNING
   127      core2 us-central1-c n1-standard-2 10.240.10.108 108.59.80.11   RUNNING
   128      core3 us-central1-c n1-standard-2 10.240.10.109 108.59.80.12   RUNNING
   129  
   130  .. note::
   131  
   132      The provision script will by default provision ``n1-standard-2`` instances. Choosing a smaller
   133      instance size is not recommended. Please refer to :ref:`system-requirements` for resource
   134      considerations when choosing an instance size to run Deis.
   135  
   136  Load Balancing
   137  --------------
   138  
   139  We will need to load balance the Deis routers so we can get to Deis services (controller and builder) and our applications.
   140  
   141  .. code-block:: console
   142  
   143      $ gcloud compute http-health-checks create basic-check --request-path /health-check
   144      $ gcloud compute target-pools create deis --health-check basic-check --session-affinity CLIENT_IP_PROTO --region us-central1
   145      $ gcloud compute target-pools add-instances deis --instances core1,core2,core3
   146      $ gcloud compute forwarding-rules create deisapp --target-pool deis --region us-central1
   147  
   148      NAME    REGION      IP_ADDRESS     IP_PROTOCOL TARGET
   149      deisapp us-central1 23.251.153.6   TCP         us-central1/targetPools/deis
   150  
   151  Note the forwarding rule external IP address. We will use it as the Deis login endpoint in a future step. Now allow the ports on the CoreOS nodes:
   152  
   153  .. code-block:: console
   154  
   155      $ gcloud compute firewall-rules create deis-router --target-tags deis --allow tcp:80,tcp:443,tcp:2222
   156  
   157  
   158  Configure DNS
   159  -------------
   160  
   161  We can create DNS records in Google Cloud DNS using the ``gcloud`` utility. In our example we will
   162  be using the domain name `deisdemo.io`. Create the zone:
   163  
   164  .. code-block:: console
   165  
   166      $ gcloud dns managed-zones create --dns-name deisdemo.io. --description "Example Deis cluster domain name" deisdemoio
   167      Creating {'dnsName': 'deisdemo.io.', 'name': 'deisdemoio', 'description':
   168      'Example Deis cluster domain name'} in eco-theater-654
   169  
   170      Do you want to continue (Y/n)?  Y
   171  
   172      {
   173          "creationTime": "2014-07-28T00:01:45.835Z",
   174          "description": "Example Deis cluster domain name",
   175          "dnsName": "deisdemo.io.",
   176          "id": "1374035518570040348",
   177          "kind": "dns#managedZone",
   178          "name": "deisdemoio",
   179          "nameServers": [
   180              "ns-cloud-d1.googledomains.com.",
   181              "ns-cloud-d2.googledomains.com.",
   182              "ns-cloud-d3.googledomains.com.",
   183              "ns-cloud-d4.googledomains.com."
   184          ]
   185      }
   186  
   187  Note the `nameServers` array from the output. We will need to setup our upstream domain name
   188  servers to these.
   189  
   190  Now edit the zone to add the Deis endpoint and wildcard DNS:
   191  
   192  .. code-block:: console
   193  
   194      $ gcloud dns record-sets --zone deisdemoio transaction start
   195  
   196  This exports a `transaction.yaml` file.
   197  
   198  .. code-block:: console
   199  
   200      ---
   201      additions:
   202      - kind: dns#resourceRecordSet
   203        name: deisdemo.io.
   204        rrdatas:
   205        - ns-cloud1.googledomains.com. dns-admin.google.com. 1 21600 3600 1209600 300
   206        ttl: 21600
   207        type: SOA
   208      deletions:
   209      - kind: dns#resourceRecordSet
   210        name: deisdemo.io.
   211        rrdatas:
   212        - ns-cloud1.googledomains.com. dns-admin.google.com. 0 21600 3600 1209600 300
   213        ttl: 21600
   214        type: SOA
   215  
   216  You will want to add two records as YAML objects. Here is an example edit for the two A record additions:
   217  
   218  .. code-block:: console
   219  
   220      ---
   221      additions:
   222      - kind: dns#resourceRecordSet
   223        name: deisdemo.io.
   224        rrdatas:
   225        - ns-cloud1.googledomains.com. dns-admin.google.com. 1 21600 3600 1209600 300
   226        ttl: 21600
   227        type: SOA
   228      - kind: dns#resourceRecordSet
   229        name: deis.deisdemo.io.
   230        rrdatas:
   231        - 23.251.153.6
   232        ttl: 21600
   233        type: A
   234      - kind: dns#resourceRecordSet
   235        name: *.dev.deisdemo.io.
   236        rrdatas:
   237        - 23.251.153.6
   238        ttl: 21600
   239        type: A
   240      deletions:
   241      - kind: dns#resourceRecordSet
   242        name: deisdemo.io.
   243        rrdatas:
   244        - ns-cloud1.googledomains.com. dns-admin.google.com. 0 21600 3600 1209600 300
   245        ttl: 21600
   246        type: SOA
   247  
   248  And finaly execute the transaction.
   249  
   250  .. code-block:: console
   251  
   252      $ gcloud dns record-sets --zone deisdemoio transaction execute
   253  
   254  
   255  Install Deis Platform
   256  ---------------------
   257  
   258  Now that you've finished provisioning a cluster, please refer to :ref:`install_deis_platform` to
   259  start installing the platform.
   260  
   261  It works! Enjoy your Deis cluster in Google Compute Engine!
   262  
   263  .. _`contrib/gce`: https://github.com/deis/deis/tree/master/contrib/gce
   264  .. _`Google Cloud SDK`: https://cloud.google.com/compute/docs/gcloud-compute/#install
   265  .. _`Google Developer Console`: https://console.developers.google.com/project