Installing kuberenets on vagrant

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

  1. Software installation
    • Vagrant 2.0.3
    • VirtualBox 5.1.34r121010
  2. Setup vagrant
    1. Copy vagrant file from https://gist.github.com/smirzai/8724cb36bd7fcbe4d289b86586b70c5a
    2. 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
  3. for each node prepare the machine:
    1. sudo apt-get update && sudo apt-get upgrade
    2. Install docker, kubectl, kubeadm, kubelet as described in installing kubeadm document
    3. swap off -a (This is not persistent. Should be done every time a machine restarts)
    4. The following changes should be enforced in /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
      1. 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″
      2. The above –node-ip should be replaced with ip of the machine
      3. $KUBELET_CGROUP_ARGS should also be added to the line starting with ExecStart=/usr/bin/kubelet
      4. restart kubeadm by executing:
        1. systemctl daemon-reload
        2. systemctl restart kubelet
    5. Initialize the cluster:
      1. 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
      2. The init command prints the statement for joining the nodes. Write it down somewhere.
      3. Update the kubectl config file:
        1. mkdir -p $HOME/.kube
          sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
          sudo chown $(id -u):$(id -g) $HOME/.kube/config
        2. or execute the following as roo:
          export KUBECONFIG=/etc/kubernetes/admin.conf
      4. Install flannel:
        1. download flannel creation yams file:
          wget https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
        2. add “–iface=eth1” to the  flannel.yaml  in the following line:
          command: [ “/opt/bin/flanneld”, “–ip-masq”, “–kube-subnet-mgr” , “–iface=eth1”]
        3. create flannel cid network: kubectl -f flannel.yaml
        4. Now all nodes should be ready
        5. Join the n2, n3, n4 by executing the join command written down above in init step

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.