Setup Kubernetes on Ubuntu [Part-2] - Hacker Tune

Latest

Stay updated with bleeding edge technology

Wednesday 1 April 2020

Setup Kubernetes on Ubuntu [Part-2]

In the previous post we have successfully installed Docker, K8s component which required as part of setting up kubernetes cluster.
Running Cluster

On the Kube master node, initialize the cluster:


sudo kubeadm init --pod-network-cidr=10.244.0.0/16
 
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
 
Verify that the cluster is responsive and that Kubectl is working:


kubectl version
 
The kubeadm init command should output a kubeadm join command containing a token and hash. 

Copy that command and run it with sudo on both worker nodes.


sudo kubeadm join $some_ip:6443 --token $some_token --discovery-token-ca-cert-hash $some_hash
Verify that all nodes have successfully joined the cluster:


kubectl get nodes
You should see all three of your nodes listed. It should look something like this:

 
NAME                      STATUS     ROLES    AGE     VERSION
master-1.mylabserver.com   NotReady   master   5m17s   v1.17.2
worker-1.mylabserver.com   NotReady   <none>   53s     v1.17.2
worker-2.mylabserver.com   NotReady   <none>   31s     v1.17.2
Note: The nodes are expected to have a STATUS of “NotReady at this point.


Configure Networking with Flannel

Once the Kubernetes cluster is set up, we need to configure cluster networking in order to make the cluster fully functional. Flannel is responsible for assigning IP to a pod and act as a packet forwarder by running a daemon flanneld on every node.
Flannel acquire a subnet lease, configure its routes based on other leases in the overlay network and start routing packets.
Flannel official site: https://coreos.com/flannel/docs/latest/

  • On all three nodes, run the following:
     
    echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.conf
    sudo sysctl -p
     
  • Install Flannel in the cluster by running this only on the Master node:
     
    kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
    
     
  • Verify that all the nodes now have a STATUS of Ready:
     
    kubectl get nodes
    

    You should see all three of your servers listed, and all should have a STATUS of Ready. It should look something like this:
     
    NAME                      STATUS     ROLES    AGE     VERSION
    wboyd1c.mylabserver.com   Ready      master   5m17s   v1.17.2
    wboyd2c.mylabserver.com   Ready      <none>   53s     v1.17.2
    wboyd3c.mylabserver.com   Ready      <none>   31s     v1.17.2
Note: It may take a few moments for all nodes to enter the Ready status

Run this command to get a list of system pods:


kubectl get pods -n kube-system
 
You should have three pods with flannel in the name, and all three should have a status of Running.

1 comment:

  1. Update:
    kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

    ReplyDelete