Star  Watch  Fork  Follow  Issues

Yaydoc Deployment to Google Cloud with Kubernetes


  • If you don’t already have a Google Account (Gmail or Google Apps), you must create one. Then, sign-in to Google Cloud Platform console ( and create a new project:

  • Store your project ID into a variable as many commands below use it:

    export PROJECT_ID="your-project-id"
  • Next, enable billing in the Cloud Console in order to use Google Cloud resources and enable the Container Engine API.

  • Install Docker, and Google Cloud SDK.

  • Finally, after Google Cloud SDK installs, run the following command to install kubectl:

    gcloud components install kubectl
  • Choose a Google Cloud Project zone to run your service. We will be using us-west1-a. This is configured on the command line via:

    gcloud config set compute/zone us-west1-a

Create and format a persistent data disk for MongoDB

  • Create a persistent disk. (min. 1 GB) with a name mongo-disk.

    gcloud compute disks create mongo-disk --size 1GB
  • The disk created is un formatted and needs to be formatted. To do that, we need to create a temporarily compute instance.

    gcloud compute instances create mongo-disk-formatter
  • Wait for the instance to get created. Once done, attach the disk to that instance.

    gcloud compute instances attach-disk mongo-disk-formatter --disk mongo-disk
  • SSH into the instance.

    gcloud compute ssh "mongo-disk-formatter"
  • In the terminal, use the ls command to list the disks that are attached to your instance and find the disk that you want to format and mount

    ls /dev/disk/by-id
    google-example-instance       scsi-0Google_PersistentDisk_example-instance
    google-example-instance-part1 scsi-0Google_PersistentDisk_example-instance-part1
    google-[DISK_NAME]            scsi-0Google_PersistentDisk_[DISK_NAME]

    where [DISK_NAME] is the name of the persistent disk that you attached to the instance.

    The disk ID usually includes the name of your persistent disk with a google- prefix or a scsi-0Google_PersistentDisk_ prefix. You can use either ID to specify your disk, but this example uses the ID with the google- prefix

  • Format the disk with a single ext4 filesystem using the mkfs tool. This command deletes all data from the specified disk.

    sudo mkfs.ext4 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/google-[DISK_NAME]
  • The disk is formatted and ready.

  • Now exit the SSH session and Detach the disk from the instance by running

    gcloud compute instances detach-disk mongo-disk-formatter --disk mongo-disk

You can delete the instance if your not planning to use it for anything else. But make sure the disk mongo-disk is not deleted.

Create your Kubernetes Cluster

  • Create a cluster via the gcloud command line tool:

    gcloud container clusters create yaydoc-cluster
  • Get the credentials for kubectl to use.

    gcloud container clusters get-credentials yaydoc-cluster

Pre deployment steps

  • A domain name (Eg.,, - A free domain can be registered at .

  • Reserve a static external IP address

    gcloud compute addresses create testip --region us-west1

    The response would be similar to

    creationTimestamp: '2017-05-16T05:26:24.894-07:00'
    description: ''
    id: '1234556789'
    kind: compute#address
    name: test
    status: RESERVED

    Note down the address. (In this case We’ll call this External IP Address One.

  • Add the External IP Address One as an A record to your domain’s DNS Zone.

  • Add the External IP Address One to kubernetes/yamls/nginx/service.yml for the parameter loadBalancerIP.

  • Add your domain name to kubernetes/yamls/web/ingress-notls.yml & kubernetes/yamls/web/ingress-tls.yml. (replace

  • In kubernetes/yamls/mongo/mongo-deployment.yml ensure pdName is mongo-disk. Else change it.

Deploy our pods, services and deployments

  • Update the kubernetes/yamls/yaydoc/configmap.yml file with relevant values for the defined environment varaibles.

  • From the project directory, use the provided deploy script to deploy our application from the defined configuration files that are in the kubernetes directory.

    ./kubernetes/ create all
  • The Kubernetes master creates the load balancer and related Compute Engine forwarding rules, target pools, and firewall rules to make the service fully accessible from outside of Google Cloud Platform.

  • Wait for a few minutes for all the containers to be created and the SSL Certificates to be generated and loaded.

  • You can track the progress using the Web GUI as mentioned below.

  • Once deployed, your instance will be accessible at your domain name.

Other handy commands

  • Delete all created pods, services and deployments

    ./kubernetes/ delete all
  • Access The Kubernetes dashboard Web GUI

    Run the following command to start a proxy.

    kubectl proxy

    and Goto http://localhost:8001/ui

  • Deleting the cluster

    gcloud container clusters delete yaydoc-cluster