Creating High Available Baremetal Kubernetes cluster with Kubeadm and Keepalived (Simple Guide)

kvaps
kvaps
Oct 18, 2018 · 3 min read

Input data

LoadBalancer setup

apt-get -y install keepalived
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type AH
auth_pass iech6peeBu6Thoo8xaih
}
virtual_ipaddress {
10.9.8.10
}
}
systemctl start keepalived
systemctl enable keepalived

Deploying Kubernetes cluster

apt-get -y install kubeadm kubelet kubectl
systemctl stop keepalived

First node

CLUSTER_IP=10.9.8.10
NODES=(node1 node2 node3)
IPS=(10.9.8.11 10.9.8.12 10.9.8.13)
POD_SUBNET="192.168.0.0/16"
for i in "${!NODES[@]}"; do
HOST=${IPS[$i]}
NAME=${NODES[$i]}
INITIAL_CLUSTER=$(
for j in "${!NODES[@]}"; do
echo "${NODES[$j]}=https://${IPS[$j]}:2380"
done | xargs | tr ' ' ,
)
cat > kubeadm-config-${NODES[$i]}.yaml <<EOT
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: stable
apiServer:
certSANs:
- "${CLUSTER_IP}"
controlPlaneEndpoint: "${CLUSTER_IP}:6443"
etcd:
local:
extraArgs:
initial-cluster: "${INITIAL_CLUSTER}"
initial-cluster-state: new
name: ${NODES[$i]}
listen-peer-urls: "https://${IPS[$i]}:2380"
listen-client-urls: "https://127.0.0.1:2379,https://${IPS[$i]}:2379"
advertise-client-urls: "https://${IPS[$i]}:2379"
initial-advertise-peer-urls: "https://${IPS[$i]}:2380"
serverCertSANs:
- "${NODES[$i]}"
- "${IPS[$i]}"
peerCertSANs:
- "${NODES[$i]}"
- "${IPS[$i]}"
networking:
podSubnet: "${POD_SUBNET}"
EOT
done
kubeadm="kubeadm --config=kubeadm-config-${HOSTNAME}.yaml"
$kubeadm init phase preflight
$kubeadm init phase certs all
$kubeadm init phase kubelet-start
$kubeadm init phase kubeconfig kubelet
$kubeadm init phase etcd local
$kubeadm init phase kubeconfig admin
systemctl start kubelet
NODES="node2 node3"
CERTS=$(find /etc/kubernetes/pki/ -maxdepth 1 -name '*ca.*' -o -name '*sa.*')
ETCD_CERTS=$(find /etc/kubernetes/pki/etcd/ -maxdepth 1 -name '*ca.*')
for NODE in $NODES; do
ssh $NODE mkdir -p /etc/kubernetes/pki/etcd
scp $CERTS $NODE:/etc/kubernetes/pki/
scp $ETCD_CERTS $NODE:/etc/kubernetes/pki/etcd/
scp /etc/kubernetes/admin.conf $NODE:/etc/kubernetes
scp kubeadm-config-$NODE.yaml $NODE:
done

Second node

kubeadm="kubeadm --config=kubeadm-config-${HOSTNAME}.yaml"
$kubeadm init phase preflight
$kubeadm init phase certs all
$kubeadm init phase kubelet-start
$kubeadm init phase kubeconfig kubelet
$kubeadm init phase etcd local
systemctl start kubelet

Third node

kubeadm init --config kubeadm-config-${HOSTNAME}.yaml

First and Second nodes

kubeadm="kubeadm --config=kubeadm-config-${HOSTNAME}.yaml"
$kubeadm init phase kubeconfig all
$kubeadm init phase control-plane all
$kubeadm init phase mark-control-plane
systemctl start keepalived

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade