Git Product home page Git Product logo

kubernetes-elasticsearch's Introduction

Elasticsearch on K8S

We are going to setup a fully redundant and highly available elasticsearch cluster on kubernetes.

Environment

Role IP DNS name OS RAM CPU
Load Balancer 10.132.132.100 - Ubuntu server 20.04 LTS 8G 8
Master 10.132.132.101 kmaster1 Ubuntu server 20.04 LTS 8G 8
Master 10.132.132.102 kmaster2 Ubuntu server 20.04 LTS 8G 8
Worker 10.132.132.103 kworker1 Ubuntu server 20.04 LTS 8G 8
Worker 10.132.132.104 kworker2 Ubuntu server 20.04 LTS 8G 8
Nignx Load Balancer 10.132.160.227 Ubuntu server 20.04 LTS

Approach

  • This Implementation is based on multiple Virtual Machines
  • Deploying elasticsearch using kubernetes statefulset
  • Persistent Volumes : LOCAL
  • Recommended Persistent Volume in cloud environment: awsElasticBlockStore
  • Recommended Persistent Volume in on-premise environment: glusterfs
  • NFS is not recommended for elasticsearch due to performance issues !

Design Overview

overview

Persistent Volume

Picture1

Services

Picture2

Set up load balancer node

Set up load balancer node

  apt update && apt install -y haproxy

Configure haproxy

Append the below lines to /etc/haproxy/haproxy.cfg

frontend kubernetes-frontend
    bind 10.132.132.100:6443
    mode tcp
    option tcplog
    default_backend kubernetes-backend

backend kubernetes-backend
    mode tcp
    option tcp-check
    balance roundrobin
    server kmaster1 10.132.132.101:6443 check fall 3 rise 2
    server kmaster2 10.132.132.102:6443 check fall 3 rise 2

On all kubernetes nodes (kmaster1, kmaster2, kworker1, kworker2)

Update sysctl settings 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
sysctl --system

Install docker engine

{
apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
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=5:19.03.10~3-0~ubuntu-focal containerd.io
}

Add Apt repository

{
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
}

Install Kubernetes components

apt update && apt install -y kubeadm=1.19.2-00 kubelet=1.19.2-00 kubectl=1.19.2-00

On master node (kmaster1)

Initialize Kubernetes Cluster

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

Deploy Calico network

kubectl --kubeconfig=/etc/kubernetes/admin.conf create -f https://docs.projectcalico.org/v3.15/manifests/calico.yaml

Join other nodes to the cluster (kmaster2 & kworker1 & kworker2)

Downloading kube config to your local machine

mkdir ~/.kube
scp [email protected]:/etc/kubernetes/admin.conf ~/.kube/config

Setup Nginx as the simulated cloud Load Balancer

Download and install Nginx

apt install nginx

create a site in nginx

vi /etc/ngin/sites-available/mysite

upstream elasticsearch {
 server 10.132.132.101:30000;
 server 10.132.132.102:30000;
 server 10.132.132.103:30000;
 server 10.132.132.104:30000;
}

server {
listen 9200 ssl;
server_name domain_name;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;    

location / {
  proxy_pass http://elasticsearch;
  auth_basic "Restricted Content";
  auth_basic_user_file /etc/nginx/.htpasswd;
    }
}

Deploy Elasticsearch using Helm

First install helm and then download elasticsearch helm package

wget https://helm.elastic.co/helm/elasticsearch/elasticsearch-7.5.2.tgz

unzip the downloaded package

tar -xvf elasticsearch-7.5.2.tgz

Edit the "values.yaml" file

>> clusterName: "picnic"

>> replicas: 2

>> minimumMasterNodes: 1

>> resources:
    requests:
        cpu: "1000m"
        memory: "2Gi"
    limits:
        cpu: "1000m"
        memory: "2Gi"

>> volumeClaimTemplate:
    accessModes: [ "ReadWriteOnce" ]
    storageClassName: local-storage
    resources:
        requests:
         storage: 5Gi

>> persistence:
        enabled: true

>> service:
    labels: {}
    labelsHeadless: {}
    type: LoadBalancer
    nodePort: "30000"
    annotations: {}
    httpPortName: http
    transportPortName: transport

Create the persistent volume manifest

  • download the manifest from the provided files

  • deploy the Persistent Volume manifest

      kubectl apply -f elasticsearch-pv.yaml
    

Install Elasticsearch using helm

helm install els elaelasticsearch-7.5.2.tgz -f values.yaml

Access the app

Authors

kubernetes-elasticsearch's People

Contributors

mozart4242 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.