You can create a Kubernetes cluster either through the Azure portal website, or using the Azure command line tools.
This page describes the commands required to setup a Kubernetes cluster using the command line. If you prefer to use the Azure portal see the Azure Kubernetes Service quickstart.
Prepare your Azure shell environment. You have two options, one is to use the Azure interactive shell, the other is to install the Azure command-line tools locally. Instructions for each are below.
Using the Azure interactive shell. The Azure Portal contains an interactive shell that you can use to communicate with your Kubernetes cluster. To access this shell, go to portal.azure.com and click on the button below.
Note If you get errors like could not retrieve token from local cache, try refreshing your browser window. The first time you do this, you’ll be asked to create a storage account where your shell filesystem will live.
Note
could not retrieve token from local cache
Install command-line tools locally. You can access the Azure CLI via a package that you can install locally.
To do so, first follow the installation instructions in the Azure documentation. Then run the following command to connect your local CLI with your account:
az login
You’ll need to open a browser and follow the instructions in your terminal to log in.
Activate the correct subscription. Azure uses the concept of subscriptions to manage spending. You can get a list of subscriptions your account has access to by running:
az account list --refresh --output table
Pick the subscription you want to use for creating the cluster, and set that as your default. If you only have one subscription you can ignore this step.
az account set -s <YOUR-CHOSEN-SUBSCRIPTION-NAME>
Create a resource group. Azure uses the concept of resource groups to group related resources together. We need to create a resource group in a given data center location. We will create computational resources within this resource group.
az group create \ --name=<RESOURCE-GROUP-NAME> \ --location=centralus \ --output table
where:
--name
<RESOURCE-GROUP-NAME>
ucb_2018sp_data100_hub
--location
centralus
--output table
Consider setting a cloud budget for your Azure account in order to make sure you don’t accidentally spend more than you wish to.
Choose a cluster name.
In the following steps we’ll run commands that ask you to input a cluster name. We recommend using something descriptive and short. We’ll refer to this as <CLUSTER-NAME> for the remainder of this section.
<CLUSTER-NAME>
The next step will create a few files on your filesystem, so first create a folder in which these files will go. We recommend giving it the same name as your cluster:
mkdir <CLUSTER-NAME> cd <CLUSTER-NAME>
Create an ssh key to secure your cluster.
ssh-keygen -f ssh-key-<CLUSTER-NAME>
It will prompt you to add a password, which you can leave empty if you wish. This will create a public key named ssh-key-<CLUSTER-NAME>.pub and a private key named ssh-key-<CLUSTER-NAME>. Make sure both go into the folder we created earlier, and keep both of them safe!
ssh-key-<CLUSTER-NAME>.pub
ssh-key-<CLUSTER-NAME>
This command will also print out something to your terminal screen. You don’t need to do anything with this text.
Create an AKS cluster.
The following command will request a Kubernetes cluster within the resource group that we created earlier.
az aks create --name <CLUSTER-NAME> \ --resource-group <RESOURCE-GROUP-NAME> \ --ssh-key-value ssh-key-<CLUSTER-NAME>.pub \ --node-count 3 \ --node-vm-size Standard_D2s_v3 \ --output table
--resource-group
--ssh-key-value
--node-count
--node-vm-size
--kubernetes-version
This should take a few minutes and provide you with a working Kubernetes cluster!
If you’re using the Azure CLI locally, install kubectl, a tool for accessing the Kubernetes API from the commandline:
az aks install-cli
Note: kubectl is already installed in Azure Cloud Shell.
Get credentials from Azure for kubectl to work:
kubectl
az aks get-credentials \ --name <CLUSTER-NAME> \ --resource-group <RESOURCE-GROUP-NAME> \ --output table
This automatically updates your Kubernetes client configuration file.
Check if your cluster is fully functional
kubectl get node
The response should list three running nodes and their Kubernetes versions! Each node should have the status of Ready, note that this may take a few moments.
Ready
If you create the cluster using the Azure Portal you must enable RBAC. RBAC is enabled by default when using the command line tools.
Congrats. Now that you have your Kubernetes cluster running, it’s time to begin Setup JupyterHub.