How to install Kubernetes using Let’s Kube script

Containerum
Containerum
Published in
4 min readJul 5, 2018

by Dmitry Timofeiev

Let’s Kube is a set of Ansible playbooks that bootstrap a Kubernetes cluster in a matter of minutes. Let’s Kube installs docker, etcd store, the core Kubernetes components (kubelet, kubectl, kubeadm, etcd), and calico — a network plug-in for network security.

In this guide we will install Ansible and then proceed to bootstrapping K8s with Let’s Kube.

Prerequisites

To run Let’s Kube you need to have 3 virtual machines with CentOS 7 and a machine with Git installed.

Install Ansible

If your machine runs on CentOS, then install Ansible from epel-release repo:

yum install epel-release

and then run:

yum install ansible

You can also build your own rpm package from source code:

$ git clone git://github.com/ansible/ansible.git — recursive
$ cd ./ansible
$ make rpm
$ sudo rpm -Uvh ./rpm-build/ansible-*.noarch.rpm

To install Ansible on Ubuntu run:

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible

If you use Debian, first add the repo to edit /etc/apt/sources.list:

deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main

Then run:

$ sudo apt-key adv — keyserver keyserver.ubuntu.com — recv-keys 93C4A3FD7BB9C367
$ sudo apt-get update
$ sudo apt-get install ansible

To install Ansible on other OS, refer to the official docs.

Let’s Kube

Preparation

First, clone the project repo from GitHub:

git clone https://github.com/containerum/letskube.git

Cd to the letskube directory and edit the inventory file:

[all]
m1 ansible_user=centos ansible_host=172.16.0.1 ansible_port=22 ip_internal=10.0.0.1
s1 ansible_user=centos ansible_host=172.16.0.2 ansible_port=22 ip_internal=10.0.0.2
[masters]
m1
[slaves]
s1
[kubectl]
m1

In [all] set the hostname and credentials for accessing the remote machine:

ansible_user — user for authorization with ansible.
ansible_host — external IP address of the remote machine.
ansible_port — SSH port to establish connection.
ip_internal — internal IP address of the remote machine, if provided. Otherwise, leave it out.

As Ansible works with SSH, it is required to exchange ssh-keys between the nodes, disable password authorization, and enable authorization by key. It is also necessary to enable root access without password.

Launch the playbook

Launch Let’s Kube with:

anisble-playbook bootstrap.yaml -i inventory -v

The -i flag refers to the inventory file that stores the data for connection. The
-v flag enables logging.

The cluster will now setup automatically.

Smoke test the cluster

Go to the m1 node and print nodes:

kubectl get nodes
NAME STATUS ROLES AGE VERSION
m1 Ready master 10m v1.9.7
s1 Ready <none> 10m v1.9.7

Print the pods and make sure that all K8s system pods are running:

kubectl get pods — all-namespaces

What you should see:

NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-kube-controllers-846c7bf5ff-jb2r8 1/1 Running 0 10m
kube-system calico-node-qjvwm 2/2 Running 0 10m
kube-system calico-node-sgc9j 2/2 Running 0 10m
kube-system calico-node-zjf5f 2/2 Running 0 10m
kube-system kube-apiserver-k1 1/1 Running 0 10m
kube-system kube-controller-manager-k1 1/1 Running 0 10m
kube-system kube-dns-6f4fd4bdf-sj79m 3/3 Running 0 10m
kube-system kube-proxy-4nldc 1/1 Running 0 10m
kube-system kube-proxy-8qw66 1/1 Running 0 10m
kube-system kube-proxy-cllk2 1/1 Running 0 10m
kube-system kube-scheduler-k1 1/1 Running 0 10m

Now deploy an application and expose its port to make sure it’s accessible from the outside. Let’s launch nginx:

kubectl run nginx — image nginx

What you should see:

deployment “nginx” created

Check if the pod is launched:

kubectl get pods — all-namespaces

In case it’s launched, you will see:

NAMESPACE NAME READY STATUS RESTARTS AGE
default nginx-8586cf59-zjlrp 1/1 Running 0 12s

If you launch pods without specifying the namespace, they are launched in the default namespace by default.

Now expose the port:

kubectl expose deploy nginx — port 8080 — target-port 80

Get the IP address of the deployment:

kubectl get pods -o wide -n default

You should get the IP address:

NAME READY STATUS RESTARTS AGE IP NODE
nginx-8586cf59-zjlrp 1/1 Running 0 19m 10.244.99.38 s1

Check availability by curling the printed address:

curl 10.244.99.38:80

In case the test is succesful, nginx should return:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href=”http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href=”http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Congratulations! You’ve just bootstrapped a Kubernetes cluster with Let’s Kube. If you like the script, you can support the project by giving it a ⭐ on the official repository. Also follow us on Twitter and join our Telegram chat to stay tuned!

Please, feel free to leave feedback and ask questions.

Containerum is your source of knowledge on Kubernetes.

--

--

Containerum
Containerum

Containerum Platform for managing applications in Kubernetes.