How to deploy logstash with persistent volume on kubernetes?
Asked Answered
L

1

0

Using GKE to deploy logstash by statefulset kind with pvc. Also need to install an output plugin.

When don't use while true; do sleep 1000; done; in container's command args, it can't deploy with pvc successfully.

The pod will cause CrashLoopBackOff error.

  Normal   Created                 13s (x2 over 14s)  kubelet                  Created container logstash
  Normal   Started                 13s (x2 over 13s)  kubelet                  Started container logstash
  Warning  BackOff                 11s (x2 over 12s)  kubelet                  Back-off restarting failed container

From here I found it can try to add sleep. So the statefulset with pvc can deploy successfully.

But when check its logs will find:

/bin/sh: bin/logstash-plugin: No such file or directory
/bin/sh: bin/logstash: No such file or directory

How to do it in a good way to start container to install an logstash output plugin?

The whole manifest file:

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: logstash-to-gcs
  namespace: logging
spec:
  serviceName: "logstash"
  selector:
    matchLabels:
      app: logstash
  updateStrategy:
    type: RollingUpdate
  replicas: 3
  template:
    metadata:
      labels:
        app: logstash
    spec:
      containers:
      - name: logstash
        image: docker.elastic.co/logstash/logstash:7.10.0
        resources:
          limits:
            memory: 2Gi
        ports:
          - containerPort: 5044
        volumeMounts:
          - name: config-volume
            mountPath: /usr/share/logstash/config
          - name: logstash-pipeline-volume
            mountPath: /usr/share/logstash/pipeline
          - name: logstash-data
            mountPath: /usr/share/logstash
        command: ["/bin/sh","-c"]
        args:
          - bin/logstash-plugin install logstash-output-google_cloud_storage;
            bin/logstash -f /usr/share/logstash/pipeline/logstash.conf;
            while true; do sleep 1000; done;
      volumes:
        - name: config-volume
          configMap:
            name: logstash-configmap
            items:
              - key: logstash.yml
                path: logstash.yml
        - name: logstash-pipeline-volume
          configMap:
            name: logstash-configmap
            items:
              - key: logstash.conf
                path: logstash.conf
  volumeClaimTemplates:
  - metadata:
      name: logstash-data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
Lizethlizette answered 13/12, 2020 at 13:12 Comment(0)
K
0

For my containers I have a script I have ran on Container Deployments and it works to install the plugins and then run logstash. Post Arg> sh /usr/share/logstash/config/plugins.sh

#!binbash

echo running post install scripts for plugins..;
logstash-plugin install logstash-filter-sentimentalizer
logstash-plugin install logstash-input-mysql
echo finished post install scripts for plugins..;
sleep 1
exec logstash 
Koerner answered 6/4, 2021 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.