AKS (Azure Container Service) is the managed Kubernetes service on Microsoft Azure. It is currently in preview, so there are some things that may change down the road.

In this post, I’m going to create an AKS cluster and install a Couchbase cluster on it, using the Couchbase Kubernetes operator (which is also in pre-release).

This post assumes you’ve already created an Azure account. If you haven’t, check out Azure: Getting Started is Easy and Free.

Azure Cloud Shell

First, login to the Azure portal. I’m going to use a relatively new and very cool feature of Azure called the Cloud Shell. Click on the “command prompt” icon at the top right of the Azure portal screen.

Azure Cloud Shell icon

Clicking this will open up a shell command prompt window right in your browser. The first time you do this, Azure will be prompt you to decide between Bash and PowerShell. I decided to use PowerShell. (If you are more comfortable with Bash, then you should still be able to follow along). You will need to setup a storage account the first time (and only the first time) you use the Cloud Shell. This will take several minutes.

Bash or PowerShell

Once you have a command prompt, you can start typing in commands directly to your browser!

Azure Cloud Shell prompt

If you’re like me and have multiple account subscriptions within Azure (for instance, I have an MSDN subscription and a Pay-as-you-go subscription), you should check to see which is the “default” by entering this command:

This command will print out a list of your accounts in JSON format. Check out the isDefault field in the JSON. For instance, mine had “Pay as you go” as the default (which I don’t want, because I have plenty of credit on my MSDN account).

If you want to change the default, enter a command like this:

You can use the subscription name (as I did) or the ID.

Azure-cli

The above two commands that used “az” are using the “Azure CLI”. You can install this on your local machine, and it comes out-of-the-box when using the Cloud Shell.

Before we can create a Kubernetes cluster with a Couchbase cluster, let’s use azure-cli to lay the groundwork.

First, create a resource group. A resource group is a logical grouping that you can use to organize the various services and instances in Azure. You can get a list of all your current resource groups with this command:

You can create a new resource group in a number of ways, but here’s how you can do it from the command line:

At this point, the resource group should appear when you run az group list, or when you view your resource groups in the normal Azure Portal UI.

If you’re trying to use your local Windows PowerShell, you might also need to take the following steps:

  1. Check to see if you have the ContainerService registered. You can find out by running az provider list | ConvertFrom-Json | Format-Wide and seeing if it’s listed there.
  2. If it’s not listed, start ContainerService registration: az provider register -n Microsoft.ContainerService
  3. Then, monitor the progress of ContainerService registration: az provider show -n Microsoft.ContainerService (wait until “registrationState” is not “Registering” and becomes “Registered”)

These steps might not be necessary when AKS goes out of preview into a general release.

Create AKS cluster

Next, create an AKS cluster inside of the resource group you created in the previous section:

(AKS cluster name can only contain letter, numbers, and dashes).

This will take some time to complete. When it’s done, you’ll have a managed container service with:

  • A node pool of size 3 (the default, you can specify with –node-count)
  • Each node is a DS1_v2 Azure instance (Single CPU, 3.5gb RAM machines, which are inexpensive and fine for this demo, but you will probably want to use a more powerful machine for Couchbase in production)

Note that you’ve created a Kubernetes cluster. Next, we’ll install a Couchbase cluster within the Kubernetes cluster. It’s important to keep track of and communicate the specific cluster whenever you refer to one.

Use kubectl to put Couchbase on AKS

This next part will run locally on PowerShell, and not in the Azure Cloud Shell. You will need to be logged in and have Azure-cli already installed along with Kubectl (which you probably have already).

Then, install the AKS cli locally with this command: az aks install-cli.

After that, you’ll need to connect to the AKS cluster created earlier.

Once that succeeds, you can use kubectl to get a list of the 3 nodes created earlier.

The output of that command should look like:

Kubectl get nodes

Couchbase has introduced a Kubernetes operator, which is currently in beta. You don’t have to use this operator, but it’s going to make using Couchbase on Kubernetes a much better experience.

Start by deploying the operator with kubectl:

Create operator

When that’s finished, you can view all deployments with kubectl get deployments.

Now it’s time to deploy Couchbase. You’ll need to create a secret and a cluster, both with YAML files. You can use a couple of sample YAML files available at these URLs:

I created my own minor variation on this sample, adjusting the memory quota, the services, and the bucket name.

At this point, AKS will start creating the “pods”. You can check out the status with: kubectl get pods.

get pods
kubectl get pods running on AKS

This will take a few minutes to complete.

Access the AKS cluster

The Couchbase cluster is now running in the Kubernetes cluster. One other way you can access Couchbase, just to verify it’s working, is with port forwarding. Run this command locally:

When you do this, you’re forwarding localhost on port 8091 to the cb-example-0000 pod on port 8091. Which means that if you open http://localhost:8091 in your local browser, you’ll be directed to the Couchbase cluster running in AKS on Azure.

Couchbase cluster

An easy way to see AKS and the Kubernetes operator in action is to remove the bucket. The Couchbase operator will notice this, and recreate the bucket automatically.

Summary

Now you’ve got your feet wet with Couchbase and AKS on Azure. Here are some more resources to continue your journey:

Questions or comments for me? You can find me on Twitter @mgroves.

Author

Posted by Matthew Groves

Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.

Leave a reply