Kubernetes - 为数据持久化挂载卷

时间:2020-12-28 15:42:04

标签: kubernetes

出于培训目的并了解卷的工作原理,我正在尝试将卷安装到 mysql 应用程序以实现数据持久性。这是我的资源:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
  namespace: ex3
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - image: mysql:5.6
          name: mysql
          env:
            - name: MYSQL_DATABASE
              valueFrom:
                configMapKeyRef:
                  name: "wordpress-mysql"
                  key: db_name
            - name: MYSQL_USER
              valueFrom:
                configMapKeyRef:
                  name: "wordpress-mysql"
                  key: db_user
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: "mysql"
                  key: db_password
            - name: MYSQL_RANDOM_ROOT_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: "wordpress-mysql"
                  key: db_random_root_password
          ports:
            - containerPort: 3306
              protocol: TCP
          volumeMounts:
            - mountPath: /var/lib/mysql
              name: data-volume
      volumes:
      - name: data-volume
        hostPath:
          path: /var/data
          type: Directory

问题是,我的 Pod 仍处于 Container-Creating 状态。
kubectl get pods -n ex3

NAME                         READY   STATUS              RESTARTS   AGE
mysql-7f56bffdbb-l8hgq       0/1     ContainerCreating   0          56s

kubectl describe pod mysql-7f56bffdbb-l8hgq -n ex3

Events:
  Type     Reason       Age               From               Message
  ----     ------       ----              ----               -------
  Normal   Scheduled    73s               default-scheduler  Successfully assigned ex3/mysql-7f56bffdbb-l8hgq to worker-1
  Warning  FailedMount  9s (x8 over 73s)  kubelet            MountVolume.SetUp failed for volume "data-volume" : hostPath type check failed: /var/data is not a directory

我在我的一个节点中创建了一个 var/data 文件夹,所以我不明白为什么会出现这个问题:/var/data is not a directory

0 个答案:

没有答案