Build a basic Kubernetes lab

Lab to build one Master and two slave nodes.

Use kubeadm tool to bootstrap the environment. (https://kubernetes.io/docs/tasks/tools/install-kubeadm/)

  1. Build three Linux (ubutnu 14.04.4 LTS) virtual machine as kubernetes hosts.
    1. Install the OS
      1. Select OpenSSH server as an option.
    2. Assign static IP Addresses(10.0.51.0/24) ex. kube-master 10.0.51.10; kube-node1,2,3 10.0.51.11,12,13).  The snippet below is an example config file for the regular Ubuntu 16.04 distribution.  If you’re using Ubuntu on Azure, configure a static IP through the portal or CLI.
      nano /etc/network/interfaces
      # The primary network interface
      auto ens32
      #iface ens32 inet dhcp
      iface ens32 inet static
      address 10.0.51.12
      netmask 255.255.255.0
      gateway 10.0.0.1
      dns-nameservers 8.8.8.8
    3. swapoff -a
    4. REM out swap file in /etc/fstab (swap is disabled by default on Azure 16.04 Ubuntu image.)
  1. Install Docker on all three: (https://docs.docker.com/install/linux/docker-ce/ubuntu/#upgrade-docker-ce-1
    https://www.itzgeek.com/how-tos/linux/ubuntu-how-tos/how-to-install-docker-on-ubuntu-16-04.html)

    1. Current (7/2018) Kubernetes release requires 17.03.x
    2. Update repository cache:
      apt-get update
    3. Install package for https and certificates:
      apt-get install -y apt-transport-https software-properties-common ca-certificates curl
    4. Add GPG key for Docker repository:
      wget https://download.docker.com/linux/ubuntu/gpg 
      apt-key add gpg
    5. Add the Docker repository:
      ### Ubuntu 16.04 ###
      echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" | sudo tee /etc/apt/sources.list.d/docker.list
      
      ### Ubuntu 17.10 ### 
      echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu artful stable" | sudo tee /etc/apt/sources.list.d/docker.list
      
      #### Ubuntu 14.04 ###
      echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty stable" | sudo tee /etc/apt/sources.list.d/docker.list
    6. Update apt database:
      apt-get update
    7. If installing from the official Docker repository, you’ll see the desired version.  Ubuntu default repository may not have the desired version.  Run the following to see the list:
      apt-cache policy docker-ce
    8. Look for the latest 17.03 release:
      17.03.2~ce-0~ubuntu-xenial 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
    9. Specifically install Docker 17.03.2:
      apt-get -y install docker-ce=17.03.2~ce-0~ubuntu-xenial
    10. Verify that 17.03.2-ce is installed:
      docker version
  2. Install kubeadm on all three (kubeadm, kubelet, kubectl)
    1. Install the apt-transport-https package:
      apt-get update && apt-get install -y apt-transport-https curl
    2.  Add Google GPG key:
      curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
    3.  Add the sources list into sources.list and update repository:
      cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
      deb http://apt.kubernetes.io/ kubernetes-xenial main
      EOF
      apt-get update
    4.  Install kubeadm and related tools:
      apt-get install -y kubelet kubeadm kubectl
  3. Initialize the master server.  On the kube-master node:
    kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.0.51.10
    1. As a regular user, run the following commands:
      mkdir -p $HOME/.kube
      sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
      sudo chown $(id -u):$(id -g) $HOME/.kube/config
    2. Collect the kubeadm join command to set things up on the other nodes.  The tokens expire after 24 hours.  If later, you’d like to add another node, one would need to generate another token.  Do this on the master:
      kubeadm token create

      A new token will be created.  Take the same command that was generated to join and substitute the old token for the new one.

  4. Set up a POD Network (cluster network) for communications between cluster nodes.  On the master node:
    kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
    1. Check if CoreDNS pod is running to verify pod network is installed:
      kubectl get pods --all-namespaces
    2. ensure that kube-dns-* is running before joining worker nodes.
  5. Join worker nodes to the master node
  6. Run the kubeadm join command previously collected on all the worker nodes.