Deploying Kubernetes On-Premise with RKE and deploying OpenFaaS on it — Part 1

Ken Fukuyama
HackerNoon.com
7 min readDec 10, 2017

--

I’m a big fan of Rancher and am very excited in how their RKE (Rancher Kubernetes Engine) is going to evolve and ease the way I deploy Kubernetes. As I’m heavily investing my time on OpenFaaS (an open source serverless platform), I’d like to easily deploy it above the kubernetes cluster made by RKE. In this post I’d like to show:

  • How to deploy a kubernetes cluster with 2 nodes (1 master & 1 worker) using RKE
  • How to deploy OpenFaaS on the kubernetes cluster you deployed via Helm

The following diagram shows a simple relation of the components:

rke

Prerequisites

  • 2 hosts that can run docker (ver. 1.12 to 17.03)
    (I’ll be using 2 Ubuntu 16.04 hosts with docker 17.03-ce)
  • Each of my hosts have 1 CPU core and 1GB RAM

Deploy a Kubernetes Cluster with RKE

If you haven’t read “Announcing RKE, a Lightweight Kubernetes Installer” already, take a look and try it out. In addition, if you have time you should watch “Managing Kubernetes Clusters with Rancher 2.0 — November 2017 Online Meetup” as it explains the newest features of Rancher 2.0 and about RKE as well.

Download RKE

You can download RKE from here. It’s a simple CLI tool to deploy Kubernetes. If you’re using OSX you’ll be downloading rke_darwin-amd64. Rename it to rke and don’t forget to give it execution permissions via chmod +x rke. From here I’m assuming that you added rke to the PATH. Confirm that you can execute rke. You should see something similar to this:

Create RKE Config

Now that we can use rke , let’s create a config in order to deploy Kubernetes to our hosts. Execute rke config and you should be prompted to answer some questions. The following diagram describes my hosts and their roles in Kubernetes. Basically Host1 will be a master node and Host2 will be a worker node.

Host Description

With this in mind, my rke config answers look like this:

Quick Note: My hosts only had root users so I’m using root but any user who can use docker could be set. Additionally, I’m using calico for networking but flannel and canal are supported as well ( weave is probably coming in the next release based on this PR from my co-worker).

This generates a cluster.yml file and the contents should look like this:

Install Docker to the Hosts

I’ll use Docker 17.03-ce for this post. Any version Kubernetes supports should work (atm this post will deploy Kubernetes 1.8.3). One of the easy ways to install Docker is from the shell provided by Rancher Labs on the following link:

The following command should work for Docker 17.03-ce:

Confirm your docker version is correct:

Register authorized_keys

Be sure you can access your hosts via an ssh key. Suppose you’re going to access the host with the private key ~/.ssh/id_rsa. You will likely have your public key at ~/.ssh/id_rsa.pub so cat and copy the content. In each of your hosts, paste the content inside ~/.ssh/authorized_keys . Confirm that you can access your hosts via ssh .

Turn Swap Off in your Hosts

If you’re using your own on-premise machine, it’s likely that your swap is on. Kubelet will fail to activate saying something like:

Either disable swap with:

or set your cluster.yml with fail-swap-on: false like this:

Deploy Kubernetes!

You’re all set now! Confirm that you’re in the directory with cluster.yml and execute rke up . Yes, that’s it! You should see rke deploying the components for Kubernetes to work the the specified hosts.

How long it takes for initial deploy will depend on your network connection because rke needs to pull the docker images, but without that it will end in a couple of minutes. After you see Finished building Kubernetes cluster successfully, you should see a file called .kube_config_cluster.yml. You can use kubectl with this config. Confirm that your nodes are working with the following command:

You should get all information about your kubernetes cluster.

Wrap Up

Pretty simple wasn’t it? You can easily create a kubernetes cluster even with an environment at your house (which I did). Part 1 focused on creating a kubernetes cluster. In Part 2 I’d like to deploy OpenFaaS on top of it.

--

--

Ken Fukuyama
HackerNoon.com

Front-end Engineer@CYDAS, Inc. OpenFaaS Contributor. Loves Technologies. IaC, DevOps, Containers, Frontend, Backend, BigData.