HOW to install kubernetes on Virtual BOX with Centos 7 : Working perfectly

Setting up the Kubernetes Master

This setup will work on Virtual host labs:

The following actions will be executed on the Kubernetes Master.
  1. Disable swap
    swapoff -a
    
  2. Edit: /etc/fstab
    vi /etc/fstab
    
  3. Comment out swap
    #/root/swap swap swap sw 0 0
    
  4. Add the Kubernetes repo
    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=1
    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
    
  5. Disable SELinux
    setenforce 0
    
  6. Permanently disable SELinux:
    vi /etc/selinux/config
    
  7. Change enforcing to disabled
    SELINUX=disabled
    
  8. Install Kubernetes 
    yum install -y kubelet kubeadm kubectl  kubernetes-cni-0.6.0 --disableexcludes=kubernetes
    
  9. Start and enable the Kubernetes service
    systemctl start kubelet && systemctl enable kubelet
    
  10. Create the k8s.conf file:
    cat << EOF >  /etc/sysctl.d/k8s.conf
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    EOF
    sysctl --system
    
  11. Assuming your Network is 192.168.1.1/16
  12. Initialize Kubernetes
     kubeadm init --pod-network-cidr=192.168.1.0/16
  13. Copy admin.conf to your home directory
    mkdir -p $HOME/.kube
    cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    chown $(id -u):$(id -g) $HOME/.kube/config
  14. Install calico
    curl \
       https://docs.projectcalico.org/v3.5/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml \
       -O
    
       kubectl apply -f calico.yaml
  15. Then reolad kubelete
    systemctl restart kubelet
    

Setting up the Kubernetes Worker nodes

Now that the setup for the Kubernetes master is complete, we will begin the process of configuring the worker node. The following actions will be executed on the Kubernetes worker.
  1. Disable swap
    swapoff -a
    
  2. Edit: /etc/fstab
    vi /etc/fstab
    
  3. Comment out swap
    #/root/swap swap swap sw 0 0
    
  4. Add the Kubernetes repo
    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=1
    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
    
  5. Disable SELinux
    setenforce 0
    
  6. Permanently disable SELinux:
    vi /etc/selinux/config
    
  7. Change enforcing to disabled
    SELINUX=disabled
    
  8. Install Kubernetes 
    yum install -y kubelet kubeadm kubectl kubernetes-cni --disableexcludes=kubernetes
    
  9. Start and enable the Kubernetes service
    systemctl start kubelet && systemctl enable kubelet
    
  10. Create the k8s.conf file:
    cat << EOF >  /etc/sysctl.d/k8s.conf
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    EOF
    sysctl --system
    
  11. Use the join token to add the Worker Node to the cluster:
    kubeadm join < MASTER_IP >:6443 --token < TOKEN > --discovery-token-ca-cert-hash sha256:< HASH >
  12. On the master node, test to see if the cluster was created properly.
  13. Get a listing of the nodes:
    kubectl get nodes
  14.  Note : If your token is expired  issue below command  :: kubeadm token create

Comments

Popular Posts