skip to Main Content

How to install Kubernetes and How to add worker-nodes to Kubernetes-Master

2

Answers


  1. Chosen as BEST ANSWER

    Let's consider 1 Kubernetes-Cluster and 2 Worker-Nodes

    1. While launching AWS ec2 instances, make sure that you open all the ports in the related security groups.
    2. All EC2 instances need to be on the same VPC and in the same availability zone.
    3. For K8-Cluster minimum requirement is t2.large
    4. For Worker-Nodes minimum requirement is t2.micro
    5. Login to putty/terminal to connect to your EC2 instances.

    Run the following Commands on both K8-Cluster and Worker-nodes

    • Be a root user. Install Docker and start Docker service. Also, enable the docker service so that the docker service starts on the system restarts.
    sudo su
    yum install docker -y 
    systemctl enable docker && systemctl start docker
    
    • Create proper yum repo files so that we can use yum commands to install the components of Kubernetes.
    cat <<EOF > /etc/yum.repos.d/kubernetes.repo
    [kubernetes]
    
    name=Kubernetes
    
    baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
    
    enabled=1
    
    gpgcheck=1
    
    repo_gpgcheck=0
    
    gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
    
    exclude=kube*
    
    EOF
    
    • sysctl command is used to modify kernel parameters at runtime. Kubernetes needs to have access to the kernel’s IP6 table and so we need to do some more modifications. This includes disabling secure Linux.
    cat <<EOF >  /etc/sysctl.d/k8s.conf
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    EOF
    
    sysctl --system
    setenforce 0
    
    • Install kubelet, kubeadm and kubectl; start kubelet daemon
    yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
    systemctl enable kubelet && systemctl start kubelet
    
    vi /etc/docker/daemon.json
    
    {
        "exec-opts": ["native.cgroupdriver=systemd"]
    }
    
    • restart docker and kubelet; reload daemon
     sudo systemctl daemon-reload
     sudo systemctl restart docker
     sudo systemctl restart kubelet
    

    Only on the Master Node:

    • On the master node initialize the cluster.
    kubeadm init --ignore-preflight-errors all
    
    • To make kubeconfig file permanent , paste the export KUBECONFIG=/etc/kubernetes/admin.conf after export PATH in .bash_profile
    ls -al
    vi .bash_profile
    
    export KUBECONFIG=/etc/kubernetes/admin.conf
    

    On All Worker nodes :

    • Copy kubeadm join command from the output of kubeadm init on the master node.
    <kubeadm join command copied from master node>
    
    # kubeadm join 172.31.37.128:6443 --token sttk5b.vco0jw5bkkf1toa4 
                     --discovery-token-ca-cert-hash sha256:d77b5f865c1e30b73ea4dd7ea458f79f56da94f9de9c8d7a26b226d94fd0c49e
    

    On the Master Node :

    • Create weave-net.
    kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d 'n')"
    
    kubectl get nodes
    

    That's it :)


  2. The easiest way to start Kubernetes on Amazon Linux AMI (or any other Linux AMI) is to use Microk8s (a lightweight distribution of Kubernetes).

    The following steps will help you get started with Kubernetes on EC2 instance:

    1. Install Microk8s on EC2 instance

      sudo snap install microk8s --classic

    2. Check the status while Kubernetes starts

      microk8s status --wait-ready

    3. Turn on the services you want

      microk8s enable dashboard dns registry istio

    4. Start using Kubernetes

      microk8s kubectl get all --all-namespaces

    5. Access the Kubernetes dashboard

      microk8s dashboard-proxy

    6. Start and stop Kubernetes to save battery
      microk8s start and microk8s stop

    This way you can install a local version of Kubernetes with Microk8s. You can also follow this tutorial for detailed instructions on the above steps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search