All you really need for this tutorial is some basic Linux knowledge
You are going to learn
- how to create a cluster of nodes in the cloud
- how to create persistent disks for your data in the cloud
- how to collect and view logs from your cluster
- $300 free trial gift from Google
- Why cloud platform providers give us free stuff ?
- Cloud platform agnostic approach using Kubernetes
- 1Register for the free trial
- 2Install gcloud and kubectl tools
- 3Create a one node cluster
- 4Add Service Account for your application
- 5Create Google Cloud Engine Persistent Disk
- 6Add persistent disk to your instance and format it
- 7Detach persistent disk from VM instance
- 8Enable Google Cloud Logging - Basic Tier
$300 free trial gift from Google
Google has done something awesome. They’ve presented us with a gift that will surely win them some developer love.
That was a smart move on their part. If you get a developer excited about something then often it spreads to his whole team like a virus. $300 bucks for free in cloud services is pretty exciting to all the coders out there who wanted to “touch” the cloud but never had the chance. I have to say that Google Cloud Platform is a great place to start your adventure with cloud development.
Additionally there are some services that are always free. For example they’ve allowed for free usage of a small (f1-micro) instance in Compute Engine (if you create them in us-east1, us-west1 and us-central1 regions). You can check what else is free. You can also take a look at what is always-free if you don’t exceed some quotas.
Why cloud platform providers give us free stuff ?
I don’t usually like to look a gifted horse in the mouth but there is always a catch when companies like Amazon or Google give you something for “free”. You get so many free services that it is easy to get yourself attached to one cloud platform provider. You need to decide what to use and what not to use in your applications. From time to time ask yourself following questions:
If I decide to switch cloud providers will I be able to ?
Can I transfer all my services and data without a hassle and loss/degradation of functionality ?
Cloud platform agnostic approach using Kubernetes
You probably don’t want to get too tightly coupled with a specific platform early on. A wise thing to do is plan cloud platform agnostic approach to your apps’ deployment. My advice is to use this opportunity to learn something interesting about containerized applications creation and deployment in the cloud. At the first glance the subject seems a bit complicated but this is where Kubernetes comes in.
Kubernetes just makes everything simple. This solution also eliminates the need to care about some of the convoluted and time consuming things. Things that are not always easy to set up properly eg. networking . If you are a developer then you will probably love it. When you use Kubernetes everything just auto-magically works (most of the time 🙂 ).
Strictly speaking in IT jargon, Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. You can learn more about Kubernetes here.
Kubernetes also runs on Amazon Web Services, Microsoft Azure, IBM Bluemix and many more.
Start your adventure with Google Cloud and Kubernetes now !
I believe that you are capable of registering for a service on your own and you don't need a bunch of stupid screenshots to guide you. You will need a credit card number to finish the registration. Nothing is charged to your credit card until you enable billing and you never actually have to do that if you don't want to. If you run out of free tier gift money with no billing enabled then your resources will be stopped. You can learn more about the end of free trial here.
Remember to add following line to the end of
Both of those tools have an extremely handy autocomplete feature. Double-tap TAB key to autocomplete not only commands but also names of the resources and objects.
I will use names example and example.com everywhere. Just replace them with the name of your choice.
You can manage your Google Cloud using a Console available at: https://console.developers.google.com
Go there and create a project first. Choose a general name for your project. Keep in mind that you can manage multiple applications using one project.
Next use gcloud tool to create a new cluster in a compute zone that is the best fit for you.
To list all available zones use
Project name: example
Compute zone: europe-west1-d (choose your own compute zone)
Cluster name: my-cluster
Instance type: g1-small
You need to create first.
Go to Google Cloud Platform ConsoleAPI ManagerCredentials
Click Create credentials button and choose Service account key
Choose Compute Engine default service account and JSON
Save the JSON file in your home directory
Add following line to your
Open new terminal or run following command to apply the changes you've made to
Run following commands. First one will log you in so that you can finally manage your cluster. Second one will print some information about your cluster
Command below makes your cluster's Kubernetes UI available under http://localhost:8001/ui
You will need a persistent storage for your application. Kubernetes gives you the ability to hook up a lot of different storage options but for this tutorial you will use Google Cloud Engine's .
First of all you need to create a Persistent Disk. You can either do it using Google Cloud Platform Console or command line. If you wish to create disk that has size lower than 10GB then you need to use command line.
Create persistent disk using Google Cloud Platform Console
Go to Google Cloud Platform ConsoleCompute EngineDisks
At the top of the page click Create disk
Now under Source type you have to click None (blank disk) tab and set the size you want your disk to have
Disk Type: Standard persistent disk (cheaper option)
Enter zone, name and other parameters according to your needs
Create persistent disk using the command line
If you do not wish to continue with the Kubernetes tutorial then substitute
PROJECT_NAME-wordpress with the name you want for your disk. Otherwise you should create two disks. One for WordPress with name matching the pattern
PROJECT_NAME-wordpress and one for MySQL named:
Don't get scared. Adding to your instance is a piece of cake. Just a few clicks in Google Cloud Platform Console and a few commands to run. If you wish to continue with Kubernetes tutorial then keep in mind that both drives you've created need to be formatted.
Follow this tutorial but do not mount the disk to the instance and do not add anything to /etc/fstab. Last step you should do is formatting the drive.
In addition now you also know how to connect to the VM instance inside your cluster should you ever need it.
Detaching disks is especially important if you wish to continue with Kubernetes tutorial.
Let's restart the VM instance. This is done just to make sure that the problem described in the notes to this step does not occur.
I do not like the fact that detaching disks can cause the problem described below. I've decreased the reliability of this step to Medium as a result. Last checked on Kubernetes ver. 1.6.4
VM instance attached disk and Kubernetes problem description
You will not be able to use your disk with Kubernetes if you do not detach your disks. Your Persistent Volumes will not be able to bind to disk that is already attached to a VM instance.
If you still get errors similar to the ones below then you probably need to restart the VM instance.
When you describe your Pod
Output: mount: cannot remount /var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/DISK_NAME read-write, is write-protected
When you look at your VM instance's logs
Orphaned pod "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX" found, but volume paths are still present on disk.
Two times that I have been formatting disks using Google's own tutorial I had that situation so I guess you might encounter it as well.
Restarting the VM instance seems to be the most simple solution to fix the problem. Instead of restarting the instance you can kill two birds with one stone and update your cluster's Kubernetes if you have an update available. You can also format the drives on some other instance and avoid the problem altogether.
Basic Tier of logging service is free if your monthly logs never exceed 5GB OR you do not agree to pay overage charges ever.
Run command below and go to your cluster's Kubernetes UI at http://localhost:8001/ui
Select All namespaces. Take a look at the logs of the Pod named
You might see a warning like that:
[warn]: Dropping 2 log message(s) error_class="Google::Apis::ClientError" error="forbidden: Stackdriver Logging API has not been used in project PROJECT_NAME before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/logging.googleapis.com/overview?project=PROJECT_NAME then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
Stackdriver's Basic Tier no cost usage details
Before you enable it, check current information on what is billable and what is free in Stackdriver's Basic Tier. You do not want to find something out at the very moment the invoice arrives. Especially take notice of overage charges.
Overage charges apply when you exceed the limit. On the day that I published this for Premium Tier accounts, overage charges are billed automatically but in Basic Tier you must sign up to pay overage charges. As always there is a catch. If you want to use logs-based or custom metrics in the Basic Tier, you must agree to pay overage charges. If you never agree to it then after exceeding 5GB logs are no longer gathered until you get another 5GB of quota.
Since Basic Tier of Stackdriver is free plus you get 30 day trial of Premium Tier let's turn it on and check it out.
If you don't like it I guess you can always disable it in Google Cloud Platform ConsoleAPI ManagerDashboard.
According to Stackdriver pricing page, start of billing occurs only after free trial expires. You can choose to use Basic Tier at that moment.
Enable Stackdriver Logging
First you need to enable the Stackdriver API.
You can use the link from the warning message. Alternatively you can go to Google Cloud Platform ConsoleAPI ManagerLibrary and search for stackdriver.
Enable Stackdriver Logging API.
As it says in the warning message, you might need to wait a few minutes before the changes propagate.
Go to Google Cloud Platform ConsoleLogging
All the logs are in one place now. You can use filters to go through them. For example using the first selectbox choose GKE containermy-clusterkube-system to see logs from resources in one namespace only.
Basic Tier allows 50GB to use monthly per project without additional charges. You can check you usage and estimated monthly usage under Google Cloud Platform ConsoleLoggingResource usage
Go to Google Cloud Platform ConsoleAPI ManagerDashboard. You should see that Stackdriver Logging API is in use.
You can do much more with your logs using Stackdriver. For more information on it check out