When it comes to Docker containers and orchestration there are a lot of available options. Almost every few months some new Docker orchestration tool is available. At least that was the case at the beginning. Most of those tools are opensource projects, but of course, there are some enterprise orchestration tools. However, Google’s Kubernetes is most used and really popular tool. Like with all Google products it is also complicated to install and manage. They recently released kubeadm Kubernetes deployment tool, but this is still in Alpha and not ready for production environments. In this post, I will show you how to deploy Kubernetes on top of Rancher which is my favorite. With Rancher, you could decide which Docker orchestration tool to use, like Cattle (Rancher), Kubernetes, Mesos or Docker Swarm.

First, I created vagrant provisioning and then added a support for AWS. For AWS I decided to make a Docker container which will work on any OS (Mac, Windows or Linux) and the only dependency you will need for this is Docker engine installed and running. komljen/salt-cloud image has all dependencies already installed, like salt-cloud, awscli and custom scripts to prepare configuration files.

All you need to do now is to run Docker container using your AWS access and secret keys:

1

2

3

4

5

6

7

docker run-d-eAWS_ACCESS_KEY_ID=KEY\

-eAWS_SECRET_ACCESS_KEY=SECRET\

-eAWS_DEFAULT_REGION=us-west-2\

-eAWS_DEFAULT_AZ=us-west-2a\

-eAWS_AMI_ID=ami-d732f0b7\

--name salt-cloud\

komljen/salt-cloud

After a few seconds you can check logs for this container and if last message is ‘Keep this container running…’ you can connect to it:

1

2

docker logs-fsalt-cloud

docker exec-i-tsalt-cloud bash

Kubernetes provisioning on Rancher

Now you can start VM provisioning on AWS. Salt master will start first and then all minion nodes will start in parallel. They will be connected to master automatically. To select which node will also be a Kubernetes node edit this file /etc/salt/cloud.maps.d/rancher.conf and update agentEnvironment value to Kubernetes. Default means Rancher Cattle environment. Each Rancher agent node can be used by only one environment at the same time. Run below command to start a VM provisioning:

1

salt-cloud-m/etc/salt/cloud.maps.d/rancher.conf-P-y

When all nodes are ready we can connect to master node and finally start Rancher provisioning. You can connect to master node using newly created pem key /etc/salt/salt_cloud_key.pem directly from a Docker container. Check your master public IP address with:

1

2

salt-cloud-Q

ssh-i/etc/salt/salt_cloud_key.pem ubuntu@<master_public_ip>

Check the environment and if all minions are connected, start Rancher deployment:

1

2

sudo salt'*'test.ping

sudo salt-run state.orchestrate deploy.rancher

To access Rancher web UI at http://AWS_MASTER_PUBLIC_DNS:8080 you need to open 8080 port on master node. Also, as Rancher agents are added to Kubernetes environment, Kubernetes deployment will start automatically.

Managing Kubernetes resources

When Kubernetes is deployed with Rancher you have multiple options to manage it. Rancher also deploys Kubernetes dashboard and kubectl is available from the web. If you prefer to use kubectl on your workstation it is possible to generate ~/.kube/config file. On top of that Rancher monitors all Kubernetes services and it’s versions: