Skip to content

InfluxDB in Kubernetes

namespace.yaml

yaml
apiVersion: v1
kind: Namespace
metadata:
  name: common

deployment.yaml

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: influxdb
  namespace: common
  labels:
    app: influxdb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: influxdb
  template:
    metadata:
      labels:
        app: influxdb
    spec:
      containers:
        - name: influxdb
          image: influxdb:2.7.11-alpine
          ports:
            - containerPort: 8086
              name: influxdb
              hostPort: 8086
          env:
            - name: INFLUXDB_DB
              value: "db0"
            - name: INFLUXDB_ADMIN_USER
              valueFrom:
                configMapKeyRef:
                  name: influxdb-config
                  key: ADMIN_USER
            - name: INFLUXDB_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: influxdb-secrets
                  key: ADMIN_PASSWORD
          volumeMounts:
            - name: influxdb-data
              mountPath: /var/lib/influxdb2
      volumes:
        - name: influxdb-data
          persistentVolumeClaim:
            claimName: influxdb-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: influxdb
  namespace: common
  labels:
    app: influxdb
spec:
  ports:
    - port: 8086
  selector:
    app: influxdb
  clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: influxdb-pvc
  namespace: common
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: influxdb-pv-volume
  namespace: common
  labels:
    type: local
spec:
  storageClassName: local
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/root/kubernetes/common/influxdb/influxdb_pv_volume" # 此处填写正确的目录
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: influxdb-config
  namespace: common
  labels:
    app: influxdb
data:
  ADMIN_USER: "admin"
---
apiVersion: v1
kind: Secret
metadata:
  name: influxdb-secrets
  namespace: common
  annotations:
    kubesphere.io/creator: admin
  labels:
    app: influxdb
type: Opaque
data:
  ADMIN_PASSWORD: "" # 在这里配置你的ADMIN_PASSWORD