loading...

Getting Started with Kubernetes (at home) — Part 1

just_insane profile image Justin Gauthier Originally published at homelab.blog on ・3 min read

When you think about Kubernetes, you probably think AWS or GCP, a nice managed service where you can easily spin up resources and build applications on top of them. This is great, and honestly the best way to experience Kubernetes. However, if all you need is a lab to mess around in and experiment, or learn new things in, this can be very cost inefficient. That is why we are going to look at setting up Kubernetes ourselves.

In this post, we are going to look at the initial deployment of Kubernetes, from creating our nodes (in this case CentOS 7 VMs) to getting a cluster up and running.

Part 1: Installing our VMs

The first step is to create some VMs. I use a custom vCenter template in my lab, but if you do not have one of those, you can follow these simple steps.

You will need to complete these steps on at least 1 machine, however more is certainly better to get the full benefit of Kubernetes.

Your machine/VM should have at least 1 core and 3Gb of RAM.

  1. Install CentOS 7 from the USB ISO image, a basic install is fine
  2. Create a user for Ansible access. This user should be part of the sudo users group, and ideally have passwordless SSH authentication
  3. Assign static IP Addresses to your hosts. Optionally set a hostname.
  4. I hate to say it, but the official docs say to disable the firewall between the nodes, and I was unable to find documentation on which ports are needed.
  5. Optionally, add your hosts to DNS.

Part 2: Kubernetes Installation

We are going to be using Kubespray for our cluster, as it makes creating and updating a Kubernetes cluster very simple and straightforward.

You can find the official docs here.

The quick guide is as follows:

  1. Install the dependencies

    sudo pip install -r requirements.txt

  2. Copy the example Inventory

    cp -rfp inventory/sample inventory/mycluster

  3. Build the inventory, you can use the built in builder, or take a look here for an example. It is fine to have a single master, but the kube-master and etcd sections should be the same.

  4. Deploy the cluster

    ansible-playbook -i inventory/mycluster/hosts.yml --become --become-user=root cluster.yml

Then all you have to do is wait while Kubespray deploys your cluster automatically. On my 6 node cluster, it usually takes about 10–15 minutes for the cluster to be completely setup and running.

Note that in the Kubespray inventory there are a couple of options which are useful to enable. First, in the addons.yaml file, it is a good idea to enable Helm and the Kubernetes Dashboard automatic deployments. It may also be beneficial to enable kube_basic_auth in the k8s-cluster.yaml file, if you are having issues with the default token based authentication. If you decide to do this later, you can simply make the change and then re-run the deployment with the command in step 4 above.

Part 3: Testing the Cluster

You can test that your cluster is up and running with the following commands:

  1. kubectl cluster-info which should return something like:

    Kubernetes master is running at https://10.0.40.245:6444

  2. kubectl get nodes which displays the state of all of your nodes.

You can find more information about how I have setup Kubernetes at my Gitlab repo, which has helpful code snippets, full configuration files, as well as expanded documentation.

Posted on by:

just_insane profile

Justin Gauthier

@just_insane

I am a college grad living in Canada, with an avid interest in programming and system administration.

Discussion

markdown guide
 

Hey there! After hitting my limit with minikube, I decided to give this a try. It looks like a great thing, but I'm struggling with the kubectl configuration. Nothing I try seems to be able to access the cluster after it seems to have successfully built. I'm a noob with setting this up so I may have missed something obvious.

 

It can take a little while for the cluster to come up.

Also, check the kube config file and make sure the IP is correct.

 

Got it working shortly after commenting of course. I stole the ~/.kube/config off the master for my workstation and it worked! Thank you for the reply. Onward and upward!

 

Interesting approach! It might be of interest as another alternative to use something like k3s.io/ as a lightweight method of setting up a kubernetes cluster - supposedly works great on a few raspberry pis on a home network!

 

K3s is definitely an option, however I’m using K8s mainly for learning, and it’s nice that my config can be converted for use in a public cloud very easily.

Also, running on Pi’s can be a pain unless everything you want to run has an ARM container, or you build your own.