Learn how to use Kubeadm to install Kubernetes in mins

2 minute read

Introduction

Long time ago, the way to install kubernetes was quite complicate. After kubernetes 1.4, we can use Kubeadm to install a kubernetes cluster with only two steps. Now, let’s start our journey.

Prequisite

  • Ubuntu 16.04

Installation

  • install.sh
#!/bin/bash
apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
# Install docker if you don't have it already.
apt-get install -y docker.io
apt-get install -y kubelet kubeadm kubectl kubernetes-cni

Install basic dependencies

$ chmod +x install.sh
$ sudo ./install.sh

Install Kubernetes core service

$ sudo kubeadm init

Optional:

  • –apiserver-advertise-address: IP address of api server
  • –apiserver-bind-port: port no. of api server (default 6443).
  • –pod-network-cidr: range of virtaul IP for pods.
  • –kubernetes-version: specified Kubernetes version (recommend 1.6+)

Config Kubectl

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

Now, you can use a standalone Kubernetes! Have fun :)

$ kubectl get pod

Troubleshooting

  • Nodes stall in NotReady status due to cni config uninitialized
$ kubectl describe nodes
...
KubeletNotReady runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
...

Kubernetes introduces RBAC since v1.6, we need to create correspond Service Account, RBAC rules and flannel daemonset so that kubelet can communicate with api server correctly. Execute following commands and wait for couple seconds before nodes turn into Ready status.

$ kubectl create -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel-rbac.yml
$ kubectl create -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Advanced CMD

Remove Kubernetes

  • NOTICE: this cmd will remove all kubernetes related services and data.
$ sudo kubeadm reset

Add compute node

Once kubeadm init is finished, you will see the command below with a valid token. Execute the command on new compute node to join the kubernetes cluster.

$ sudo kubeadm join --token <token> <api server ip>:<port>

Access remote Kubernetes api server

$ cp admin.conf <path>/admin.conf
$ kubectl --kubeconfig <path>/admin.conf proxy
Starting to serve on 127.0.0.1:8001
$ kubectl get pod --server=127.0.0.1:8001

Further Readings

Reference


comments powered by Disqus