Skip to content

Instantly share code, notes, and snippets.

Last active July 28, 2023 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilangvperdana/645915a298704117042133ca26e0cbdd to your computer and use it in GitHub Desktop.
Save gilangvperdana/645915a298704117042133ca26e0cbdd to your computer and use it in GitHub Desktop.
Kubeadm 2 Nodes All Role


  • 2x Ubuntu 20.04LTS
  • 2 VCPU
  • 2GB RAM
  • 50GB Storage


  • Assume node1 have IP ->

Update & Install Package

sudo apt update -y
sudo apt -y install curl apt-transport-https
curl -s | sudo apt-key add -
echo "deb kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update
sudo apt -y install vim git curl wget kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
kubectl version --client && kubeadm version

Turnoff Swap

sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
sudo swapoff -a
sudo mount -a
free -h

Activate Net Package

sudo modprobe overlay
sudo modprobe br_netfilter

sudo tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
sudo sysctl --system

Install Docker & Containerd

  • We will use container as container runtime & docker as build env
sudo apt update
sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
curl -fsSL | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
sudo apt update
sudo apt install -y docker-ce docker-ce-cli
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/docker/daemon.json <<EOF
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  "storage-driver": "overlay2"

containerd config default > /etc/containerd/config.toml 
systemctl restart containerd

sudo systemctl daemon-reload 
sudo systemctl restart docker
sudo systemctl enable docker
sudo systemctl enable kubelet
sudo sysctl -p

Pull Kubernetes Component Container Image

sudo kubeadm config images pull

Initialize Cluster

sudo kubeadm init \
  --pod-network-cidr= \

If you have an VIP you can add --control-plane-endpoint <endpoint-ip-or-dns>:<port> to Initiation Kubeadm. This article doesnt have an VIP so HA can't achieve on this article.

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

Add node2 to Cluster

  • In this article, we will make node2 as controller & worker too
    • As i mentioned on top, this article lab doesnt have an VIP so i just tricking all of this into working, but in fact it won't work since node1 is still the backbone.
kubectl -n kube-system edit cm kubeadm-config

## Agar menjadi seperti ini
apiVersion: v1
  ClusterConfiguration: |
        authorization-mode: Node,RBAC
      timeoutForControlPlane: 4m0s
    certificatesDir: /etc/kubernetes/pki
    clusterName: kubernetes
    controlPlaneEndpoint: node1:6443

Print Join Token on Node1

echo $(kubeadm token create --print-join-command) --control-plane --certificate-key $(kubeadm init phase upload-certs --upload-certs | grep -vw -e certificate -e Namespace)

Join (exec on Node2)

kubeadm join --token r1vzt4.pezwi321b3w0g4i3 \
  --discovery-token-ca-cert-hash sha256:75d689244b2e9a94de4c4638842bcd7f106bf0cccc62556bcd568bba32225c1e \
  --control-plane --certificate-key 3ed139a494117f344f551e48dde981f5fa7e126ee4b52755aee6edcca7efa7d9

Untaint Node

kubectl taint nodes --all
kubectl taint nodes --all

Deploy Container Network Component (Flannel)

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