Cloud Native Blog - Container Solutions

Running Kontena in the Google Cloud

Written by Maarten Hoogendoorn | Oct 19, 2016 1:00:56 PM

In this blog post we'll set up Kontena on top of CoreOS on GCE. In the previous blog, I described Kontena's architecture.

Register an account

We'll use the authentication service hosted by kontena.

To register an account, we need to install the command line interface. It's packaged at the moment as a ruby gem, so make sure that ruby is installed.

I personally use this trick to install gems local to a project directory:

  
cat env.sh
(out) export GEM_HOME=`pwd`/.gems
(out) export PATH=$PATH:`pwd`/.gems/bin
source env.sh # evaluate the exports in the current shell

And install the cli, and register an account. Follow the instructions provided by the client.

  
gem install kontena-cli
kontena register

Setting up the GCE instances.

We'll adapt the instructions on how to set up a CoreOS cluster. I recommend to browse through them as well, to get a feeling of what we're about to do.

Setup of the Kontena Master

  1. Create a master.yml file with the cloud config content described on the CoreOS cluster page.
  2. Follow the instructions to create random values for KONTENA_VAULT_KEY and KONTENA_VAULT_IV with the provided command cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1. Put them in the master.yml file.
  3. Now we should add a SSL certificate to encrypt the http traffic. If you're going to deploy something else than an experiment, I strongly recomment to get a domain name, and get a valid certificate. A Let's Encrypt certificate will do.

    We'll create a self signed certificate for now, because we will not be using a domain name.

      
    openssl genrsa -out private.key 2048
    openssl req -new -key private.key -out public.csr -subj "/CN=kontena-master/"
    openssl x509 -req -days 365 -in public.csr -signkey private.key -out public.crt
    cat public.crt private.key > kontena-master.pem
    cat kontena-master.pem
    

    Copy the content of kontena-master.pem in the master.yml file. Mind the indentation!

  4. Now we'll create the master server. I picked the instructions on how to create a CoreOS stable instance from the CoreOS documentation.

      
    gcloud compute instances create kontena-master \
    (out)    --image https://www.googleapis.com/compute/v1/projects/coreos-cloud/global/images/coreos-stable-1122-2-0-v20160906 \
    (out)    --zone europe-west1-b \
    (out)    --machine-type n1-standard-1 \
    (out)    --metadata-from-file user-data=master.yml \
    (out)    --tags=http-server,https-server
    

    Find the external IP address of the master in the output from gcloud, and put it in an environmental variable.

      
    export KONTENA_MASTER_IP=aaa.bbb.ccc.ddd
    	
    	
  5. As the last step of setting up the master, we'll log in to it. Note that we have to ignore the validity of our self-signed certificate. This is not how things should be done, but will get a fast result for a quick evaluation.

      
    SSL_IGNORE_ERRORS=true kontena login --name kontena-master-gce https://$KONTENA_MASTER_IP
    

Creating a grid, and adding nodes to it.

  1. We'll create a grid, a logical grouping of nodes, first.
      
    SSL_IGNORE_ERRORS=true kontena grid create testgrid
    
  2. The next step is to generate a generic cloud-config.yml for the nodes:
      
    SSL_IGNORE_ERRORS=true kontena grid cloud-config testgrid > grid_node.yml
    
  3. We finish with creating the nodes themselves using the gcloud tool:
      
    gcloud compute instances create \
    (out)     kontena-testgrid-node1 \
    (out)     --image https://www.googleapis.com/compute/v1/projects/coreos-cloud/global/images/coreos-stable-1122-2-0-v20160906 \
    (out)     --zone europe-west1-b \
    (out)     --machine-type n1-standard-1 \
    (out)     --metadata-from-file user-data=grid_node.yml \
    (out)     --tags=http-server,https-server
    (out)
    gcloud compute instances create \
    (out)     kontena-testgrid-node2 \
    (out)     --image https://www.googleapis.com/compute/v1/projects/coreos-cloud/global/images/coreos-stable-1122-2-0-v20160906 \
    (out)     --zone europe-west1-b \
    (out)     --machine-type n1-standard-1 \
    (out)     --metadata-from-file user-data=grid_node.yml \
    (out)     --tags=http-server,https-server
    
    gcloud compute instances create \
    (out)     kontena-testgrid-node3 \
    (out)     --image https://www.googleapis.com/compute/v1/projects/coreos-cloud/global/images/coreos-stable-1122-2-0-v20160906 \
    (out)     --zone europe-west1-b \
    (out)     --machine-type n1-standard-1 \
    (out)     --metadata-from-file user-data=grid_node.yml \
    (out)     --tags=http-server,https-server
    
nten

Take a look at some of the provided example applications on GitHub. Clone the repo, go to one of the directories containing a kontena.yml file, and run kontena app deploy to deploy that application.