WillSquire
4/17/2018 - 3:52 PM

Install Kubernetes cluster on Ubuntu

Install Kubernetes

This part of the installation is carried out on all nodes.

Perform updates and upgrades:

apt -y update &&
apt -y full-upgrade --auto-remove &&
apt -y upgrade

Install, enable and start Docker:

apt install -y docker.io &&
systemctl start docker &&
systemctl enable docker

Install Kubernetes:

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add &&
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list &&
apt -y update &&
apt install -y kubelet kubeadm kubectl kubernetes-cni

Master node

This part of the installation is carried out on the master node only.

Initialise the master node. If the non default IP address should be used, such as for routeing the cluster node in the same datacenter using private IP addresses, then --api-advertise-addresses should be added:

kubeadm init --apiserver-advertise-address PRIVATE_IP

Copy the join command outputted (i.e.kubeadm join ...) so that worker nodes can join later on, then create a non-priveledged user as the output suggests (replacing PASSWORD as appropriate):

useradd kubernetes -G sudo -m -s /bin/bash &&
echo "kubernetes:PASSWORD" | chpasswd

Copy the config (password required for sudo):

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

May not be needed now and Flannel shouldn't be used without giving args on init above. Deploy a CNI (container network interface) to deploy pods to the cluster. Flannel is used here, but other cluster network technologies are avalible.

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml &&
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml

Optional

By default pods can't be deployed on master nodes. To allow pods on master nodes and also allow a single node deploy:

kubectl taint nodes --all node-role.kubernetes.io/master-

References