A simple demo to setup Kubernetes on bare-metal (and also on VM via Vagrant.
- Ubuntu 18.04.1 LTS (Bionic Beaver). The Vagrantfile is based on this distribution.
- Ansible
For VMs we need:
- Vagrant
- vagrant-rsync-back to obtain the
KUBECONFIG
file from the master node.
$ vagrant plugin install vagrant-rsync-back
Execute Ansible playbook to provision the machine.
cd ansible
export PRIV_KEY=""
ansible-playbook --diff --check -vv provision.yml --private-key="${PRIV_KEY}" --ask-become-pass
Use Vagrant.
cd vagrant
vagrant up
- SSH into the master node and setup Kubernetes master with
kubeadm
.
# export IP_ADDR="" # For Vagrant, this should be 192.168.50.110
# kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address="${IP_ADDR}"
- Copy the
/etc/kubernetes/admin.conf
file and use that withkubectl
to talk with kubernetes. We can use theKUBECONFIG
environment variable for this. For Vagrant this can be done with:
# cp -i /etc/kubernetes/admin.conf /vagrant/config
# chown vagrant:vagrant /vagrant/config
On the host, run the follwing under the vagrant/
directory to copy the config file to host
$ vagrant rsync-back
$ ls kubernetes
config
$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
$ kubectl apply -f kube-flannel.yml
Taint the master node so that we can use the master as single-host cluster.
$ kubectl taint nodes --all node-role.kubernetes.io/master-
When we have more machines to join the the cluster, we can generate the join command within the master node and use the resulting kubeadm join
command in the worker node to add it into the cluster.
# kubeadm token create --print-join-command
kubeadm join <IP-ADDR> --token <SECRET> --discovery-token-ca-cert-hash <HASH>