Reader small image

You're reading from  Kubernetes - A Complete DevOps Cookbook

Product typeBook
Published inMar 2020
PublisherPackt
ISBN-139781838828042
Edition1st Edition
Concepts
Right arrow
Author (1)
Murat Karslioglu
Murat Karslioglu
author image
Murat Karslioglu

Murat Karslioglu is a distinguished technologist with years of experience using infrastructure tools and technologies. Murat is currently the VP of products at MayaData, a start-up that builds data agility platform for stateful applications, and a maintainer of open source projects, namely OpenEBS and Litmus. In his free time, Murat is busy writing practical articles about DevOps best practices, CI/CD, Kubernetes, and running stateful applications on popular Kubernetes platforms on his blog, Containerized Me. Murat also runs a cloud-native news curator site, The Containerized Today, where he regularly publishes updates on the Kubernetes ecosystem.
Read more about Murat Karslioglu

Right arrow

Configuring a Kubernetes cluster on Microsoft Azure

In this section, we will cover a recipe using Microsoft Azure Kubernetes Service (AKS) in order to create a Kubernetes cluster on the Microsoft Azure Cloud.

Getting ready

All the operations mentioned here require a Microsoft Azure subscription. If you don't have one already, go to https://portal.azure.com and create a free account.

How to do it…

This section will take you through how to configure a Kubernetes cluster on Microsoft Azure. This section is further divided into the following subsections to make this process easier:

  • Installing the command-line tools to configure Azure services
  • Provisioning a managed Kubernetes cluster on AKS
  • Connecting to AKS clusters

Installing the command-line tools to configure Azure services

In this recipe, we will get the Azure CLI tool called az and kubectl installed.

Let's perform the following steps:

  1. Install the necessary dependencies:
$ sudo apt-get update && sudo apt-get install -y libssl-dev \
libffi-dev python-dev build-essential
  1. Download and install the az CLI tool:
$ curl -L https://aka.ms/InstallAzureCli | bash
  1. Verify the az version you're using:
$ az --version
  1. Install kubectl, if you haven't installed it already:
$ az aks install-cli

If all commands were successful, you can start provisioning your AKS cluster.

Provisioning a managed Kubernetes cluster on AKS

Let's perform the following steps:

  1. Log in to your account:
$ az login
  1. Create a resource group named k8sdevopscookbook in your preferred region:
$ az group create --name k8sdevopscookbook --location eastus
  1. Create a service principal and take note of your appId and password for the next steps:
$ az ad sp create-for-rbac --skip-assignment
{
"appId": "12345678-1234-1234-1234-123456789012",
"displayName": "azure-cli-2019-05-11-20-43-47",
"name": "http://azure-cli-2019-05-11-20-43-47",
"password": "12345678-1234-1234-1234-123456789012",
"tenant": "12345678-1234-1234-1234-123456789012"
  1. Create a cluster. Replace appId and password with the output from the preceding command:
$ az aks create --resource-group k8sdevopscookbook \
--name AKSCluster \
--kubernetes-version 1.15.4 \
--node-vm-size Standard_DS2_v2 \
--node-count 3 \
--service-principal <appId> \
--client-secret <password> \
--generate-ssh-keys

Cluster creation will take around 5 minutes. You will see "provisioningState": Succeeded" when it has successfully completed.

Connecting to AKS clusters

Let's perform the following steps:

  1. Gather some credentials and configure kubectl so that you can use them:
$ az aks get-credentials --resource-group k8sdevopscookbook \
--name AKSCluster
  1. Verify your Kubernetes cluster:
$ kubectl get nodes

Now, you have a three-node GKE cluster up and running.

How it works…

This recipe showed you how to quickly provision an AKS cluster using some common options.

In step 3, the command starts with az aks create, followed by -g or --resource-group, so that you can select the name of your resource group. You can configure the default group using az configure --defaults group=k8sdevopscookbook and skip this parameter next time.

We used the --name AKSCluster parameter to set the name of the managed cluster to AKSCluster. The rest of the parameters are optional; --kubernetes-version or -k sets the version of Kubernetes to use for the cluster. You can use the az aks get-versions --location eastus --output table command to get the list of available options.

We used --node-vm-size to set the instance type for the Kubernetes worker nodes. If this isn't set, the default is Standard_DS2_v2.

Next, we used --node-count to set the number of Kubernetes worker nodes. If this isn't set, the default is 3. This can be changed using the az aks scale command.

Finally, the --generate-ssh-keys parameter is used to autogenerate the SSH public and private key files, which are stored in the ~/.ssh directory.

There's more…

Although Windows-based containers are now supported by Kubernetes, to be able to run Windows Server containers, you need to run Windows Server-based nodes. AKS nodes currently run on Linux OS and Windows Server-based nodes are not available in AKS. However, you can use Virtual Kubelet to schedule Windows containers on container instances and manage them as part of your cluster. In this section, we will take a look at the following:

  • Deleting your cluster
  • Viewing Kubernetes Dashboard

Deleting your cluster

To delete your cluster, use the following command:

$ az aks delete --resource-group k8sdevopscookbook --name AKSCluster

This process will take a few minutes and, when finished, you will receive confirmation of this.

Viewing Kubernetes Dashboard

To view Kubernetes Dashboard, you need to follow these steps:

  1. To start Kubernetes Dashboard, use the following command:
$ az aks browse --resource-group k8sdevopscookbook --name AKSCluster
  1. If your cluster is RBAC-enabled, then create Clusterrolebinding:
$ kubectl create clusterrolebinding kubernetes-dashboard \
--clusterrole=cluster-admin \
--serviceaccount=kube-system:kubernetes-dashboard
  1. Open a browser window and go to the address where the proxy is running. In our example, this is http://127.0.0.1:8001/.

See also

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Kubernetes - A Complete DevOps Cookbook
Published in: Mar 2020Publisher: PacktISBN-13: 9781838828042

Author (1)

author image
Murat Karslioglu

Murat Karslioglu is a distinguished technologist with years of experience using infrastructure tools and technologies. Murat is currently the VP of products at MayaData, a start-up that builds data agility platform for stateful applications, and a maintainer of open source projects, namely OpenEBS and Litmus. In his free time, Murat is busy writing practical articles about DevOps best practices, CI/CD, Kubernetes, and running stateful applications on popular Kubernetes platforms on his blog, Containerized Me. Murat also runs a cloud-native news curator site, The Containerized Today, where he regularly publishes updates on the Kubernetes ecosystem.
Read more about Murat Karslioglu