Today DigitalOcean rolled their managed Kubernetes service out into limited availability. Previously we wrote a preview on this and some other managed Kubernetes services by other cloud providers but here I want to deploy a sample web service application onto DigitalOcean’s brand new managed Kubernetes service with the super simple Cloud 66 Skycap. Let’s get started!
What you need
Before we get started, you will need the following:
- A DigitalOcean account signup here.
- A Cloud 66 account signup here.
- Cloud 66 Toolbelt download here.
kubectl(Kubernete’s client CLI) on your laptop learn how here.
Create a Kubernetes Cluster
DigitalOcean managed Kubernetes lets you build a Kubernetes cluster in a few steps. While the worker nodes will be under your own account, the Master nodes will be run and managed by DigitalOcean.
To start, first create a DigitalOcean managed Kubernetes cluster:
It will take a few minutes for your cluster to be available. This is a good time to get our application setup in Skycap.
Create a Skycap Application
Head to your Cloud 66 account and create a new Skycap application. There you can add your application’s service or services to the stack using Skycap UI. For this example, I’m going to use a simple web application written in Go (https://github.com/cloud66-samples/helloworld). I’m using Go to show how Skycap also builds a compiled language like Go into my application containers.
For this, add a new service and use
master as the source of your service, then click Next.
Now you have a Skycap application. Click on Take a Snapshot button to build the code into a Docker image first. This takes a minute. Now you can turn this a Kubernetes-ready application!
Click on Setup Deployment and the choose Formations and then New Formation.
A Formation is like a deployment destination. You can deploy your application to as many as Kubernetes cluster you want (dev, staging, QA, production, Europe, US are some examples).
Let’s call your newly created Formation “DO K8S”.
If you are familiar with Kubernetes, you know that it uses yaml configuration files to define and deploy your application onto it. Formations come with a set of per-built Stencils (ie templates) you can get started with. Later on, you can create your own templates so you can use them again and again for any application.
Choose the “Demos” Stencil Template dropdown and click on Save Information.
For a simple Kubernetes application you need 3 things to be configured on it: a namespace, a “deployment” and a service.
A namespace is pretty clear: it provides a virtual boundary around your application. This is optional (without it you will deploy to the
default namespace but that’s not always a good idea).
A deployment is a definition of how Kubernetes should start your application. Things like the Docker image for your application the port it serves on and the command that starts is are in a deployment.
A service, as the name suggests, serves your application to the outside world. Without it your application will run, but won’t be accessible.
The Demo Stencil Templates has all of these 3 components read made for you to use: simply click on the + button and add them:
First, add the
setup.yml from the list. You will see an editor where you can modify the file that’s based on the template if you want. For now, let’s leave it as it is and commit it into our Formation.
Side note: Formations are backed by a git repository so you can clone them and work on them locally if you prefer that.
Next, let’s add a
deployment.yml. Since our
deployment.yml is generic, you need to make a couple of changes to it before committing into the Formation: first let’s delete the
command line as our Dockerfile already includes a
CMD line. Next let’s put
5000 as the
port as our tiny web application serves traffic on that port. Now submit the
Lastly, add a
service.yml. This also needs to know the port, so we’re going to change the port to
80 and the
5000 as we saw in our deployment. One last step is to change
LoadBalancer in the file. This tells Kubernetes to create a load balancer in DigitalOcean for our service.
Now we have 3 stencils we need to configure the 3 components Kubernetes needs to run our application. So let’s deploy our Formation to the cluster.
If your cluster is ready on DigitalOcean, you will be able to download a configuration file for it. You can use this file to talk to your new Kubernetes cluster with
$ export KUBECONFIG=/PATH/TO/KUBECONFIG/FILE
You can test your
$ kubectl get nodes NAME STATUS ROLES AGE VERSION worker-11623 Ready <none> 2h v1.11.1 worker-11624 Ready <none> 2h v1.11.1
With a working
kubectl ready, we can get our stencils “rendered” into a fully working Kubernetes configuration files with a single command. Click on Render Formation button and copy the command on top of the page (if you don’t see the command, then there is an error in the rendering which you can find more details on if you scroll down on the page).
This Toolbelt command pulls the rendered and concatenated latest version of your Formation Stencils to your terminal where you can feed them into
kubectl and deploy your application:
$ cx snapshots render --stack 'My Awesome App' --snapshot 'sn-xolet-sevym-gybir-ticef-cizud-darop-vufeb-zetuc-vixyx' --formation 'fm-93785ace3188fe66a1242a63db70fcf2' | kubectl apply -f -
NOTE: The first past of the command is the copied one, the second part which is then piped into
kubectlin the second part.
After you run this command, Kubernetes gets to work: it pulls your application image down from your Skycap repository, deploys it and creates a DigitalOcean load balancer. Wait until the load balancer is ready and then hit the IP address.
Your app is up and running!
In the steps above, we did this:
- Create a DigitalOcean Kubernetes cluster
- Create a new Cloud 66 Skycap application + Formations and our applications Stencils
- Deploy the Formation to our new cluster
From this point, any change you’d make to your code can be deployed only by taking a snapshot of your application (click on the Snapshot button) and then re-running the same Toolbelt command every time.
Skycap Formations makes it easy to generate Kubernetes configuration files and reuse them, but they also provide much more:
- Storing templates in a git repository for repeated use across apps
- Secure use of secrets from environment variables or HashiCorp Vault into Kubernetes configuration files
- Reuse of partial configuration files with
- Support for Copper to validate and enforce configuration best practices, as code
- And much more!
- DigitalOcean $100 of Free Credits
- Cloud 66 $100 of Free Credits with code: C66+DOKubes. *Promo Codes apply only to the new users.