k8s: Statefulset with pvc templates and external pvc

  Kiến thức lập trình

I am trying to deploy my statefulset. The set contains 3 pvc templates and 1 externally managed PVC. The creation of the statefulset fails with the error shown below, I’m kind of lost what I am missing here.

Deployment method:

  • k8s version: 1.29.0
  • ArgoCD
  • Helm template

Deploying the statefulset returns the following error:

FailedCreate: create Pod myapp-0 in StatefulSet myapp failed error: Pod “myapp-0” is invalid: [spec.volumes[3].persistentVolumeClaim.claimName: Required value, spec.containers[1].volumeMounts[3].name: Not found: “external-pvc”]

Using argoCD I can see the my helm template deployed the desired manifest. I do see that the pvc has successfully deployed within the namespace (see manifest below):

Statefulset

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app.kubernetes.io/instance: myapp
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: myapp
    app.kubernetes.io/version: 1.16.0
    argocd.argoproj.io/instance: myapp
    helm.sh/chart: myapp-0.1.6
  name: myapp
  namespace: mynamespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/instance: myapp
      app.kubernetes.io/name: myapp
  template:
    metadata:
      labels:
        app.kubernetes.io/instance: myapp
        app.kubernetes.io/name: myapp
    spec:
      containers:
          image: 'lscr.io/linuxserver/myapp:latest'
          imagePullPolicy: IfNotPresent
          name: myapp
          securityContext: {}
          volumeMounts:
            - mountPath: /config
              name: myapp-config
            - mountPath: /mount01
              name: myapp-01
            - mountPath: /mount02
              name: myapp-02
            - mountPath: /mount03
              name: external-pvc
      securityContext: {}
      volumes:
        - name: myapp-config
          persistentVolumeClaim:
            claimName: myapp-config
        - name: myapp-01
          persistentVolumeClaim:
            claimname: myapp-01
        - name: myapp-02
          persistentVolumeClaim:
            claimname: myapp-02
        - name: external-pvc
          persistentVolumeClaim:
            claimname: external-pvc
  volumeClaimTemplates:
    - metadata:
        name: myapp-config
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
        storageClassName: nfs-csi-applications
        volumeName: pv-myapp-config
    - metadata:
        name: myapp-01
      spec:
        accessModes:
          - ReadWriteMany
        resources:
          requests:
            storage: 1Ti
        storageClassName: nfs-csi-applications
        volumeName: pv-myapp-01
    - metadata:
        name: myapp-02
      spec:
        accessModes:
          - ReadWriteMany
        resources:
          requests:
            storage: 15Ti
        storageClassName: nfs-csi-applications
        volumeName: myapp-02

external-pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  finalizers:
    - kubernetes.io/pvc-protection
  name: external-pvc
  namespace: mynamespace
  resourceVersion: '1314916'
  uid: 74972df6-ad14-49ab-afd9-dc8dffa0755a
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Ti
  storageClassName: nfs-csi-applications
  volumeMode: Filesystem
  volumeName: pv-external-pvc
status:
  accessModes:
    - ReadWriteOnce
    - ReadWriteMany
  capacity:
    storage: 2Ti
  phase: Bound

LEAVE A COMMENT