Knife and Skills

I love a good knife. I love chopping with my knife, and I have no idea why.

The key, I realize, is to hold the knife right. That, and a good knife.

This is my current knife – a Victorinox 8 Inch Chef’s Knife and I love it.

Kubernetes Setup Using Azure ACS Engine - Part II

Continuing on from Part I

Now that we have the acs-engine binary, we can create a template and launch the kubernetes cluster.

Before we proceed, it doesn’t hurt to pull a fresh copy of acs-engine, bootstrap and build it.

$ git clone https://github.com/Azure/acs-engine.git
$ cd acs-engine
$ sudo ./scripts/devenv.sh

Once the bootstrap is complete, build acs-engine as follows:

# make build
# # ./bin/acs-engine
ACS-Engine deploys and manages Kubernetes, Swarm Mode, and DC/OS clusters in Azure

Usage:
  acs-engine [command]

Available Commands:
  deploy        deploy an Azure Resource Manager template
  generate      Generate an Azure Resource Manager template
  help          Help about any command
  orchestrators provide info about supported orchestrators
  upgrade       upgrades an existing Kubernetes cluster
  version       Print the version of ACS-Engine

Flags:
      --debug   enable verbose debug logs
  -h, --help    help for acs-engine

Use "acs-engine [command] --help" for more information about a command.

That’s our prep done. Next, we need to create a template that will generate the deployment templates.

You can find templates that you can use in the examples folder.

Here’s my example that launches a kubernetes cluster within an existing vnet.

Once you have your template ready, you can generate the deployment templates, as follows:

$ ./bin/acs-engine generate examples/kubernetes.json
INFO[0000] Generating assets into _output/k8s...

Your deployment templates will be written to a directory with the dnsPrefix used in your template into the _output directory.

Login to Azure and create a resource group to use for your kubernetes cluster:

$ az login
$ az group create -n k8s -l westus2

Validate the generated templates:

$ cd _output/k8s
$ az group deployment validate -g k8s --template-file azuredeploy.json --parameters @./azuredeploy.parameters.json

Once the template has been validated, deploy as follows:

$ az group deployment create -g k8s --template-file azuredeploy.json --parameters @./azuredeploy.parameters.json

The deployment should take a while. My last one took around 9 minutes.

Once the deployment is complete, copy the kube config from the acs-engine folder to your .kube directory.

$ mkdir ~/.kube
$ cp _output/k8s/kubeconfig/kubeconfig.westus2.json ~/.kube/config

Once the config is in place, ensure you have the kubectl binary installed. If you don’t have it installed, you an follow the instructions here to install it.

Once it’s installed, you can get a list of the nodes:

$ kubectl get nodes
NAME                        STATUS    ROLES     AGE       VERSION
k8s-master-14054749-0       Ready     master    3d        v1.8.2
k8s-master-14054749-1       Ready     master    3d        v1.8.2
k8s-master-14054749-2       Ready     master    3d        v1.8.2
k8s-workerpool-14054749-0   Ready     agent     3d        v1.8.2
k8s-workerpool-14054749-1   Ready     agent     3d        v1.8.2
k8s-workerpool-14054749-2   Ready     agent     3d        v1.8.2
k8s-workerpool-14054749-3   Ready     agent     3d        v1.8.2

Using Azure Container Registry with Kubernetes

Instead of specifying this directly in your configuration, we’ll use the concept of k8s secrets. You decouple the k8s object from the registry configuration by just referencing the secret by it’s name. But first, let’s create a new k8s secret.

$ kubectl create secret docker-registry <SECRET_NAME> --docker-server <REGISTRY_NAME>.azurecr.io --docker-email <YOUR_MAIL> --docker-username=<SERVICE_PRINCIPAL_ID> --docker-password <YOUR_PASSWORD>

JSON Feed

Until recently, this site had an atom feed.

Not anymore.

We now have JSON feed available here, i.e. if you still use a feed reader. 😏

Kubernetes Setup Using Azure ACS Engine - Part I

These days I spend nearly all of my time on Azure. Ansible support for Azure hasn’t been great until version 2.4, so I’ve even had to build custom modules to do some stuff internally for ourselves.

Beyond that, there’s a lot of interesting and innovative stuff happening in Azure.

In this post, I want to focus on one very specific thing – setting up Kubernetes1 on Azure. Microsoft already has some great documentation on setting up Kubernetes on Azure and there’s other documentation on the Kubernetes site itself.

I’ve done some work on getting a Kubernetes cluster up in Azure using acs-engine and this post is intended to document that.

Let’s start. I am using Debian 9 as my operating system2.

  1. First things first – install the dependencies
$ sudo apt-get install apt-transport-https ca-certificates curl \
                          gnupg2 \
                          software-properties-common
  1. Add the docker repository public key, so we can…
$ curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -
  1. Add the docker repository to the sources list
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
    $(lsb_release -cs) \
    stable"
  1. Install Docker Community Edition
$ sudo apt-get update
$ sudo apt-get install docker-ce

That should be all the required software we need to start using acs-engine.

  1. Next, checkout the acs-engine repo
$ git clone https://github.com/Azure/acs-engine.git
  1. And “bootstrap” the environment, so to speak. For the next step(s), you’ll need to run as a user who can pull docker images, which could be either root or a docker user
$ cd acs-engine
$ ./scripts/devenv.sh

The last step above should take a while, as it pulls docker images and all the other dependencies required for acs-engine.

It should then drop you inside a docker container shell.

  1. Once you’re in the container shell, we bootstrap and build
# make bootstrap
# make build
  1. Once complete, there should be an acs-engine binary in the bin folder.
# ./bin/acs-engine
ACS-Engine deploys and manages Kubernetes, Swarm Mode, and DC/OS clusters in Azure

Usage:
  acs-engine [command]

Available Commands:
  deploy        deploy an Azure Resource Manager template
  generate      Generate an Azure Resource Manager template
  help          Help about any command
  orchestrators provide info about supported orchestrators
  upgrade       upgrades an existing Kubernetes cluster
  version       Print the version of ACS-Engine

Flags:
      --debug   enable verbose debug logs
  -h, --help    help for acs-engine

Use "acs-engine [command] --help" for more information about a command.

That’s what we will use to generate templates and build our clusters using azure cli tools.

In Part II, I’ll cover the following:

  • Creating a template from the examples provided in the examples folder
  • Generate deployment templates using the template we create
  • Create a resource group to use for the kubernetes cluster. Alternately, use an existing one.
  • Validate and deploy the template
  • Login and check the kubernetes cluster we just deployed

1 Take a look at DigitalOcean’s intro to kubernetes.

2 The steps for other Linux distributions and operations systems are available here. For other operating systems, after you install docker, you can continue from Step 5 above.