Getting Started with Google Container Builder – Part 4

November 20, 2017

Note: This is the fourth part in a series of posts Getting Started with Google Container Builder


 

Configure CD to Kubernetes

In this part we will configure the build to deploy the application to our Kubernetes cluster after each commit (CD).

 

• Add a new kubectl step in the cloudbuild.yaml file to replace the image used by kubernetes to run the application:

steps:
- name: 'gcr.io/cloud-builders/npm'
  args: ['install']
- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/sdp-demo-app:$SHORT_SHA', '.' ]
- name: 'gcr.io/cloud-builders/kubectl'
  args: ['set', 'image', 'deployment/demo-app', 'demo-app=gcr.io/$PROJECT_ID/sdp-demo-app:$SHORT_SHA']
  env:
  - 'CLOUDSDK_COMPUTE_ZONE=europe-west1-c'
  - 'CLOUDSDK_CONTAINER_CLUSTER=demo-cluster'
images:
- 'gcr.io/$PROJECT_ID/sdp-demo-app'
tags:
- 'demo'
- 'nodejs'

 

• Change the application message to test that the CD is working. For this edit the get main function in the “server.js” file to change the message from Hello World! to Hello New World!:

var express = require('express');
var app = express();
var port = 3000;
var primes = require('./primes.js');

app.get('/', function(req, res){
    res.status(200).send('Hello New World!');
})

app.get('/isPrime/:number', function(req, res){
    res.status(200).send(primes.isPrime(req.params.number));    
})

exports.stop = function(){
    server.close();
}
var server = app.listen(port, function(){
  console.log("Express server listening on port %d in %s mode", port, app.settings.env);
});

 

• After commit and push the changes a new build should be triggered in the build history view:

Image

 

• Wait for the build to finish and then browse to the application page

Image

 
 

Continue with: Getting Started with Google Container Builder – Part 5

 

Add comment
facebook linkedin twitter email

Leave a Reply