How to get Kubernetes and Deis onto Azure

With Kubernetes Anywhere, setting up a Kubernetes cluster on Microsoft’s Azure isn’t as painful as it used to be.

Prerequisite

  • Docker is setup
  • gcc is setup
  • kubectl is setup
  • Azure Subscription ID is prepared

Kubernetes

Prepare your environment

Deploy

$ git clone https://github.com/kubernetes/kubernetes-anywhere
$ cd kubernetes-anywhere

Starting the development process

$ make docker-dev
$ make deploy

You’ll be prompted to fill up the required fields. Please skip the following fields by leaving them blank. This is to let the script handle the registration of the required fields.

  • Tenant ID
  • Client ID
  • Client Secret

You can identify optional fields by a blank [] in the fields prompt.

There’s quite a number of fields here so please bear with the wizard.

Once the whole process is done and if you don’t see any errors, your Kubernetes cluster should be set up!

Initiate Kubernetes Cluster

Now that you have your Kubernetes cluster setup, how do we obtain access to it?

First, make sure you exit the environment

[container]:/opt/kubernetes-anywhere> exit

Next, lets copy the kubeconfig.json file into a directory of your choosing. I would recommend putting it into your ~/.kube/ directory so that it is easier to keep track of it. If you don’t have the ~/.kube/ directory, you can create it with mkdir ~/.kube

# in your kubernetes-anywhere directory
$ cp phase1/azure/.tmp/kubeconfig.json ~/.kube/

Now, lets make sure that kubectl is using your newly created kubeconfig.json configuration.

$ export KUBECONFIG=$HOME/.kube/kubeconfig.json

Now when you run kubectl cluster-info you should see information about your newly created Azure Kubernetes Cluster.

Deis Workflow

Setup CLI

Install Deis CLI

$ curl -sSL http://deis.io/deis-cli/install-v2.sh | bash
$ sudo cp deis /usr/local/bin/
$ deis version
<version tag>

Install Helm CLI

$ curl -sSL https://get.helm.sh | bash
$ sudo cp helmc /usr/local/bin
$ helmc --version
<version tag>

Deis Setup

Test helmc is able to access your Kubernetes cluster

$ helmc target

If you see an output with paths to various Kubernetes services, your helmc and Kubernetes is correctly setup.

Install Deis Workflow

$ helmc repo add deis https://github.com/deis/charts
$ helmc fetch deis/workflow-v2.7.0
$ helmc generate -x manifests workflow-v2.7.0
$ helmc install workflow-v2.7.0

Now when you do a kubectl --namespace=deis get pods, you should see a list of containers being created.

Deis Configuration

Once you see that all pods are in the Ready state, your Deis cluster is up and running. Now lets quickly interact with it.

To start, we will need to get the loadbalancer IP address. This is a loadbalancer that is created automatically by Deis. Because Deis detects that your cluster is hosted on Azure, it creates Azure’s LoadBalancer for the purpose of routing.

$ kubectl --namespace=deis describe svc deis-router | egrep "LoadBalancer Ingress"
LoadBalancer Ingress: <ip>

With the LoadBalancer ip, your controller url will look something like http://deis.<ip>.nip.io

So lets register our admin account

$ deis register http://deis.<ip>.nip.io
username: admin
password:
password (confirm):
email: [email protected]
Registered admin
Logged in as admin
$ deis whoami
You are admin at http://deis.<ip>.nip.io

Congrats! You’re done!

Deploy a test app.

$ deis create --no-remote
Creating Application... done, created dreamy-wayfarer
If you want to add a git remote for this app later, use `deis git:remote -a dreamy-wayfarer`

Remotely deploy an example docker app.

$ deis pull deis/example-go -a dreamy-wayfarer
$ curl http://dreamy-wayfarer.<ip>.nip.io
Powered by Deis

Alternatively, if you have an existing repository

# in your git repo
$ deis create
Creating Application... done, created benign-quilting
Git remote deis successfully created for app benign-quilting.
$ deis keys:add # remember to add your keys here!
$ git push deis master
...
...
Build complete.
Launching App...
Done, benign-quilting:v2 deployed to Workflow

$ curl http://benign-quilting.<ip>.nip.io

And you have an existing Application Running! All the benefits of a easily deployable PaaS on the powerful Kubernetes engine.


Note: Right now, Deis doesn’t have the concept of Service Brokers, a concept borrowed from Cloudfoundry to help spin up backing services like databases etc which your app can use. In order to get your app running with a database, you’ll have to manually spin up a database instance and config your application to use environment variables to use it. This can be done with deis config:set. More information here


References