Installing Kubernetes on a two node cluster in Ubuntu

Howto Apr 02, 2019

A master and 2 node workers

This post describes stepwise how to install kubernetes with on a 2 node cluster on ubuntu

deploying the Master or Control host

ssh or login to the master machine
log in as root

sudo -s

add the repository key

wget -O - https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

add the repository

cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

update all packages and install kubelet, kubeadm, kubectl and pull all images necessary for orchestration

apt-get update
apt-get install -y kubelet kubeadm kubectl
kubeadm config images pull

initialize the network

kubeadm init --pod-network-cidr=192.168.0.0/16 --apiserver-cert-extra-sans="$custom-domain" --node-name="$master-custom-domain"
kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f https://docs.projectcalico.org/v3.6/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

configure the master node

mkdir -p /home/$user/.kube
chown $user:$group /home/ubuntu/.kube
cp /etc/kubernetes/admin.conf /home/$user/.kube/config
chown $user:$group /home/$user/.kube/config
exit

log in as $user and setup bash completion for kubernetes

kubectl version --short
kubectl completion bash > ~/.kube/completion.bash.inc

printf "
# Kubectl shell completion
echo source '$HOME/.kube/completion.bash.inc'" >> $HOME/.bash_profile

source $HOME/.bash_profile

Installing Kubernetes on the nodes

wget -O - https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

log in as root

cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm

login to the master and view the necessary token for the nodes to join the master

kubeadm token create --print-join-command
kubeadm join some_ip_address:6443 --token xxxxxxxxxxxxxxxx     --discovery-token-ca-cert-hash sha256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

login back to the node and run the join command

kubeadm join some_ip_address:6443 --token xxxxxxxxxxxxxxxx     --discovery-token-ca-cert-hash sha256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

run all the commands again on the installing kubernetes on the nodes on the second worker

login to the master

kubectl get nodes
NAME                 STATUS   ROLES    AGE    VERSION
master-cluster       Ready    master   168m   v1.14.0
worker-one-cluster   Ready    <none>   148m   v1.14.0
worker-two-cluster   Ready    <none>   141m   v1.14.0
Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
#