Building a Kubernetes cluster from scratch with VirtualBox and CentOS 7

Drew Sears edited this page Mar 4, 2017 · 5 revisions



The goal of this process is to build a Kubernetes cluster in a local dev environment with minimal amount of automation/magic, to understand the components involved. This is definitely not a good way to deploy a production cluster. However, it provides a starting point and a base of comparison for more automated and more platform-specific cluster deployment solutions.

Starting point

Our physical host machine is running VirtualBox and has a copy of the c7base.home template.

We have four linked clones that have been given DNS entries and static IPs on the LAN:

  • kubemaster01
  • kubenode01
  • kubenode02
  • kubectl01

Besides a master and two nodes, we're also building a dedicated control VM, to allow our physical host to play the role of hypervisor only. We will SSH to kubectl01 and use it to build and configure the other nodes, possibly run Ansible playbooks, build and push Docker images, and run kubectl.

Install kubectl

SSH to user@kubectl01

curl -LO$(curl -s
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

Install docker:

curl -fsSL | sh
sudo systemctl enable docker.service
sudo systemctl start docker.service
sudo usermod -aG docker user

Reconnect to SSH to get updated groups.

Make a docker image. Enter "hello-flask" directory and add:

import os
import datetime
from flask import Flask
app = Flask(__name__)

def hello():
  html = ['<h1>Hello Flask, Docker and Kubernetes!</h1>']
  html.append('<p>The time is: %s</p>' %
  html.append('<p>I am running on: %s</p>' % os.environ['HOSTNAME'])
  return "\n".join(html)

flask run --host=


FROM python:2.7
RUN apt-get -y update && apt-get -y upgrade
RUN pip install --upgrade pip && pip install flask
COPY . /app
CMD ["bash", ""]

Build and run it:

docker build -t hello-flask:latest .
docker run -d -p 5000:5000 hello-flask

Check success:

user@kubectl01 hello-flask]$ curl http://localhost:5000
<h1>Hello Flask, Docker and Kubernetes!</h1>
<p>The time is: 2017-03-04 17:27:15.630636</p>
<p>I am running on: f0b6d4ddfc7e</p>[user@kubectl01 hello-flask]$ 
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.