Skip to content

Instantly share code, notes, and snippets.

@jiankaiwang
Created December 23, 2020 10:11
Show Gist options
  • Save jiankaiwang/7120c3c57c508b61b2ae4e9dc2a100e1 to your computer and use it in GitHub Desktop.
Save jiankaiwang/7120c3c57c508b61b2ae4e9dc2a100e1 to your computer and use it in GitHub Desktop.
The following flow is how to use `kubeadm` to establish a Kubernetes cluster.

Create a kubernetes clsuter on the bare metal machines

The following flow is how to use kubeadm to establish a Kubernetes cluster.

Install the toolkits

In the beginning, use the package management tool to install the necessary components of 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-get update
apt-get upgrade
apt-get install -y kubelet kubeadm kubectl kubernetes-cni

Setup the Node Network

Setup the master and worker nodes separately.

Master node

Initialize the master node.

sudo su
kubeadm reset
kubeadm init --pod-network-cidr 10.244.0.0/16 --control-plane-endpoint 192.168.3.40
exit    # logout the superuser
mkdir ~/.kube
sudo cp -i /etc/kubernetes/admin.conf ./.kube/config
sudo chown 1000:1000 ./.kube/config
kubectl get nodes -o wide -n kube-system
kubectl get pods -o wide -n kube-system

Worker node

Make the worker node join the master one.

sudo su
kubeadm reset
kubeadm join 192.168.3.40:6443 --token <token>     --discovery-token-ca-cert-hash sha256:<token>

Setup the Pod Network

After you setup the node network, next, you have to setup the network of pods.

# for the intel solution,
# flannel was not working
curl https://docs.projectcalico.org/manifests/calico.yaml -O
kubectl apply -f calico.yaml
# for the ARM solution
# calico does not support ARM
curl -sSL https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml > ./kube-flannel.yaml
kubectl apply -f ./kube-flannel.yaml

You can inspect the networking state on Pods.

kubectl get pods -o wide -n kube-system
kubectl describe nodes | grep PodCIDR

Setup the Dashboard

Now, the cluster was established. You can view the status of API from the dashboard.

curl -sSL https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.5/aio/deploy/recommended.yaml > dashboard.yaml
kubectl apply -f ./dashboard.yaml
kubectl get pods -o wide -n kubernetes-dashboard

# view from the node port
kubectl proxy --address 0.0.0.0 --accept-hosts='.*'
@jiankaiwang
Copy link
Author

The followings are some tips when kubeadm init fails.

  • missing required cgroups: memory

You can add the following parameters cgroup_enable=memory cgroup_memory=1 to the end of the file /boot/firmware/cmdline.txt.

  • Kubelet can't start because of the cni issue.

Because the docker's default cgroup is different from k8s, you can add the configure {"exec-opts": ["native.cgroupdriver=systemd"]} to the file /etc/docker/daemon.json and restart the docker.

@jiankaiwang
Copy link
Author

jiankaiwang commented Apr 17, 2022

You can surf the dashboard by the following links.

  • http://ip-address_or_hostname:8001
  • http://ip-address_or_hostname:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment