apiVersion: v1
kind: ServiceAccount
metadata:
  name: contosoba
  namespace: cerebral
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: contosoba-clusterrole
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: contosoba
  namespace: cerebral
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: contosoba-role
  namespace: cerebral
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: contosoba
  namespace: cerebral
---
apiVersion: v1
kind: Service
metadata:
  name: influxdb
  namespace: cerebral
spec:
  type: LoadBalancer
  selector:
    app: influxdb
  ports:
  - name: api
    port: 9999
    protocol: TCP
    targetPort: 9999
  - name: gui
    port: 8086
    protocol: TCP
    targetPort: 8086
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: influxdb-pv
  namespace: cerebral
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/var/lib/influxdb2" 
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: influxdb-pvc
  namespace: cerebral
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: influxdb
  namespace: cerebral
spec:
  serviceName: "influxdb"
  selector:
    matchLabels:
      app: influxdb
  template:
    metadata:
      labels:
        app: influxdb
    spec:
      serviceAccount: contosoba    
      containers:
      - name: influxdb
        image: influxdb:latest
        resources:
          limits:
            memory: "8Gi"
            cpu: 1
        ports:
        - name: api
          containerPort: 9999
        - name: gui
          containerPort: 8086
        volumeMounts:
        - name: influxdb-storage
          mountPath: /var/lib/influxdb2
      volumes:
      - name: influxdb-storage
        persistentVolumeClaim:
          claimName: influxdb-pvc