How to deploy a microservice application using Kubernetes using three machines in my local network?

10/22/2019

As I am new to Kubernetes, I still haven't figured out how to deploy an application on my local network using one or various physical machines. Usually the tutorials on the internet describe situations using minikube, but it is only for local machine tests, isn't it? Or situations where the deploy is performed on cloud platforms, like google.
I would really appreciate some support in where to begin? In my case will I need to install only Kubernetes on the machines? Is it a trivial task?

-- Rodolfo
kubernetes
minikube

4 Answers

10/22/2019

From https://kubernetes.io/docs/setup/learning-environment/minikube/

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a Virtual Machine (VM) on your laptop for users looking to try out Kubernetes or develop with it day-to-day

If you want to set up your own cluster including, there's quite a few options including kubeadm or kubespray.

Personally I've used Vagrant and Ansible to set up a local Kubernetes cluster using kubeadm - there's a good tutorial here... and here's my implementation :)

-- Ryan.Bartsch
Source: StackOverflow

10/22/2019

You can use kubeadm, here is a doc which will help you to install it.

Each server will need to have kubeadm, kubelet and kubectl installed.

On master node you will do kubeadm init and once the whole process is finished it will provide you with an output which you can run to add worker nodes. Of course those servers needs to see each other on your network.

There are also other options to install Kubernetes. For example using kops or kubespray.

-- Spook
Source: StackOverflow

10/22/2019

One way is to install kubernetes is via kubeadm.

I've done this with my own VM. But should also work for your physical machines.

-- loki
Source: StackOverflow

10/23/2019

Kubeadm allows you to create cluster using any machine that runs Docker.

This guide will help you to create your first cluster with 1 master and 1 worker nodes. (This is based on Debian)

Execute the following command on all 2 machines:

Installing Docker from official repository

$ sudo apt-get update
$ sudo apt-get -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
$ curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")    $(lsb_release -cs) stable"
$ sudo apt-get update
$ sudo apt-get install -y docker-ce docker-ce-cli containerd.io
$ sudo groupadd docker
$ sudo usermod -aG docker $USER

Install kubeadm, kubectl and kubelet from official repository

$ sudo apt-get update && sudo apt-get install -y apt-transport-https curl
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

$ sudo su -c "cat > /etc/apt/sources.list.d/kubernetes.list <<EOF
  deb https://apt.kubernetes.io/ kubernetes-xenial main
  EOF"

$ sudo apt-get update
$ sudo apt-get install -y kubelet kubeadm kubectl
$ sudo apt-mark hold kubelet kubeadm kubectl

Execute the following command only on your master node

Initialize your cluster

$ sudo kubeadm init

When the init finishes, kubeadm will give you the command to add your workers to your cluster. Save this command for later use.

EXAMPLE:

kubeadm join 10.128.0.17:6443 --token 27evky.hoel95h16poqici6 \
  --discovery-token-ca-cert-hash sha256:521f69cb935951bbfee142432108caeaeaf1682d8647208ba2f558624890ab63 

After the kubeadm init command completes, run the following commands to start using your new cluster

$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

Your master is not ready yet, we need to create a cni network (You can choose different CNIs)

$ kubectl apply -f https://docs.projectcalico.org/v3.8/manifests/calico.yaml

Check if your master node is ready. It needs a while to start all dependencies $ kubectl get nodes

EXAMPLE:

user@kubemaster:~$ kubectl get nodes
NAME         STATUS     ROLES    AGE   VERSION
kubemaster   NotReady   master   32s   v1.16.2

To check more details about your node:

$ kubectl describe node <NODENAME>

When your master node is ready you can proceed and run the kubectl join command (saved previously) on your worker nodes:

$ sudo kubeadm join 10.128.0.17:6443 --token 27evky.hoel95h16poqici6 --discovery-token-ca-cert-hash sha256:521f69cb935951bbfee142432108caeaeaf1682d8647208ba2f558624890ab63

Check if your worker node is ready (command must be executed on master node)

$ kubectl get nodes

If you want to have more workers, just repeat the kubectl join command on the new workers.

-- mWatney
Source: StackOverflow