Deploy elastic search to infrastructure node in Open Shift - unix1998/technical_notes GitHub Wiki

deploy Elasticsearch as a containerized application on OpenShift and ensure it runs on infrastructure nodes by using labels and node selectors. Here's a step-by-step guide to help you achieve this:

Steps to Deploy Elasticsearch on OpenShift Infrastructure Nodes

  1. Label the Infrastructure Nodes
  2. Create Elasticsearch Deployment with Node Selector

Step 1: Label the Infrastructure Nodes

First, you need to label your infrastructure nodes to differentiate them from the worker nodes. Use the oc command to label the nodes.

Identify the nodes you want to label as infrastructure nodes:

oc get nodes

Label the nodes accordingly. For example, if you have nodes named infra-node1 and infra-node2, label them as follows:

oc label node infra-node1 node-role.kubernetes.io/infra=true
oc label node infra-node2 node-role.kubernetes.io/infra=true

Step 2: Create Elasticsearch Deployment with Node Selector

Now, create a Deployment or StatefulSet for Elasticsearch and use a node selector to ensure it gets scheduled on the infrastructure nodes.

Here is an example of a Deployment YAML file for Elasticsearch that uses a node selector:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: elasticsearch
  namespace: logging
spec:
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      nodeSelector:
        node-role.kubernetes.io/infra: "true"
      containers:
      - name: elasticsearch
        image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
        ports:
        - containerPort: 9200
        - containerPort: 9300
        env:
        - name: discovery.type
          value: single-node
        volumeMounts:
        - name: es-data
          mountPath: /usr/share/elasticsearch/data
      volumes:
      - name: es-data
        persistentVolumeClaim:
          claimName: es-data-pvc

Create a PersistentVolumeClaim (PVC) for Elasticsearch data:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: es-data-pvc
  namespace: logging
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi

Apply the PVC:

oc apply -f es-pvc.yaml

Then apply the Deployment:

oc apply -f elasticsearch-deployment.yaml

Summary

  1. Label the Infrastructure Nodes: Use oc label node to label the nodes you want to use for Elasticsearch.
  2. Deploy Elasticsearch: Create a Deployment (or StatefulSet) with a node selector to ensure Elasticsearch pods are scheduled on the labeled infrastructure nodes.

This approach ensures that Elasticsearch runs on your designated infrastructure nodes, keeping it separate from application workloads and providing better resource isolation and management.