This blog is possible because of this tweet!

kubernetes-logo

Kubernetes is an open source orchestration system by Google for Docker containers.  It manages containerized applications across multiple hosts and provides basic mechanisms for deployment, maintenance, and scaling of applications. It allows the user to provide declarative primitives for the desired state, for example “need 5 Couchbase servers”. Kubernetes self-healing mechanisms, such as auto-restarting, re-scheduling, and replicating containers then ensure that this state is met. The user just define the state and Kubernetes ensures that the state is met at all times on the cluster. Key Concepts of Kubernetes explains the key concepts of Kubernetes. This multi-part blog series will show how to run Couchbase on Kubernetes in multiple ways. The first part starts with a simple setup using Vagrant.

Getting Started with Kubernetes

There are multiple ways to run Kubernetes but I found the simples (not necessarily predictable ;) way is to run using Vagrant.

  • Download the latest Kubernetes release, 1.1.8 as of this writing, and expand the archive.
  • Start the Kubernetes cluster as:

    This shows the output as:

Run Couchbase on Kubernetes Cluster

The easiest way to start running a Docker container in Kubernetes is using the kubectl run command. The command usage is:

The command runs a particular image, possibly replicated. The image replication is handled by creating a Replication Controller to manage the created container(s). Complete list of options to run this command can be seen using:

Couchbase Docker Container explains the different Docker container for Couchbase. For this blog, we’ll use arungupta/couchbase image as that is pre-configured.

This shows the output:

The output confirms that a Replication Controller is created. Lets verify it:

Now, check the pods:

Lets check the status of the pod:

Fifth line of the output says the node’s IP is 10.245.1.4. This would be used to access the Web Console later. The last line in this output shows that the pod is now ready. Checking the status of the pod again shows:

Couchbase Web Console on Kubernetes Cluster

Now that your Couchbase container is running in Kubernetes cluster, you may like to view the Web Console. Each pod is assigned a unique IP address, but this address is only accessible within the cluster. It can exposed using the kubectl expose command. This command takes a Replication Controller, Service or Pod and expose it as new Kubernetes Service. This can be done by giving the command:

In this command:

  • --target-port is the name or number for the port on the container that the service should direct traffic to
  • --port is the port that the service should serve on
  • --external-ip is the external IP address to set for the service. Note, this IP address was obtained with kubectl describe pod command earlier.

Now, you can access the Couchbase Web Console at http://10.245.1.4:8091 and looks like:
Couchbase Web Console on Kubernetes
Enter the password credentials as Administrator/password.

Couchbase Web Console in Kubernetes
Voila!
Discuss with us at StackOverflow or Couchbase Forums. You can also follow us at @couchbasedev and @couchbase.

Author

Posted by Arun Gupta, VP, Developer Advocacy, Couchbase

Arun Gupta is the vice president of developer advocacy at Couchbase. He has built and led developer communities for 10+ years at Sun, Oracle, and Red Hat. He has deep expertise in leading cross-functional teams to develop and execute strategy, planning and execution of content, marketing campaigns, and programs. Prior to that he led engineering teams at Sun and is a founding member of the Java EE team. Gupta has authored more than 2,000 blog posts on technology. He has extensive speaking experience in more than 40 countries on myriad topics and is a JavaOne Rock Star for three years in a row. Gupta also founded the Devoxx4Kids chapter in the US and continues to promote technology education among children. An author of several books on technology, an avid runner, a globe trotter, a Java Champion, a JUG leader, NetBeans Dream Team member, and a Docker Captain, he is easily accessible at @arungupta.

Leave a reply