In this blog post, I provide a basic guide on how to become a Kubernaut and set up your own Kubernetes Cluster.
… is Greek for helmsman or captain.
And this is what Kubernetes is about – Shipping your containerized applications.
Kubernetes is a system for automating
of containerized applications.
Kubernetes manages the
- Computing Infrastructure
- Networking Infrastructure
- Storage Infrastructure
for your containers.
It manages everything around your application.
Kubernetes Cluster Setup
The most simple Kubernetes Cluster consists of one Kubernetes-Master, which manages an arbitrary amount of Kubernetes-Nodes (Workers).
1. Infrastructure Setup
- Choose your Hardware and Operating System
Since I’m a huge fan of Raspberry Pi’s, in my case I used three Raspberry Pi’s with Raspbian as an operating system (kube-master01, kube-node01 and kube-node02) for my Cluster Setup.
- Connect the hosts to the network infrastructure and assign a static IP for easy access.
- Enable SSH with Public-Key-Authentication to provide root SSH access from the Kubernetes Master to your Nodes.
2. Install Ansible
Install ansible on Kubernetes-Master executing
sudo apt-get install -y ansible.
Check that the installed version is higher than Ansible 2.2 using
3. Kubernetes Cluster Configuration and Setup
Once the Ansible is installed the required Ansible-Playbooks I provided can be downloaded into the Kubernetes-Master.
git clone https://gitlab.com/fabian.guschlbauer/k8cluster-blog.git
- The inventory package contains a hosts file that describes the components or to be precise the master and workers nodes of the Kubernetes Cluster.
Modify inventory/hosts and add your future master and worker hostnames.
My basic Kubernetes Cluster example consists of one Kubernetes-Master (kube-master01) and two Kubernetes-Workers (kube-node01, kube-node02).
root@kube-master01:~/k8cluster# cat inventory/hosts [picluster:children] master workers [master] kube-master01 [workers] kube-node01 kube-node02
- The inventory/host_vars package contains the detailed configuration of the Kubernetes Cluster components. So a configuration file for each of the hostnames specified in inventory/hosts is needed, containing the following information.
root@kube-master01:~/k8cluster# cat inventory/host_vars/kube-master01 ansible_host: HOST_IP ansible_port: 22 ansible_user: root ansible_ssh_private_key_file: SSH_PRIVATE_KEY_FILEPATH ansible_ssh_user: root root@kube-master01:~/k8cluster# cat inventory/host_vars/kube-node01 ansible_host: HOST_IP ansible_port: 22 ansible_user: root ansible_ssh_private_key_file: SSH_PRIVATE_KEY_FILEPATH ansible_ssh_user: root ...
Cluster Setup using Ansible
After the basic Kubernetes Cluster configuration, the provided Ansible Cluster Setup Playbook can be started from the root directory of the cloned setup repository using
At the end of the setup there will be an output like:
Note: In case of any problems or errors, the playbook (cluster.yaml) or any tasks (listed below) can be modified.
root@kube-master01:~/k8cluster# find roles/ -name "main.yml" roles/common/tasks/main.yml roles/workers/tasks/main.yml roles/master/tasks/main.yml roles/cleanup/tasks/main.yml roles/kubeadm/tasks/main.yml roles/dashboard/tasks/main.yml
As the last step of the Kubernetes Cluster Setup, the available nodes can be checked using
kubectl get nodes.
Congratulation Kubernaut, the Kubernetes Cluster setup is done.
Deploy, Deploy, Deploy
As a newly qualified Kubernaut, it is perfectly clear to deploy a first container to the new Kubernetes Cluster.
To do so, simply deploy any docker image you prefer using
kubectl create deployment example –image=<docker_image>
After a few moments, the docker container can be seen up and running.
kubectl get pods
For a detailed description of creating Deployments, I recommend visiting the Kubernetes documentation.