Building a Kubernetes Cluster with Kubeadm


To build a cluster, you need to have master and slave nodes and dockers need to be installed.

1. Install Docker on all three nodes.keyboard_arrow_up
  1. Do the following on all three nodes:
    • apt install gpg-agent
    
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
    sudo apt-get update
    sudo apt-get install -y docker-ce=18.06.1~ce~3-0~ubuntu
    sudo apt-mark hold docker-ce
  2. Verify that Docker is up and running with:
    sudo systemctl status docker

2. Install Kubeadm, Kubelet, and Kubectl on all three nodes.keyboard_arrow_up

  1. Install the Kubernetes components by running this on all three nodes:
    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
    cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
    deb https://apt.kubernetes.io/ kubernetes-xenial main
    EOF
    sudo apt-get update
    sudo apt-get install -y kubelet=1.12.7-00 kubeadm=1.12.7-00 kubectl=1.12.7-00
    sudo apt-mark hold kubelet kubeadm kubectl
3. Bootstrap the cluster on the Kube master node.keyboard_arrow_up
  1. On the Kube master node, do this:
    sudo kubeadm init --pod-network-cidr=10.244.0.0/16

    That command may take a few minutes to complete.

  2. When it is done, set up the local kubeconfig:
    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config

    Take note that the kubeadm init command printed a long kubeadm join command to the screen.

    You will need that kubeadm join command in the next step!

  3. Run the following commmand on the Kube master node to verify it is up and running:
    kubectl version

    This command should return both a Client Version and a Server Version.

  4. Join the two Kube worker nodes to the cluster.keyboard_arrow_up

    1. Copy the kubeadm join command that was printed by the kubeadm init command earlier, with the token and hash. Run this command on both worker nodes, but make sure you add sudo in front of it:
      sudo kubeadm join $some_ip:6443 --token $some_token --discovery-token-ca-cert-hash $some_hash
    2. Now, on the Kube master node, make sure your nodes joined the cluster successfully:
      kubectl get nodes

      Verify that all three of your nodes are listed. It will look something like this:

      NAME            STATUS     ROLES    AGE   VERSION
      ip-10-0-1-101   NotReady   master   30s   v1.12.2
      ip-10-0-1-102   NotReady      8s    v1.12.2
      ip-10-0-1-103   NotReady      5s    v1.12.2

      Note that the nodes are expected to be in the NotReady state for now.

  5. Set up cluster networking with flannel.keyboard_arrow_up

    1. Turn on iptables bridge calls on all three nodes:
      echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.conf
      sudo sysctl -p
    2. Next, run this only on the Kube master node:
      kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml

      Now flannel is installed! Make sure it is working by checking the node status again:

      kubectl get nodes

      After a short time, all three nodes should be in the Ready state. If they are not all Ready the first time you run kubectl get nodes, wait a few moments and try again. It should look something like this:

      NAME            STATUS   ROLES    AGE   VERSION
      ip-10-0-1-101   Ready    master   85s   v1.12.2
      ip-10-0-1-102   Ready       63s   v1.12.2
      ip-10-0-1-103   Ready       60s   v1.12.2

 

How to commit docker images


[cloud_user@aryan1c ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

To commit docker image, you need to copy the identification number
65d264fc1d7e centos:6 “/bin/bash” 39 minutes ago Exited (0) About a minute ago quirky_nightingale
5fdeaceec288 spacebones/doge “nginx -g ‘daemon …” 2 hours ago Up 2 hours 0.0.0.0:80->80/tcp treatseekers
[cloud_user@aryan1c ~]$ docker commit 65d264fc1d7e spacebones:thewebsite
sha256:d764a58ff47b2db18aec6aa2928b404998130cdba8edcaa6af78ea5f744b651f
[cloud_user@aryan1c ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
spacebones thewebsite d764a58ff47b 4 seconds ago 511 MB

Apache2 Ubuntu Default Page shows instead of my actual website


To avoid this to happen
mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.bak

apache

chkconfig httpd on

How to copy contents to web server directory in Linux


To copy contents to Apache Web Server Directory, Use CP

cp YOURCONTENT/FOLDER/* /var/www/html/

Example:

[root@65d264fc1d7e /]# cp content-dockerquest/mydocker/* /var/www/html/

How to install Apache in Linux container


[root@65d264fc1d7e /]# yum -y install httpd
Loaded plugins: fastestmirror, ovl
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirror.cisp.com
* extras: mirrors.mit.edu
* updates: mirror.trouble-free.net
Resolving Dependencies
–> Running transaction check
—> Package httpd.x86_64 0:2.2.15-69.el6.centos will be installed
–> Processing Dependency: httpd-tools = 2.2.15-69.el6.centos for package: httpd-2.2.15-69.el6.centos.x86_64
–> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-69.el6.centos.x86_64