kubernetes 重新启动时,K3s上的Nexus无法持久保存用户和数据

ui7jx7zq  于 2022-11-21  发布在  Kubernetes
关注(0)|答案(1)|浏览(143)

我已经在K3S raspberry pi cluster nexus上安装了以下设置,用于学习kubernetes。首先,我创建了一个StatefulSet:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nexus
  namespace: dev-ops
spec:
  serviceName: "nexus"
  replicas: 1
  selector:
    matchLabels:
      app: nexus-server
  template:
      metadata:
        labels:
          app: nexus-server
      spec:
        containers:
        - name: nexus
          image: klo2k/nexus3:latest
          env:
          - name: MAX_HEAP
            value: "800m"
          - name: MIN_HEAP
            value: "300m"
          resources:
            limits:
              memory: "4Gi"
              cpu: "1000m"
            requests:
              memory: "2Gi"
              cpu: "500m"
          ports:
            - containerPort: 8081
          volumeMounts:
            - name: nexusstorage
              mountPath: /sonatype-work
        volumes:
            - name: nexusstorage
              persistentVolumeClaim:
                claimName: nexusstorage

储存类别

apiVersion: storage.k8s.io/v1   
kind: StorageClass   
metadata:   
  name: nexusstorage 
provisioner: driver.longhorn.io
allowVolumeExpansion: true
reclaimPolicy: Delete
volumeBindingMode: Immediate
parameters:
  numberOfReplicas: "3"
  staleReplicaTimeout: "30"
  fsType: "ext4"
  diskSelector: "ssd"
  nodeSelector: "ssd"

聚氯乙烯

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nexusstorage
  namespace: dev-ops
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: nexusstorage
  resources:
    requests:
      storage: 50Gi

服务

apiVersion: v1
kind: Service
metadata:
  name: nexus-server
  namespace: dev-ops
  annotations:
      prometheus.io/scrape: 'true'
      prometheus.io/path:   /
      prometheus.io/port:   '8081'
spec:
  selector: 
    app: nexus-server
  type: LoadBalancer
  ports:
    - port: 8081
      targetPort: 8081
      nodePort: 32000

这个设置将旋转Nexus,但如果我重新启动Pod,数据将不会持续,我必须从头开始创建所有的设置和用户。
我在这件案子里漏掉了什么?

更新

我让它工作了,nexus需要目录的挂载权限。工作的StatefulSet看起来如下

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nexus
  namespace: dev-ops
spec:
  serviceName: "nexus"
  replicas: 1
  selector:
    matchLabels:
      app: nexus-server
  template:
      metadata:
        labels:
          app: nexus-server
      spec:
        securityContext:
          runAsUser: 200
          runAsGroup: 200
          fsGroup: 200
        containers:
        - name: nexus
          image: klo2k/nexus3:latest
          env:
          - name: MAX_HEAP
            value: "800m"
          - name: MIN_HEAP
            value: "300m"
          resources:
            limits:
              memory: "4Gi"
              cpu: "1000m"
            requests:
              memory: "2Gi"
              cpu: "500m"
          ports:
            - containerPort: 8081
          volumeMounts:
            - name: nexus-storage
              mountPath: /nexus-data
        volumes:
            - name: nexus-storage
              persistentVolumeClaim:
                claimName: nexus-storage

使其工作的重要代码片段

securityContext:
          runAsUser: 200
          runAsGroup: 200
          fsGroup: 200
yyyllmsg

yyyllmsg1#

我不熟悉该映像,虽然checking dockerhub,但他们提到使用类似于Sonatype的Dockerfile。
这是存储数据的默认路径(他们设置了这个env var,然后声明了一个VOLUME)。
接着您的最后一条评论,让我们尝试将其挂载到/opt/sonatype/sonatype-work/nexus 3中...
在statefulset中,将volumeMounts更改为:

volumeMounts:
        - name: nexusstorage
          mountPath: /nexus-data
        - name: nexusstorage
          mountPath: /opt/sonatype/sonatype-work/nexus3
    volumes:
      - name: nexusstorage
        persistentVolumeClaim:
          claimName: nexusstorage

虽然第二个volumeMount条目应该是不必要的,据我所知。也许是你的存储提供商出了问题?
您确定您的PVC是可写的吗?恢复到初始配置,输入您的pod(kubectl exec -it)并尝试在PVC的根目录下写入文件。

相关问题