使用minikube的Kubernetes持久卷

时间:2019-04-04 21:03:00

标签: kubernetes kubectl minikube

我一直在战斗,因为在持久创建卷的阶段,将我的k8s Pod设置在minikube单节点上。

即使我从kubernetes文档中复制/粘贴示例规范,该命令也总是以错误结尾:

$kubectl apply -f pv-volume.yml
  

错误:SchemaError(io.k8s.api.core.v1.ScaleIOVolumeSource):无效   对象没有其他属性

$cat pv-volume.yml
kind: PersistentVolume
apiVersion: v1
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"

当我使用本地卷时,我不知道为什么kubectl要求我在规范中指定ScaleIO

我在指定storagaClassNamestandard时遇到相同的错误

有什么问题的想法吗?

我的版本:

$minikube version
minikube version: v1.0.0

$kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:45:25Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}

2 个答案:

答案 0 :(得分:0)

在minikube中,默认情况下已经存在动态预配置器,您只需要使用该类创建持久卷声明即可。

C02W84XMHTD5:Downloads iahmad$ minikube start
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
Loading cached images from config file.
C02W84XMHTD5:Downloads iahmad$ kubectl get nodes
NAME       STATUS   ROLES    AGE   VERSION
minikube   Ready    master   4d    v1.10.0
C02W84XMHTD5:Downloads iahmad$ 
C02W84XMHTD5:Downloads iahmad$ kubectl get storageclasses.storage.k8s.io 
NAME                 PROVISIONER                AGE
standard (default)   k8s.io/minikube-hostpath   4d
C02W84XMHTD5:Downloads iahmad$ 
C02W84XMHTD5:Downloads iahmad$ 

因此,要保持数据持久性,您只需要批量声明并在kubernetes部署中使用它即可。

使用内置的minikube存储类的示例mysql批量声明。

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mysql-volumeclaim
  annotations:
    volume.beta.kubernetes.io/storage-class: standard
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

在mysql部署中的用法:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - image: mysql:5.6
          name: mysql
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql
                  key: password
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-volumeclaim

答案 1 :(得分:0)

我从一个错误到另一个错误,然后尝试创建另一个对象,例如机密和相同的问题。

然后

  • 我依次删除了kubectl,然后重新安装,
  • 我停止mikube并重新启动

似乎kubectl升级是解决方案的关键,1.10客户端版本正试图与1.14进行对话-API版本不匹配可以解释错误消息。似乎与minikube并没有真正的联系。

现在可以正常使用了,我实际上可以运行kube命令了