我在本地 Kubernetes 环境中运行带有 SQL Server 的 Ubuntu 容器,并在 Windows 笔记本电脑上使用 Docker Desktop。
现在我正在尝试安装本地文件夹(C:\data\sql
),其中包含 pod 中的数据库文件。
为此,我在 Kubernetes 中配置了持久卷和持久卷声明,但它似乎没有正确安装。我没有看到错误或任何东西,但是当我使用进入容器时docker exec -it
并检查数据文件夹,它是空的。我希望本地文件夹中的文件出现在已安装的文件夹“data”中,但事实并非如此。
PV、PVC 或 pod 中是否配置错误?
这是我的 yaml 文件:
apiVersion: v1
kind: PersistentVolume
metadata:
name: dev-customer-db-pv
labels:
type: local
app: customer-db
chart: customer-db-0.1.0
release: dev
heritage: Helm
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /C/data/sql
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: dev-customer-db-pvc
labels:
app: customer-db
chart: customer-db-0.1.0
release: dev
heritage: Helm
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
apiVersion: apps/v1
kind: Deployment
metadata:
name: dev-customer-db
labels:
ufo: dev-customer-db-config
app: customer-db
chart: customer-db-0.1.0
release: dev
heritage: Helm
spec:
selector:
matchLabels:
app: customer-db
release: dev
replicas: 1
template:
metadata:
labels:
app: customer-db
release: dev
spec:
volumes:
- name: dev-customer-db-pv
persistentVolumeClaim:
claimName: dev-customer-db-pvc
containers:
- name: customer-db
image: "mcr.microsoft.com/mssql/server:2019-latest"
imagePullPolicy: IfNotPresent
volumeMounts:
- name: dev-customer-db-pv
mountPath: /data
envFrom:
- configMapRef:
name: dev-customer-db-config
- secretRef:
name: dev-customer-db-secrets
起初,我尝试在 pod 中定义一个没有 PV 和 PVC 的卷,但当我尝试从已安装的数据文件夹中读取文件时,出现访问被拒绝错误。
spec:
volumes:
- name: dev-customer-db-data
hostPath:
path: C/data/sql
containers:
...
volumeMounts:
- name: dev-customer-db-data
mountPath: data
我也尝试过 Helm 安装--set volumePermissions.enabled=true
但这并没有解决访问被拒绝的错误。
根据此信息Docker 的 GitHub https://github.com/docker/for-win/issues/5325#issuecomment-567481915WSL 2 中不支持主机路径卷。
Thus, 可以使用下一个解决方法.
我们只需要追加/run/desktop/mnt/host
到主机上的初始路径/c/data/sql
。在这种情况下不需要 PersistentVolume 和 PersistentVolumeClaim - 只需删除它们即可。
我变了spec.volumes
部署根据有关 Kubernetes 站点上的 hostPath 配置的信息 https://kubernetes.io/docs/concepts/storage/volumes/#hostpath-configuration-example:
volumes:
- name: dev-customer-db-pv
hostPath:
path: /run/desktop/mnt/host/c/data/sql
type: Directory
应用这些更改后,可以在以下位置找到这些文件data
pod 中的文件夹,因为mountPath: /data
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)