Kubernetes Setup on Ubuntu 16.04

Juniarto Samsudin
3 min readApr 24, 2019

--

This step by step instructions is based on my experiment, following Hemant Sharma’s “How To Install Kubernetes Cluster On Ubuntu 16.04”. I encountered many problems, mainly due to the VMs I used were not fresh-installed. If you have the luxury, to be able to fresh-install your VMs, do it! You really don’t want to go through the pain that I have been through.

My setup comprised of 1 Master and 3 Normal Nodes.

On all the master and normal nodes:

  1. Switch off firewall

sudo systemctl stop ufw

sudo systemctl disable ufw

2. Turn off swap space

sudo swapoff -a

sudo vim /etc/fstab

3. Edit /etc/hosts

4. I am using docker version 18.09.5.

To check your docker version: docker version

If you believe your docker version is somehow outdated, you have to remove it before you install the new version.

To remove old version:

sudo apt-get remove docker docker-engine docker.io containerd runc

Install the latest version:

sudo apt-get update

sudo apt-get install docker-ce

5. Docker bridge adapter, composer_default, docker_gwbridge poised problem in kubernetes networking.

To check the existing of such adapters: sudo docker network ls

Remove composer_default and docker_gwbridge:

sudo docker network rm composer_default

sudo docker network rm docker_gwbridge

6. 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’ | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update

apt-get install kubelet kubeadm kubectl –y

7. Changing kubernetes configuration

sudo vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

On Master only:

1. Execute the following:

sudo kubeadm init — apiserver-advertise-address=172.20.98.139 — pod-network-cidr=192.168.0.0/16

172.20.98.139 : is the ip address of your master

192.168.0.0/16: for calico pod network, make sure it doesn’t exist in your physical network.

You will get the following output:

To start using your cluster, you need to run the following as a regular user:

Step 1.

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.

Step 2.

Run “kubectl apply -f [podnetwork].yaml” with one of the options listed at:

https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

Step 3.

kubeadm join 172.20.98.139:6443 — token 2izp99.h3n43nbawqor0879 \

— discovery-token-ca-cert-hash sha256:e6bf7af8fbcf6efb38fbf523cd0da236101dbc9a3be1f595681ffa050573d7c2

Explanation:

Step 1 instruction is quite straightforward.

Step 2. There are many pod network deployment scheme. [https://kubernetes.io/docs/concepts/cluster-administration/addons/]. But we are going to use calico network. If you want to learn more, you can go to https://docs.projectcalico.org/v3.6/getting-started/kubernetes/.

Execute the following instruction:

sudo kubectl apply -f https://docs.projectcalico.org/v3.6/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

Calico network sometimes can be really fussy on our network configuration. In several occasions, the calico nodes failed to launch. Deploying flannel network is much easier.

sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

2. Installing the dashboard.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml

To see the dashboard, you have to run : kubectl proxy

Then you navigate your browser to

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

3. Create account and credentials for the dashboard.

a. $kubectl create serviceaccount dashboard -n default

b. $ kubectl create clusterrolebinding dashboard-admin -n default \

— clusterrole=cluster-admin \

— serviceaccount=default:dashboard

c. get the token to access your dashboard.

$ kubectl get secret $(kubectl get serviceaccount dashboard -o

jsonpath=”{.secrets[0].name}”) -o jsonpath=”{.data.token}” | base64 — decode

On the remaining of normal nodes:

Only one step:

sudo kubeadm join 172.20.98.139:6443 — token 2izp99.h3n43nbawqor0879 \

— discovery-token-ca-cert-hash sha256:e6bf7af8fbcf6efb38fbf523cd0da236101dbc9a3be1f595681ffa050573d7c2

--

--

No responses yet