LearnITGuide.net

Latest Article

This tutorial post will help you with Step by Step procedure to configure HA Cluster using KeepAlived on Ubuntu with Floating IP.

If you are new to kubernetes and want to learn about kubernetes from basics, Refer the below links and also you can checkout all tutorial videos for free on YouTube and do subscribe for more free videos.

What is Kubernetes - Learn Kubernetes from Basics
How to Install Kubernetes on Linux (RedHat / CentOS)
How to Install Kubernetes On Ubuntu 16.04 LTS
How to Create Kubernetes Deployment, Services & Pods Using Kubectl
How to Create Kubernetes YAML for Deployment, Service & Pods
Kubernetes Volumes Explained with Examples
Kubernetes Persistent Volumes and Claims Explained

Also You can Watch this Entire Tutorial video on our YouTube Channel.

HA Cluster Architecture Lab Setup:

Configure HA Cluster using KeepAliveD on Ubuntu
Web Servers - 2 Nos.
HaProxy LB - 2 Nos.
Note: All nodes are installed with Ubuntu 20.04. 

Prerequisites:

1. Users must have root or sudo access to perform administrative tasks. (switchover to root user to avoid unnecessary permission issues).

2. (OPTIONAL )- Make an entry of each host in /etc/hosts file for name resolution on all nodes as below or configure it on DNS if you have DNS Server.

$ cat /etc/hosts
192.168.2.11  haproxy-lb1
192.168.2.12  haproxy-lb2
192.168.2.13  apache-web1
192.168.2.14  apache-web2

3. Make sure all the nodes are reachable between each others.

4. Internet must be enabled on all nodes, because we will be using official repositories to download and install required packages to setup keepalived linux cluster.

Steps Involved to Create Linux Cluster using KeepAlived.

On All Web Servers:

1. Install Apache2

2. Configure Apache2 Web Servers

3. Start and Enable Apache2 Service.

On All HAProxy Servers:

4. Install HAProxy

5. Setup HAProxy with Frontend and Backend Configuration.

6. Start and Enable HAProxy Service.

On All HAProxy Servers:

7. Install KeepAlived

8. Configure KeepAlived

9. Start and Enable KeepAlived Service.


Let's Get Started.

On All Web Servers (IP: 192.168.2.13 and 192.168.2.14):

1. Install Apache2

Use apt-get command to install Apache2 package as below.

# sudo apt update && sudo apt install -y apache2

2. Configure Apache2

Once Apache2 package is installed, configure the document root and modify the configuration if required.

I just modify the exsiting default index.html with sample content as below.

sudo echo "Test Data" > /var/www/html/index.html

3. Start and Enable Apache2 Service.

Use systemtctl to enable and start Apache2 service.

sudo systemctl enable apache2
sudo systemctl start apache2

On All HAProxy Servers (IP: 192.168.2.11 and 192.168.2.12):

1. Install HAProxy

[ads-post]

Use apt-get command to install HAProxy package as below.

# sudo apt update && sudo apt install -y haproxy

2. Setup HAProxy with Frontend and Backend Configuration

Once HAProxy package is installed, edit the main configuration file /etc/haproxy/haproxy.conf with below frontend and backend configuration. Replace the Web Server IP Address with your Web Servers and even you can more webservers if you have any.

frontend myweb
        bind *:80
        option tcplog
        mode tcp
        default_backend web-servers
backend web-servers
        mode tcp
        balance roundrobin
        option tcp-check
        server web1 192.168.2.13:80 check fall 3 rise 2
        server web2 192.168.2.14:80 check fall 3 rise 2

3. Start and Enable HAProxy.

Use systemctl command to start and enable the HAProxy service as below.

# systemctl restart haproxy
# systemctl enable haproxy

4. Install KeepAlived

Use apt-get command to install KeepAlived package as below.

# sudo apt update && sudo apt install -y keepalived

5. Configure KeepAlived

Once KeepAlived package is installed, create the main configuration file /etc/keepalived/keepalived.conf with below configuration. Replace the Highlighted values as per your configurations.

On Haproxy LB1 (192.168.2.11)

# Define the script used to check if haproxy is still working

vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 2
    weight 2
}
# Configuation for the virtual interface
vrrp_instance VI_1 {
    interface enp0s8
    state MASTER # set this to BACKUP on the other machine
    priority 101        # set this to 100 on the other machine
    virtual_router_id 51
    smtp_alert          # Activate email notifications
    authentication {
        auth_type AH
        auth_pass myPassw0rd      # Set this to some secret phrase
    }
    # The virtual ip address shared between the two loadbalancers
    virtual_ipaddress {
        192.168.2.100
    }
    # Use the script above to check if we should fail over
    track_script {
        chk_haproxy
    }
}
On Haproxy LB2 (192.168.2.12)

# Define the script used to check if haproxy is still working

vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 2
    weight 2
}
# Configuation for the virtual interface
vrrp_instance VI_1 {
    interface enp0s8
    state BACKUP # set this to BACKUP on the other machine
    priority 100       # set this to 100 on the other machine
    virtual_router_id 51
    smtp_alert          # Activate email notifications
    authentication {
        auth_type AH
        auth_pass myPassw0rd      # Set this to some secret phrase
    }
    # The virtual ip address shared between the two loadbalancers
    virtual_ipaddress {
        192.168.2.100
    }
    # Use the script above to check if we should fail over
    track_script {
        chk_haproxy
    }
}
6. Start and Enable KeepAlived Service.

Use systemctl command to start and enable the KeepAlived service as below.

# systemctl restart keepalived
# systemctl enable keepalived

 7. Test your configurations.

Once the keepalived service is started, we could see an virtual ip address 192.168.2.100 is configured on primary HAProxy Server as shown in the image below. Use ifconfig or ip a command to list the configured address.

ipaddress command examples

Use any browser to access the web through browser using the ip http://192.168.2.100..

In order to test the floating ip failover, shutdown the haproxy lb1 server, this will configure the virtual ip to the other node automatically as below.

linux ipaddress commands

Once you bring up the haproxy lb1 server, virtual ip will be configured back to the primary server.

Thats all for this post.

Also You can Watch this Entire Tutorial video on our YouTube Channel.


Also refer below related articles and checkout all tutorial videos for free on youtube.

What is Kubernetes - Learn Kubernetes from Basics
How to Install Kubernetes on Linux (RedHat / CentOS)
How to Install Kubernetes On Ubuntu 16.04 LTS
How to Create Kubernetes Deployment, Services & Pods Using Kubectl
How to Create Kubernetes YAML for Deployment, Service & Pods
Kubernetes Volumes Explained with Examples
Kubernetes Persistent Volumes and Claims Explained

Keep practicing and have fun. Leave your comments if any.
Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.

Incoming searches: configure ha cluster using keepalived on ubuntu, configure ha cluster on ubuntu, configure ha cluster linux, configure ha cluster using keepalived floating ip, install keepalived on ubuntu, setup ha cluster using keepalived, install keepalived on linux, create ha cluster on ubuntu, create linux cluster using keepalived, create linux failover cluster, create linux ha cluster on ubuntu 

This tutorial post provides you the step by step procedure to setup kubernetes cluster with multi master nodes on Ubuntu using Kubeadm.

If you are new to kubernetes and want to learn about kubernetes from basics, Refer the below links and also you can checkout all tutorial videos for free on YouTube and do subscribe for more free videos.

What is Kubernetes - Learn Kubernetes from Basics
How to Install Kubernetes on Linux (RedHat / CentOS)
How to Install Kubernetes On Ubuntu 16.04 LTS
How to Create Kubernetes Deployment, Services & Pods Using Kubectl
How to Create Kubernetes YAML for Deployment, Service & Pods
Kubernetes Volumes Explained with Examples
Kubernetes Persistent Volumes and Claims Explained

Also You can Watch this Entire Tutorial video on our YouTube Channel.

Kubernetes Multi Master Architecture Lab Setup:

Minimum 2 CPU's with 4Gb Memory is required.

Note: All nodes are installed with Ubuntu 20.04. You can add multiple worker nodes as you want and follow the steps given. Only due to my limitation and pricing, i used minimum worker node. Agenda of this tutorial is to have multi master node setup, since no need to worry about worker nodes.

Prerequisites:

1. Users must have root or sudo access to perform administrative tasks. (switchover to root user to avoid unnecessary permission issues).

2. (OPTIONAL )- Make an entry of each host in /etc/hosts file for name resolution on all nodes as below or configure it on DNS if you have DNS Server.

$ cat /etc/hosts
10.0.1.77 haproxy-lb
10.0.1.54 kubernetes-master1
10.0.1.252 kubernetes-master2
10.0.1.32 kubernetes-worker1

3. Make sure all the nodes are reachable between each others.

4. Internet must be enabled on all nodes, because we will be using official repositories to download and install required packages to setup kubernetes cluster.

Steps Involved to Create Kubernetes Cluster with Multi Master nodes.

On HAProxy Server:

1. Install HAProxy

2. Configure HAProxy

3. Start and Enable HAProxy.

On all kubernetes nodes:

4. Prerequisites Kubernetes Configurations

5. Enable Docker and Kubernetes Repository

6. Install kubernetes packages - kubeadm, kubelet and kubectl.

On Kubernetes Master Nodes - Anyone Node:

7. Initializing and Setting up Kubernetes Master Node.

8. Post Kubernetes Cluster Setup

9. Install Network add-on to enable the communication between the pods.

On Other Kubernetes Master Nodes:

10. Join all Kubernetes Master nodes

On Other Kubernetes Worker Nodes:

11. Join all Kubernetes Worker Nodes


Let's Get Started.


On HAProxy Server (IP: 10.0.1.77):

1. Install HAProxy

[ads-post]

Use apt-get command to install HAProxy package as below.

# apt update && apt install -y haproxy

2. Configure HAProxy

Once HAproxy is installed, configure HAProxy to forward the traffic across the kubernetes master nodes.

Edit the config file /etc/haproxy/haproxy.cfg to define the frontend and backend configuration and append the below config. Replace the IP Address with your HaProxy and Kubernetes Master Nodes.

frontend kubernetes
        bind 10.0.1.77:6443
        option tcplog
        mode tcp
        default_backend kubernetes-master-nodes
backend kubernetes-master-nodes
        mode tcp
        balance roundrobin
        option tcp-check
        server kubernetes-master1 10.0.1.54:6443 check fall 3 rise 2
        server kubernetes-master2 10.0.1.242:6443 check fall 3 rise 2

3. Start and Enable HAProxy.

Use systemctl command to start and enable the HAProxy service as below.

# systemctl restart haproxy
# systemctl enable haproxy

On all kubernetes nodes:

4. Prerequisitis Kubernetes Configurations

Kubernetes doesnt support "Swap". Disable swap on all kubernetes nodes and also to make it permanent, comment out the swap entry in /etc/fstab file as below.

# swapoff -a; sed -i '/swap/d' /etc/fstab

Allow sysctl to pass bridged traffic of IPv4 and IPv6 to iptables chains for Kubernetes networking.

cat >>/etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

5. Enable Docker and Kubernetes Repository

Before begin, we must update the Ubuntu repositories and install basic tools like apt-transport-https, curl and etc,.

# apt-get update && apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Once installation is completed, enable and install docker on all nodes.

# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# apt update && apt install -y docker-ce containerd.io

Afer docker installation, add kubernetes signing key and add kubernetes repository on all nodes.

# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
# echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list

6. Install kubernetes packages.

Use apt-get command to install kubeadm, kubelet and kubectl packages with specific version.. Very newer version 1.21.x, 1.22.x are not worked on Ubuntu 20.04.

# apt update && apt install -y kubeadm=1.20.0-00 kubelet=1.20.0-00 kubectl=1.20.0-00

Make sure kubelet service is running or not.

# systemctl status kubelet

On Kubernetes Master Nodes - Anyone Node (10.0.1.54):

7. Initializing and Setting up kubernetes master node.

Only on first kubernetes master node, Use "kubeadm" command to initialize the kubernetes cluster along with "--control-plane-endpoint", "apiserver-advertise-address" and "--pod-network-cidr" options. It is used to specify the control plane server IP Address, IP address for kubernetes cluster communication and range of networks for the pods respectively.

# kubeadm init --control-plane-endpoint="10.0.1.77:6443" --upload-certs --apiserver-advertise-address=10.0.1.54 --pod-network-cidr=192.168.0.0/16

Output Trimmed:

Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
Alternatively, if you are the root user, you can run:
  export KUBECONFIG=/etc/kubernetes/admin.conf
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of the control-plane node running the following command on each as root:
  kubeadm join 10.0.1.77:6443 --token pdrhap.w5ynabi9aa24l9cc \
    --discovery-token-ca-cert-hash sha256:ccdede9a044092b93b720f05b4172da8b10070f0fa4a56445b0a27bdc0d5eaba \
    --control-plane --certificate-key 4520073a1f14e58d48a1fb3515b6bac3be41cac89ed51561067783b1a24684ac

Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use
"kubeadm init phase upload-certs --upload-certs" to reload certs afterward.
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 10.0.1.77:6443 --token pdrhap.w5ynabi9aa24l9cc \
    --discovery-token-ca-cert-hash sha256:ccdede9a044092b93b720f05b4172da8b10070f0fa4a56445b0a27bdc0d5eaba

Once Kubernetes cluster initialization is completed, Copy the join token highlighted in yellow color to join any number of the control-plane node.

Copy the other join token highlighted in red color to any number of worker nodes.

Store it in a secure location, it may be required for you later.

8. Post Kubernetes Cluster Setup

To start using your cluster, you need to run the following as if you have logged in as regular user:

#  mkdir -p $HOME/.kube
#  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
#  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run the below, even I have logged in as root user:

#  export KUBECONFIG=/etc/kubernetes/admin.conf

9. Install Network add-on to enable the communication between the pods.

We have lot of network add-on available to enable the network communication with different functionality, Here I have used Calico network provider.

# kubectl create -f https://docs.projectcalico.org/v3.15/manifests/calico.yaml

10. Join all Other Kubernetes Master nodes:

Login into other kubernetes master nodes and use the join token of control plane (highlighted in yellow color).

# kubeadm join 10.0.1.77:6443 --token pdrhap.w5ynabi9aa24l9cc \
    --discovery-token-ca-cert-hash sha256:ccdede9a044092b93b720f05b4172da8b10070f0fa4a56445b0a27bdc0d5eaba \
    --control-plane --certificate-key 4520073a1f14e58d48a1fb3515b6bac3be41cac89ed51561067783b1a24684ac

Replace with your join token of master nodes.

11. Join all Kubernetes Worker Nodes:

Login into other kubernetes worker nodes and use the join token of worker nodes (highlighted in red color).

# kubeadm join 10.0.1.77:6443 --token pdrhap.w5ynabi9aa24l9cc \
    --discovery-token-ca-cert-hash sha256:ccdede9a044092b93b720f05b4172da8b10070f0fa4a56445b0a27bdc0d5eaba
Replace with your join token of worker nodes.

Once all done, verify the list of nodes been added to the kubernetes cluster using the below command.

# kubectl get nodes.

Also You can Watch this Entire Tutorial video on our YouTube Channel.


Also refer below related articles and checkout all tutorial videos for free on youtube.

What is Kubernetes - Learn Kubernetes from Basics
How to Install Kubernetes on Linux (RedHat / CentOS)
How to Install Kubernetes On Ubuntu 16.04 LTS
How to Create Kubernetes Deployment, Services & Pods Using Kubectl
How to Create Kubernetes YAML for Deployment, Service & Pods
Kubernetes Volumes Explained with Examples
Kubernetes Persistent Volumes and Claims Explained

Keep practicing and have fun. Leave your comments if any.
Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.

Incoming searches: kubernetes multi master setup, kubernetes multi master cluster setup ubuntu, kubernetes multi master setup with haproxy, kubernetes multi master cluster setup ubuntu 20, kubernetes multi master cluster, configure kubernetes multi master nodes, kubernetes multi master installation, setup ha kubernetes master, set up high-availability kubernetes masters, setup ha kubernetes cluster, multi master kubernetes setup, multi master kubernetes using kubeadm, multi master kubernetes ubuntu, install multi master kubernetes, multi master kubernetes architecture

This post will help you to get Best Kubernetes Scenario Based Interview Questions with Answers to Crack Kubernetes Interviews from the different sources, It will have all Scenario Based Kubernetes Interview Questions for Beginners, Intermediate and Advanced Experienced Candidates.


Answers of each Kubernetes Questions can be found here in the video along with explainations.


1. Let’s say a Kubernetes job should finish in 40 seconds, however on a rare occasion it takes 5 minutes, How can I make sure to stop the application if it exceeds more than 40 seconds?

2. How do you test a manifest without actually executing it?

3. How do you initiate a rollback for an application?

4. How do you package Kubernetes applications?

5. What are init containers?

6. What is node affinity and pod affinity?

7. How do you drain the traffic from a Pod during maintenance?

[ads-post]

8. I have one POD and inside 2 containers are running one is Nginx and another one is  wordpress So, how can access these 2 containers from the Browser with IP address?

9. If I have multiple containers running inside a pod, and I want to wait for a specific container to start before starting another one.

10. What is the impact of upgrading kubelet if we leave the pods on the worker node - will it break running pods? why?

11. How service that selects apps based on the label and has an externalIP?

12. Does the container restart When applying/updating the secret object (kubectl apply -f mysecret.yml)?  If not, how is the new password applied to the database?

13. How should you connect an app pod with a database pod?

14. How to configure a default ImagePullSecret for any deployment?

15. If you have a pod that is using a ConfigMap which you updated, and you want the container to be updated with those changes, what should you do?

Answers of each Kubernetes Questions can be found here in the video along with explainations.
"Kubernetes Scenario Based Interview Questions"


Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.
YouTube | Facebook | Twitter | Pinterest | Rss
incoming searches: kubernetes, kubernetes interview questions and answers, kubernetes interview questions, kubernetes interview, kubernetes questions and answers, kubernetes interview questions for experienced, kubernetes questions, kubernetes questions for interview, kubernetes interview questions with answers, kubernetes scenario based interview questions, kubernetes scenario based questions, scenario based kubernetes interview questions, scenario based kubernetes questions with answers

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget