Just to get some knowledge and test products on it, it is vey useful to be have access to a cluster. One easy way is using Vagrant. Here is how I did it:
I am using a bare metal server running Centos 7.4.1708
- Software installation
- Vagrant 2.0.3
- VirtualBox 5.1.34r121010
- Setup vagrant
- Copy vagrant file from https://gist.github.com/smirzai/8724cb36bd7fcbe4d289b86586b70c5a
- vagrant up. You will have four machines named n1, n2, n3, n4. n1 will be the master node. Each machine will have two network interfaces. Here the local is 192.168.0.0/16
- for each node prepare the machine:
- sudo apt-get update && sudo apt-get upgrade
- Install docker, kubectl, kubeadm, kubelet as described in installing kubeadm document
- swap off -a (This is not persistent. Should be done every time a machine restarts)
- The following changes should be enforced in /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
- Environment=”KUBELET_EXTRA_ARGS=–node-ip=192.168.77.10 –enable-debugging-handlers=true –cluster-dns=10.244.0.10 –cgroup-driver=cgroupfs –cluster-dns=10.244.0.10″
- The above –node-ip should be replaced with ip of the machine
- $KUBELET_CGROUP_ARGS should also be added to the line starting with ExecStart=/usr/bin/kubelet
- restart kubeadm by executing:
- systemctl daemon-reload
- systemctl restart kubelet
- Initialize the cluster:
- sudo kubeadm init –apiserver-advertise-address 192.168.77.10 –pod-network-cidr=10.244.0.0/16 –service-cidr=10.244.0.0/16
- The init command prints the statement for joining the nodes. Write it down somewhere.
- Update the kubectl config file:
- mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config - or execute the following as roo:
export KUBECONFIG=/etc/kubernetes/admin.conf
- mkdir -p $HOME/.kube
- Install flannel:
- download flannel creation yams file:
wget https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml - add “–iface=eth1” to the flannel.yaml in the following line:
command: [ “/opt/bin/flanneld”, “–ip-masq”, “–kube-subnet-mgr” , “–iface=eth1”] - create flannel cid network: kubectl -f flannel.yaml
- Now all nodes should be ready
- Join the n2, n3, n4 by executing the join command written down above in init step
- download flannel creation yams file: