Warning
Running this tutorial on Digital Ocean (or any other public cloud provider) will incurr some costs. The entire tutorial should cost less than $1 (USD) as long as you start and finish the steps within a few hours and delete everything when you’re finished.
If you cannot use DigitalOcean or something similar, you still have options to experiment with Kubernetes. I recommend looking through one of these resources:
Intro
This is the third article in a series I plan to write about Kubernetes. The previous articles can be found here:
In this post, I’ll go over the basics of creating your first Kubernetes cluster. I’ll be showing you how to do this on Digital Ocean, but you should be able to follow along with whatever service you choose to use. Specifically, the things we’ll do are:
- Spin up a Kubernetes on Digital Ocean
- Deploy the Kubernetes dashboard to your cluster
- Deploy Traefik as your Ingress controller
- Deploy a simple hello world application
- Test reliability in Kubernetes by causing failures
Prerequisites
You’ll need to have the following installed on your machine to go through this tutorial:
- Kubectl
- Docker
Create your Kubernetes Cluster
This part is easy. Simply log into your DigitalOcean account and go to the Kubernetes tab. For the purpose of this tutorial, we’ll start out with the smallest possible cluster: A single node of the smallest size.
Talk to your Cluster
The main way to talk to you cluster is via a command line tool called kubectl.
To provide kubectl with the information it needs to talk to your cluster,
you will need to download a configuration file from your Digital Ocean dashboard.
A download link can be found by opening the cluster you created. Note that the credentials in here will be valid for about a week. After that you will need to re-download a new file.
Install Kubernetes Dashboard
The Kubernetes dashboard provides a very nice web interface to examine and administer your cluster. The dashboard is also an application that runs in your cluser. It will therefore need to be deployed similar to how you would deploy your own custom applications.
Before following the instructions in the documentation to deploy the dashboard, let’s take a peek at the file they want us to push to our cluser:
If you read the previous post in this series, you should see a few familiar words such as “Deployment” and “ReplicaSet” and “Pod”.
Deploying an Application
Next we’re going to deploy a simple “hello world” application. In the next tutorial I’ll show you how to deploy your own custom code, but for this purposes of this tutorial I’m going to show you how to deploy an unmodified nginx image to your cluster. But first, let’s run it locally to make sure we understand what it should do. If you have docker installed simply execute the following command:
|
|
If you open http://localhost/ in your browser, you should be greeted by the standard nginx welcome page. To shut down the locally running container, just type the following two commands:
|
|
Deploying the Application
Now that we’ve seen our application running locally, it’s time to push it to our cluser.
To do this, we create a deployment definition in yaml and apply it to the cluster using kubectl.
Defining the Application as a Service
Next, we create a service definition of our application. This is needed to route requests to your application from other applications in your cluster.
Deploying Traefik
Traefik is an open source application that can be used to route traffic and load balance.
Setting up Ingress
Ingresses define how
Conclusion
In this tutorial, we created a cluster and deployed a very simple application to it. We also got familiar with deploying application updates to Kubernetes, scaling the application to multiple nodes, and we observed how Kubernetes reacts to failures.