简体   繁体   English

Amazon EKS (NFS) 到 Kubernetes pod。 无法挂载卷

[英]Amazon EKS (NFS) to Kubernetes pod. Can't mount volume

I'm working on attaching Amazon EKS (NFS) to Kubernetes pod using terraform.我正在使用 terraform 将 Amazon EKS (NFS) 附加到 Kubernetes pod。

Everything runs without an error and is created:一切运行都没有错误并被创建:

  • Pod victoriametrics Pod victoriametrics
  • Storage Classes存储类
  • Persistent Volumes持久卷
  • Persistent Volume Claims持久卷声明

However, the volume victoriametrics-data doesn't attach to the pod.但是,卷victoriametrics-data不会附加到 pod。 Anyway, I can't see one in the pod's shell.无论如何,我在 pod 的外壳中看不到一个。 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

You need to use the persistent volume claim that you have created instead of emptyDir in your deployment:您需要在部署中使用您创建的持久卷声明而不是emptyDir

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM