简体   繁体   English

Kubernetes持久体积与迷你管

[英]Kubernetes persistent volume with minikube

I'm fighting since many hours setting my k8s pods on my minikube single node, at persistent volume creation stage. 我在很长时间内在我的minikube单节点上设置我的k8s pod,并在持续的音量创建阶段进行战斗。

This command always ends with error, even if I copy/paste the example spec from kubernetes documentation : 即使我从kubernetes文档中复制/粘贴示例规范,此命令也始终以错误结束:

$kubectl apply -f pv-volume.yml

error: SchemaError(io.k8s.api.core.v1.ScaleIOVolumeSource): invalid object doesn't have additional properties 错误: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"

I can't figure out why kubectl obliges me to specify ScaleIO in my spec, while I'm using local volume. 我无法弄清楚为什么kubectl要求我在我的规范中指定ScaleIO ,而我正在使用本地卷。

I've the same error specifying storagaClassName to standard 我将storagaClassName指定为standard出现同样的错误

Any idea about what can be the problem? 关于什么可能是问题的任何想法?

My versions : 我的版本:

$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"}

In minikube , the dynamic provisioner is already there by default , you just need to create persistent volume claims using that Class. 在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$ 

so for th data persistence to host , you just need a volume claim and use it on your kubernetes deployment. 因此,对于托管数据持久性,您只需要一个卷声明并在kubernetes部署中使用它。

example mysql volume claim using the built in minikube storage class. 使用内置的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

Usage inside mysql deployment: 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

I was going from error to error, then try to create another object such as secrets and the same issue. 我是从错误转到错误,然后尝试创建另一个对象,如秘密和相同的问题。

Then 然后

  • I removed kubectl in turn, and reinstall it, 我依次删除kubectl,然后重新安装,
  • I stop mikube and start it again 我停止mikube并再次启动它

It looks like the kubectl upgrade was the key to the solution, 1.10 client version was trying to talk to 1.14 - and the mismatch in API version can explain the weirdness in the error messages. 看起来kubectl升级是解决方案的关键, 1.10客户端版本试图与1.14交谈 - 而API版本中的不匹配可以解释错误消息中的怪异。 It seemed to be not really minikube related. 它似乎与minikube无关。

It's now working, I can actually run my kube commands without errors 它现在正在工作,我实际上可以kube运行我的kube命令

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

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