简体   繁体   English

如何在 OSX 上将 Kubernetes Persistent Local Volumes 与 Minikube 一起使用?

[英]How to use Kubernetes Persistent Local Volumes with Minikube on OSX?

I want to experiment with Persistent Local Volumes using Minikube on OSX.我想在 OSX 上使用 Minikube 试验持久性本地卷 I am using the local provisioner ( https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner ) to create the PVs for me.我正在使用本地供应商 ( https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner ) 为我创建 PV。

I create the local directory on the OSX host and mount it to the Minikube VM:我在 OSX 主机上创建本地目录并将其挂载到 Minikube VM:

mkdir -p /path/to/data/dir
minikube mount /path/to/data/dir:/data/dir &

When I look at the logs for the provisioner, I can see errors like this:当我查看配置程序的日志时,我可以看到如下错误:

Found new volume at host path "/data/dir" with capacity 0, creating Local PV "local-pv-ccc90d9b", required volumeMode "Filesystem"
Error creating PV "local-pv-ccc90d9b" for volume at "/data/zk-2": PersistentVolume "local-pv-ccc90d9b" is invalid: spec.capacity[storage]: Invalid value: "0": must be greater than zero

Guided by the advice here ( https://github.com/kubernetes-incubator/external-storage/issues/968 ), I ssh'ed in to the Minikube VM and looked at the capacity of the mount:在此处的建议 ( https://github.com/kubernetes-incubator/external-storage/issues/968 ) 的指导下,我进入 Minikube VM 并查看了挂载的容量:

$ df /data/dir/
Filesystem     1K-blocks  Used Available Use% Mounted on
192.168.99.1           0     0         0    - /data/dir

So the capacity of the mount is zero and this seems to the why it's throwing up the error I see.所以安装的容量为零,这似乎是它抛出我看到的错误的原因。 However, the parent directory但是,父目录

$ df /data          
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       16888216 1129408  14769676   8% /data

Is this an issue with the minikube mount command?这是minikube mount命令的问题吗? Can this be made to work on OSX?这可以在 OSX 上运行吗? How do I get a Persistent Local Volume to work on OSX Minikube?如何让持久性本地卷在 OSX Minikube 上工作?

Here is my little how-to for those who ended up on that page looking for a way to share local folders on their Mac with minikube.这是我为那些最终在该页面上寻找一种使用 minikube 在 Mac 上共享本地文件夹的方法的人的小指南。

Personally, I was spinning up some Azure SQL Edge server (an equivalent to MS SQL Server, but that is compiled for the arm architecture of M1 silicon chips) and I wanted the database's data to persist on my disk so I could restart my pods without loosing their data.就我个人而言,我正在启动一些 Azure SQL Edge 服务器(相当于 MS SQL Server,但它是为 M1 硅芯片的 arm 架构编译的)并且我希望数据库的数据保留在我的磁盘上,这样我就可以重新启动我的 pods丢失他们的数据。

1. Mount the folder you want to share on your host, in minikube: 1. 在 minikube 中挂载您要共享的文件夹到您的主机上:

minikube mount ./path/to/mySharedData:/mnt1/shared1 --uid 10001 --gid 10001

Here, the volume mounted in minikube will have group id and user id 10001. This is the user id of Azure SQL Edge server inside the container.在这里,安装在 minikube 中的卷将具有组 ID 和用户 ID 10001。这是容器内 Azure SQL Edge 服务器的用户 ID。

I used these --uid and --gid arguments because I was running into some write access error.我使用了这些 --uid 和 --gid 参数,因为我遇到了一些写访问错误。

If you don't know what is the user id inside your container, log into your container and type id , it will tell you the user id.如果您不知道容器内的用户 ID 是什么,请登录您的容器并输入id ,它会告诉您用户 ID。

Don't close the terminal.不要关闭终端。 That process needs to be running all the time for the folder to be accessible.该过程需要一直运行才能访问该文件夹。

2. Use that folder with hostPath: 2. 将该文件夹与 hostPath 一起使用:

    spec:
      volumes:
        - name: mssql-data
          hostPath:
            path: /mnt1/shared1
      containers:
        - name: azuresqledge
          image: mcr.microsoft.com/azure-sql-edge:latest
          ports:
            - containerPort: 1433
          volumeMounts:
            - name: mssql-data
              mountPath: /var/opt/mssql/data
          env:
            - name: MSSQL_PID
              value: "Developer"
            - name: ACCEPT_EULA
              value: "Y"
            - name: SA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mssql
                  key: SA_PASSWORD
            - name: MSSQL_AGENT_ENABLED
              value: "TRUE"
            - name: MSSQL_COLLATION
              value: "SQL_Latin1_General_CP1_CI_AS"
            - name: MSSQL_LCID
              value: "1033"
      terminationGracePeriodSeconds: 30
      securityContext:
        fsGroup: 10001

A lot of the stuff here is Azure SQL specific (all the env ...).这里的很多东西都是特定于 Azure SQL 的(所有环境......)。 Two things are important: Define the volume mounted in minikube with:有两件事很重要:使用以下命令定义安装在 minikube 中的卷:

      volumes:
        - name: mssql-data
          hostPath:
            path: /mnt1/shared1

And mount it inside your container where you need:并将其安装在您需要的容器中:

          volumeMounts:
            - name: mssql-data
              mountPath: /var/opt/mssql/data

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

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