Kubernetes has released v1.8 since Sepetember 2017. The former installation steps for v1.75 are not compatible to the new version. The article is to document the steps I took to install Kubernetes cluster on Ubuntu Server 16.04 LTS with kubeadm. The steps are tested by installing Kubernetes v1.8.4.
Prerequisites
Install Ubuntu Server 16.04 LTS using the HWE kernel (version 4.10) option. The HWE kernel is version 4.10 and aims to support newer platforms, while the Ubuntu Sever 16.04 LTS standard kernel is version 4.40.
Environment Preparation
Setup proxy if you work behind the corporate network as Kubeadm uses the system proxy to download components. Put the following settings in the $HOME/.bashrc
file. Be mindful to put the master host’s IP address in the no_proxy list.
And check your proxy settings:
Next perform a software update for all packages before you continue with the cluster installation.
Install latest OS updates
|
|
Disable Swap
Since v1.8, it is required to turn swap off. Otherwise, kubelet service cannot be started. We disable system swap by run this command:
System Configuration
We suppose that we have four servers ready, one as k8s master and the other three as k8s nodes.
Configure local DNS in /etc/hosts
. Map the IP address with host names.
Install Kubernetes version 1.8.4 on each of your hosts.
|
|
Install Docker version 17.09 on each of your hosts
|
|
And ensure that the service is up and running:
Note: Make sure that the cgroup driver used by kubelet is the same as the one used by Docker. To ensure compatibility you can either update Docker settings (like what the official document recommends) or update kubelet setting by adding the setting option below to file /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
:
After updating the service file (for either kubelet or docker service), do remember to reload the configuration and restart the service
Other than that, it is highly recommended that you use the overlay2
driver which is faster and stronger than other docker storage drivers. You may follow the instructions here to complete the installation.
Initialize Kubernetes Master
On the master node (load balancer), if you run as root, do
If you run as a normal user, do
If --apiserver-advertise-address
is not specified, it auto-detects the network interface to advertise the master. Better to set the argument if there are more than one network interface.--pod-network-cidr
is to specify the virtual IP range for the third party network plugin.
Set --use-kubernetes-version
if you want to use a specific Kubernetes version.
To start using your cluster, you need to run (as a regular user):
By default, your cluster will not schedule pods on the master for security reasons. Expand your load capacity if you want to schedule pods on your master.
Install WeaveNet Pod Network Plugin
A pod network add-on is supposed to be installed in order that pods can communicate with each other.
Set /proc/sys/net/bridge/bridge-nf-call-iptables
to 1 by adding net.bridge.bridge-nf-call-iptables=1
to file /etc/sysctl.d/k8s.conf
in order to pass bridged IPv4 traffic to iptables’ chains.
And run the following command to make it take effect:
Then run:
Check the status of Weave pods and make sure that it is in Running
state:
Join Nodes to Cluster
Get the cluster token on master:
Since Kubernetes v1.8, the token is only valid for 24 hours. You may generate another token if the previous one gets expired.
Run the commands below on each of the nodes:
Replace the token e5e6d6.6710059ca7130394
and the sha256 hash with the actual token and hash got from kubeadm init
command.
“Pub key validation” can be skipped passing --discovery-token-unsafe-skip-ca-verification flag
instead of using --discovery-token-ca-cert-hash
but the security would be weakened;
And check whether nodes joins the cluster successfully.
Install Dashboard Add-on
Create the dashboard pod :
To start using Dashboard run following command:
Then access the dashboard at http://192.168.1.102:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/. Replace the IP address with the actually IP you are using.
There are a couple of ways to login here. For development purpose, you may simply grant full admin privileges to Dashboard’s Service Account by creating below ClusterRoleBinding. Copy the contents below and save as a file named dashboard-admin.yaml
. Use kubectl create -f dashboard-admin.yaml
to deploy it. Afterwards you can use Skip option on login page to access Dashboard.
Tear Down
Firstly, drain the nodes on the master or wherever credential is configured. It does a graceful termination and marks the node as unschedulable.
Then on the node to be removed, remove all the configuration files and settings
Diagnose
Check services and pods status.
kube-system
is the default namespace for system-level pods. You may also pass other specific namespaces. Use--all-namespaces
to check all namespaces1kubectl get po,svc -n kube-systemThis is how the output looks like:
123456789101112131415NAME READY STATUS RESTARTS AGEpo/etcd-loadbalancer 1/1 Running 0 9mpo/kube-apiserver-loadbalancer 1/1 Running 0 9mpo/kube-controller-manager-loadbalancer 1/1 Running 0 10mpo/kube-dns-545bc4bfd4-2qvkk 3/3 Running 0 10mpo/kube-proxy-6rk26 1/1 Running 0 10mpo/kube-proxy-qvhmw 1/1 Running 0 1mpo/kube-scheduler-loadbalancer 1/1 Running 0 9mpo/kubernetes-dashboard-7486b894c6-dw8zz 1/1 Running 0 23spo/weave-net-s59fw 2/2 Running 0 3mpo/weave-net-zsfls 2/2 Running 1 1mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEsvc/kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 10msvc/kubernetes-dashboard ClusterIP 10.110.76.10 <none> 443/TCP 23sCheck pods logs. Get pod name from the command above (eg.
kubernetes-dashboard-3313488171-tkdtz
). Use-c <container_name>
if there are more than one containers running in the pod.1kubectl logs <pod_name> -f -n kube-systemRun commands in the container. Use
-c <container_name>
if there are more than one containers running in the pod.
Run a single command:1kubectl exec <pod_name> -n <namespace> <command_ to_run>Enter the container’s shell:
1kubectl exec -it <pod_name> -n <namespace> -- /bin/bashCheck Docker logs
1sudo journalctl -u docker.service -fCheck kubelet logs
1sudo journalctl -u kubelet.service -f
References: