Wednesday, 27 January 2021

How to install IPv4/IPv6 Kubernetes Dual Stack Cluster ?

 

   Steps to install Kubernetes Dual Stack Cluster 

Below lists simple steps that can be followed to set up a dual stack cluster using ubuntu VMs. You can set it up in any OS. I have windows machine.

1 master+ 2 node deployment

 Prerequisites

  • Oracle VM Virtual Box : Download from https://www.virtualbox.org/
  • Turn on hardware virtualization support in BIOS Settings. (Hyper V in windows 10 )

Create VMs

Create 2 VMs for 1 master with 1 worker node cluster with below requirements
  • Version: Ubuntu (64-bit)
  • Processor: 2 CPU
  • 4 GB RAM
  • Network : Select NAT as adapter 1 and Host only adapter as adapter 2

Initial setup on all nodes

  1. Turn off swap  using  sudo swapoff -a
             Comment the line with swap in /etc/fstab
              nano /etc/fstab  
  2. Add IPv6 address on all nodes
            E.g.  master# ifconfig enp0s8 inet6 add 2021::100/64 up
  3. Add IP address (including IPv4 and IPv6 address) of all nodes in etc/hosts with details of ip address and hostname.                     
      4.   Run below command on all nodes
    sudo sysctl -w net.ipv6.conf.all.forwarding=1

      5. Install docker

            apt-get update && apt-get install -y docker.io

      6. Install Kubelet, Kubeadm adn Kubectl

          apt-get update && apt-get install -y apt-transport-https curl
          curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
          cat << EOF >/etc/apt/sources.list.d/kubernetes.list
             deb http://apt.kubernetes.io/ kubernetes-xenial main
           EOF

          apt-get update && apt-get install -y kubelet kubeadm kubectl

    7. Update cgroup-driver in all nodes
            nano /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
 
          Edit kubeadm.conf file and add below variable after the last Environment
           Environment="cgroup-driver=systemd/cgroup-driver=cgroupfs" 

       #Also add below configuration in all worker nodes to connect pods from master
        Environment="KUBELET_EXTRA_ARGS=--node-ip=<worker IP address>"

   8. Create kubeadmin-config.yaml

    #Example config file
        apiVersion: kubeadm.k8s.io/v1beta2
        featureGates:
          IPv6DualStack: true
        kind: ClusterConfiguration
        apiServer:
          extraArgs:
            advertise-address: <API Address>
        networking:
          dnsDomain: cluster.local
          podSubnet: "<IPV4 range>/16, <IPV6 range>/48"
          serviceSubnet: "<IPV4 range>/16,<IPV4 range>/112"  
        ----
        apiVersion: kubeadm.k8s.io/v1beta2
        kind: InitConfiguration
        localAPIEndpoint:
          advertiseAddress: <API Address>
          bindPort: 6443
        ---

     9.  Install K8s using created config file
            kubeadm init --config /home/kubeadm-config.yaml

   10. Install Calico

       Edit configuration and enable dual stack as explained under section 'Enable dualstack' in

        Kubectl apply -f calico.yaml

    11. Deploy and check your application Pods and see if they have received both IP addresses   :)