Home > other >  Amazon EKS (NFS) to Kubernetes pod. Can't mount volume
Amazon EKS (NFS) to Kubernetes pod. Can't mount volume

Time:11-11

I'm working on attaching Amazon EKS (NFS) to Kubernetes pod using terraform.

Everything runs without an error and is created:

  • Pod victoriametrics
  • Storage Classes
  • Persistent Volumes
  • Persistent Volume Claims

However, the volume victoriametrics-data doesn't attach to the pod. Anyway, I can't see one in the pod's shell. Could someone be so kind to help me understand where I'm wrong, please?

I have cut some unimportant code for the question to get code shorted.

resource "kubernetes_deployment" "victoriametrics" {
...
      spec {
        container {
          image = var.image
          name  = var.name
          ...
          volume_mount {
              mount_path        = "/data"
              mount_propagation = "None"
              name              = "victoriametrics-data"
              read_only         = false
            }
        }

        volume {
            name = "victoriametrics-data"
        }

      }
    }
...

}
resource "kubernetes_csi_driver" "efs" {
  metadata {
    name = "${local.cluster_name}-${local.namespace}"
    annotations = {
      name = "For store data of ${local.namespace}."
    }
  }
  spec {
    attach_required        = true
    pod_info_on_mount      = true
    volume_lifecycle_modes = ["Persistent"]
  }
}
resource "kubernetes_storage_class" "efs" {
  metadata {
    name = "efs-sc"
  }
  storage_provisioner = kubernetes_csi_driver.efs.id
  reclaim_policy      = "Retain"
  mount_options       = ["file_mode=0700", "dir_mode=0777", "mfsymlinks", "uid=1000", "gid=1000", "nobrl", "cache=none"]
}
resource "kubernetes_persistent_volume" "victoriametrics" {
  metadata {
    name = "${local.cluster_name}-${local.namespace}"
  }
  spec {
    storage_class_name               = "efs-sc"
    persistent_volume_reclaim_policy = "Retain"
    volume_mode                      = "Filesystem"
    access_modes                     = ["ReadWriteMany"]
    capacity = {
      storage = var.size_of_persistent_volume_claim
    }
    persistent_volume_source {
      nfs {
        path   = "/"
        server = local.eks_iput_target
      }
    }
  }
}
resource "kubernetes_persistent_volume_claim" "victoriametrics" {
  metadata {
    name      = local.name_persistent_volume_claim
    namespace = local.namespace
  }
  spec {
    access_modes       = ["ReadWriteMany"]
    storage_class_name = "efs-sc"
    resources {
      requests = {
        storage = var.size_of_persistent_volume_claim
      }
    }
    volume_name = kubernetes_persistent_volume.victoriametrics.metadata.0.name
  }
}
kind: Deployment
apiVersion: apps/v1
metadata:
  name: victoriametrics
  namespace: victoriametrics
  labels:
    k8s-app: victoriametrics
    purpose: victoriametrics
  annotations:
    deployment.kubernetes.io/revision: '1'
    name: >-
      VictoriaMetrics - The High Performance Open Source Time Series Database &
      Monitoring Solution.
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: victoriametrics
      purpose: victoriametrics
  template:
    metadata:
      name: victoriametrics
      creationTimestamp: null
      labels:
        k8s-app: victoriametrics
        purpose: victoriametrics
      annotations:
        name: >-
          VictoriaMetrics - The High Performance Open Source Time Series
          Database & Monitoring Solution.
    spec:
      containers:
        - name: victoriametrics
          image: 714154805721.dkr.ecr.us-east-1.amazonaws.com/victoriametrics:v1.68.0
          ports:
            - containerPort: 8428
              protocol: TCP
            - containerPort: 2003
              protocol: TCP
            - containerPort: 2003
              protocol: UDP
          volumeMounts:
            - mountPath: /data
              name: victoriametrics-data
            - mountPath: /var/log
              name: varlog
          env:
            - name: Name
              value: victoriametrics
          resources:
            limits:
              cpu: '1'
              memory: 1Gi
            requests:
              cpu: 500m
              memory: 1Gi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      volumes:
      - name: victoriametrics-data
        emptyDir: {}
      - name: varlog
        emptyDir: {}    
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      automountServiceAccountToken: true
      shareProcessNamespace: false
      securityContext: {}
      schedulerName: default-scheduler
      tolerations:
        - key: k8s-app
          operator: Equal
          value: victoriametrics
          effect: NoSchedule
      enableServiceLinks: true
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  minReadySeconds: 15
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 300

CodePudding user response:

You need to use the persistent volume claim that you have created instead of emptyDir in your deployment:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: victoriametrics
...
  volumes:
  - name: victoriametrics-data
      persistentVolumeClaim:
        claimName: <value of local.name_persistent_volume_claim>
  • Related