Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Building a Kubernetes cluster from scratch with VirtualBox and CentOS 7
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.
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:
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.
SSH to user@kubectl01
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl
curl -fsSL https://get.docker.com/ | 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__) @app.route('/') def hello(): html = ['<h1>Hello Flask, Docker and Kubernetes!</h1>'] html.append('<p>The time is: %s</p>' % datetime.datetime.now()) html.append('<p>I am running on: %s</p>' % os.environ['HOSTNAME']) return "\n".join(html)
export FLASK_APP=hello.py flask run --host=0.0.0.0
FROM python:2.7 RUN apt-get -y update && apt-get -y upgrade RUN pip install --upgrade pip && pip install flask COPY . /app WORKDIR /app CMD ["bash", "run.sh"]
Build and run it:
docker build -t hello-flask:latest . docker run -d -p 5000:5000 hello-flask
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]$