In this blog we will explore how to get setup with using Couchbase with Kubernetes and CoreOS. There are various deployment strategies ranging from the bare metal physical servers to virtual machines in the cloud or by using a fully managed solution from major cloud providers. For this series, we will be installing a full bare metal Kubernetes solution by running all the components on your local machine. There are a couple of prerequisites and we will go into each a bit to understand the overall picture. The environment I am using for this blog is:
- Virtual Box 5.0.8
- Vagrant 1.7.4
- Mac OSX 10.11.1
- Kubernetes 1.0.6
First we need to setup Kubernetes and we will use Vagrant and CoreOS. Vagrant allows you to create consistent development environments quickly across various members of your team. You may read more on the benefits of using Vagrant. Go to the downloads page and select the package of your choice. At the time of writing, we are targeting Vagrant 1.7.4 for MAC OSX against Virtual Box 5.0.8
Open the vagrant .dmg package and follow through on the installation instructions. Next we will initiate Vagrant.
Download Kubernetes
From within your terminal application, create a new folder and navigate to that folder. For the example, I created a folder named 'couchbase-kubernetes' and that is where we will spend the majority of our time. 'kubectl' is the main command CLI tool that we will use for interacting with the Kubernetes API.
1 2 |
$mkdir couchbase-kubernetes |
1 2 |
$cd couchbase-kubernetes/ |
From within the 'couchbase-kubernetes' folder, we will download the binaries. First install the package manager, Homebrew, if you have not already and execute a 'wget' on:
1 2 |
$ARCH=darwin; wget https://storage.googleapis.com/kubernetes-release/release/v1.0.6/bin/$ARCH/amd64/kubectl |
You will see something similar as the below where the 'kubectl' is then saved. I choose the 'darwin' environment as I am on MacOSX and you can also choose 'linux' depending on your workstation operating system.
Check to see if the binary is an executable by executing:
1 2 |
$file kubectl |
You should see that the 'kubectl' file exists and that it is an executable x86_64 like below.
Let us move 'kubectl' into our PATH by executing:
1 2 |
$chmod +x kubectl |
1 2 |
$mv kubectl /usr/local/bin/kubectl |
Run Kubernetes on top of CoreOS
Now we are ready to setup the virtual machines that will be running Kubernetes on CoreOS. First we will clone the repository that contains a Vagrantfile. The 'Vagrantfile' will have the configurations of the Kubernetes virtual machines. Execute the command:
1 2 |
$git clone https://github.com/coreos/coreos-kubernetes.git |
You should now have the 'coreos-kubernetes' repo after seeing something similar below
Start Kubernetes
Now we are ready to start our machine. To do that let us first navigate to the 'single-node' folder where we will initiate Vagrant
1 2 |
$cd coreos-kubernetes/single-node/ |
From within the 'single-node' folder we will now execute the commands below to have a fully running virtual machine in VirtualBox.
1 2 |
$vagrant init hashicorp/precise64 |
Targeting the 64-bit version, below is what will see during the process of setting up the Ubuntu 12.04 LTS 64-bit box.
Next up let us run the virtual machine in VirtualBox by executing:
1 2 |
$vagrant up |
Configuring kubectl
From within the 'single-node' directory, we will next configure the local Kubernetes client with the commands below.
1 2 |
$kubectl config set-cluster vagrant --server=https://172.17.4.99:443 --certificate-authority=${PWD}/ssl/ca.pem |
1 2 |
$kubectl config set-credentials vagrant-admin --certificate-authority=${PWD}/ssl/ca.pem --client-key=${PWD}/ssl/admin-key.pem --client-certificate=${PWD}/ssl/admin.pem |
1 2 |
$kubectl config set-context vagrant --cluster=vagrant --user=vagrant-admin |
1 2 |
$kubectl config use-context vagrant |
Now that everything is ready, you can see your cluster's status and its configuration information by executing:
1 2 |
$kubectl get nodes |
Congrats! Now you have a Kubernetes cluster running and set up. This is the first step before running Couchbase on it. Next we will explore how to run Couchbase in the Kubernetes cluster.
Setting Up Couchbase
From within the 'single-node' directory, we will start bringing in the Couchbase pieces. From there we can then configure Couchbase to specific service logics. We begin by cloning the Couchbase-Kubernetes repo:
1 2 |
$git clone https://github.com/couchbase/kubernetes.git couchbase-kubernetes |
1 2 |
$cd couchbase-kubernetes |
In our next blog on Couchbase and Kubernetes, we will go through in concept and in configuring and running the Service and Replication Controllers for Couchbase!