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.
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.
Once you have a command prompt, you can start typing in commands directly to your browser!
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:
az account list
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:
az account set --subscription "Visual Studio Ultimate with MSDN"
You can use the subscription name (as I did) or the ID.
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:
az group list
You can create a new resource group in a number of ways, but here’s how you can do it from the command line:
az group create --name cb_aks_spike --location eastus
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:
- Check to see if you have the ContainerService registered. You can find out by running
az provider list | ConvertFrom-Json | Format-Wideand seeing if it’s listed there.
- If it’s not listed, start ContainerService registration:
az provider register -n Microsoft.ContainerService
- 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:
az aks create --resource-group cb_aks_spike --name cbAKScluster --generate-ssh-keys
(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.
az aks get-credentials --resource-group=cb_aks_spike --name=cbAKScluster
Once that succeeds, you can use kubectl to get a list of the 3 nodes created earlier.
kubectl get nodes
The output of that command should look like:
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 -f https://s3.amazonaws.com/packages.couchbase.com/kubernetes/beta/operator.yaml
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:
kubectl create -f https://s3.amazonaws.com/packages.couchbase.com/kubernetes/beta/secret.yaml
kubectl create -f https://s3.amazonaws.com/packages.couchbase.com/kubernetes/beta/couchbase-cluster.yaml
Of course, you can create your own YAML cluster configuration.
I created my own minor variation on this sample, adjusting the memory quota, the services, and the bucket name.
- name: myBucket
- size: 3
At this point, AKS will start creating the “pods”. You can check out the status with:
kubectl get pods.
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:
kubectl port-forward cb-example-0000 8091:8091
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.
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.
Now you’ve got your feet wet with Couchbase and AKS on Azure. Here are some more resources to continue your journey:
- Couchbase Operator with AKS guide from the Couchbase Partners team.
- Getting started with Azure-cli from the Microsoft docs team.
- Couchbase Kubernetes operator documentation
- Questions? Head over the Couchbase Server forums.
Questions or comments for me? You can find me on Twitter @mgroves.