Deploying InfluxDB on Kubernetes with NFS & Auto Setup

Kubernetes 환경에서 InfluxDB를 보다 안정적이고 자동화된 방식으로 운영하고자 할 때, NFS 기반 퍼시스턴트 스토리지를 활용하면 백업과 데이터 지속성이 향상됩니다. 이 문서에서는 Persistent Volume 구성부터 StatefulSet 배포, 초기 사용자 세팅까지 모든 단계를 다룹니다.


📦 1. Define PersistentVolume and PersistentVolumeClaim

InfluxDB 데이터를 저장할 디스크를 NFS를 통해 연결합니다.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: db-influxdb-pv
  labels:
    type: nfs
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: 192.168.0.99
    path: /mnt/influxdb
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: db-influxdb-pvc
spec:
  storageClassName: ""
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  selector:
    matchExpressions:
      - key: type
        operator: In
        values:
          - nfs
  • NFS Server: 192.168.0.99
  • Path: /mnt/influxdb

🧱 2. Deploy InfluxDB using StatefulSet

InfluxDB를 컨테이너 형태로 배포하고 위에서 설정한 PVC를 마운트합니다.

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: db-influxdb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: db-influxdb
  template:
    metadata:
      labels:
        app: db-influxdb
    spec:
      containers:
        - name: db-influxdb
          image: quay.io/influxdb/influxdb:v2.0.3
          ports:
            - containerPort: 8086
            - containerPort: 9999
          volumeMounts:
            - name: var-lib-influxdb
              mountPath: /root/.influxdbv2
      volumes:
        - name: var-lib-influxdb
          persistentVolumeClaim:
            claimName: db-influxdb-pvc
  • 8086: GUI 및 API 포트
  • 9999: 내부 API 포트

🌐 3. Create Service for InfluxDB Access

InfluxDB를 외부에서 접근하기 위한 NodePort Service를 설정합니다.

apiVersion: v1
kind: Service
metadata:
  name: influxdb
spec:
  type: NodePort
  selector:
    app: db-influxdb
  ports:
    - port: 8086
      targetPort: 8086
      nodePort: 30086  # Optional: set your desired port

이제 브라우저에서 http://<node-ip>:30086으로 접속 가능하게 됩니다.


⚙️ 4. Auto Setup with Kubernetes Job

InfluxDB는 초기 실행 시 계정, 버킷, 토큰을 CLI를 통해 설정해야 합니다. 이를 Job으로 자동화하여 수동 입력 없이 설정을 완료할 수 있습니다.

apiVersion: batch/v1
kind: Job
metadata:
  name: db-influxdb-setup
spec:
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: create-credentials
          image: quay.io/influxdb/influxdb:v2.0.3
          command: ["influx"]
          args:
            - setup
            - --host
            - http://influxdb.네임스페이스:8086
            - --bucket
            - my-bucket
            - --org
            - my-org
            - --username
            - my-user
            - --password
            - my-password
            - --token
            - my-token
            - --force

Replace 네임스페이스 and credentials with your own values.


✅ Summary (정리)

  • ✅ NFS를 이용한 외부 볼륨으로 안정적 데이터 저장
  • ✅ StatefulSet으로 관리되는 InfluxDB 컨테이너 배포
  • ✅ Job을 활용한 사용자 초기 설정 자동화

이 구성을 기반으로 InfluxDB + Telegraf + Grafana 환경까지 확장할 수 있습니다. Kubernetes 환경에서 시계열 데이터 저장소가 필요한 경우 강력한 솔루션이 될 것입니다.

Leave a Comment