TerraKube is the simplest way to get started with Kubernetes on OpenStack.
TerraKube is a simple tool to provision a Kubernetes cluster on top of OpenStack using Hashicorp’s Terraform. If you are unfamiliar with Terraform, Terraform is a declarative tool for building, changing and versioning infrastructure. Desired state of the infrastructure is described in a configuration file and Terraform takes the plan and builds the desired state. If you are familiar with AWS CloudFormation or OpenStack Heat, here’s how it compares to OpenStack Heat: Terraform or Heat
TerraKube is a project that I started few months ago while I was evaluating Kubernetes and needed a simple, quick and repeatable way to install Kubernetes on OpenStack. Keep in mind that this is a work in progress.
For the sake of this tutorial, I will assume you already have some familiarity with OpenStack and know how to use the OpenStack command line.
So what we are going to do here is to install Terraform on a node, typically your workstation. TerraKube is just a terraform configuraion file called a plan. We will apply the plan, which in turn talks to OpenStack, launches instances and configures them with Kubernetes.
The Kubernetes cluster will consist of one Kubernetes Master and n number of Kubernetes nodes:
Kubernetes Master: CoreOS, etcd, kube-api, kube-scheduler, kube-controller-manager
Kubernetes Nodes: CoreOS, etcd, kube-kubelet, kube-proxy, flannel, docker
1. Install Terraform
Follow the instructions from here: https://www.terraform.io/intro/getting-started/install.html
2. Upload CoreOS Image to OpenStack Glance
TerraKube deploys Kubernetes on top of CoreOS instances on OpenStack. So first we need a CoreOS image to be uploaded to our OpenStack Image Service.
wget http://stable.release.core-os.net/amd64-usr/current/coreos_production_openstack_image.img.bz2 bunzip2 coreos_production_openstack_image.img.bz2 glance image-create --name CoreOs --container-format bare --disk-format qcow2 --file coreos_production_openstack_image.img --is-public True
3. Configure Terrakube
git clone https://github.com/sacharya/terrakube cd terrakube mv terraform.tfvars.example terraform.tfvars
Edit your terraform.tfvars with your configuration info. Most of the configuration should be pretty straight forward.
Please note that you have to get a new etcd_discovery_url for every new cluster. Take a look at restart.sh for example, where the etcd_discovery_url in the terraform.vars file is updated with a new value before you apply the terraform plan/
4. Using Terrakube
Show the execution plan
Execute the plan
One you apply the plan and wait for few minutes, you should get an output like:
Outputs: master_ip = 10.0.0.50 worker_ips = 10.0.0.51
The master_ip is the Kubernetes Master and worker_ips is a list of Kubernetes nodes.
Login to the master and make sure all services are up and Kubernetes is functioning properly.
ssh firstname.lastname@example.org cd /opt/kubernetes/server/bin ./kubectl get cluster-info ./kubectl get nodes
5. Running some examples
Kubernetes comes with a lot of examples that you can try out. Note that many of the examples are configured to run on top of Google Container Engine (GKE), and may not run on top of OpenStack without some tweaking. But the manifests are a pretty good starting point to learn about deploying apps on Kubernetes.
git clone https://github.com/kubernetes/kubernetes ~/kubernetes
There are plenty of example applications under examples directory. Examples/guestbook is a good start.