kubernetes - Kubernetes 卷挂载设置类型检查失败
问题描述
我无法在 kubernetes 中部署应用程序,这是部署 yaml。
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
labels:
app: test
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
containers:
- name: test
image: openjdk:14
ports:
- containerPort: 8080
volumeMounts:
- name: testing
mountPath: "/usr/src/myapp/docker.jar"
workingDir: "/usr/src/myapp"
command: ["java"]
args: ["-jar", "docker.jar"]
volumes:
- hostPath:
path: /home/user/docker.jar
type: File
name: testing
这是我收到的错误,我可以验证该文件确实存在并且在此文件夹中。我尝试删除该类型,但它只上传一个空目录,似乎无法识别该文件存在。
MountVolume.SetUp failed for volume "testing" : hostPath type check failed: /home/user/docker.jar is not a file
解决方案
当您使用默认驱动程序启动minikube时,您是在机器内部创建。docker
Docker VM
背景
当你使用你的虚拟机时,你的终端看起来像:
user@nameofyourhost:~$
但是,如果您愿意ssh
,您的Minikube VM
终端将如下所示:
docker@minikube:~$
在HostPath你有信息:
hostPath 卷将文件或目录从主机节点的文件系统安装到您的 Pod 中。
在minikube
您使用时hostPath
,节点被认为不是您的,machine
而是Minikube VM
在期间创建的minikube start
测试
因为我没有你的文件,所以我用过nginx
. 请记住,您应该对要挂载的目录具有适当的权限。我tmp
在nginx
这个目录中使用过,每个人都可以完全访问。
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
labels:
app: test
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
containers:
- name: test
image: nginx
ports:
- containerPort: 8080
volumeMounts:
- name: testing
mountPath: "/tmp/docker.jar" #this is path to the file
volumes:
- hostPath:
path: <path to docker.jar file> #should be on Minikube VM
type: File
name: testing
docker.jar
在 VM 上创建时。
user@nameOfMyVM:~$ pwd
/home/user
user@nameOfMyVM:~$ ls
docker.jar
当你hostpath.path
进入/home/user/docker.jar
它时会返回警告
Warning FailedMount 4s (x4 over 7s) kubelet MountVolume.SetUp failed for volume "testing" : hostPath type check failed: /home/sekreta/docker.jar is not a file`
由于 Kubernetes 没有找到这个文件。
但是当你在里面创建这个文件时Minikube VM
$ minikube ssh
docker@minikube:~$ pwd
/home/docker
docker@minikube:~$ ls
docker.jar
hostPath.path
并将创建对/home/docker/docker.jar
pod的部署更改。
$ kubectl get po
NAME READY STATUS RESTARTS AGE
test-c68d959c6-kb275 1/1 Running 0 13s
文件可以在 YAML 中设置的目录中找到,即tmp
.
$ kubectl exec -ti test-c68d959c6-kb275 -- bin/bash
root@test-c68d959c6-kb275:/# cd /tmp
root@test-c68d959c6-kb275:/tmp# ls
docker.jar
结论
当您使用HostPath
on时,Minikube
您需要记住这filesystem
不是您的Machine
,而是Minikube VM
在minikube start
.
推荐阅读
- php - 获取用于创建 mysql 表的代码
- xtext - 如何更改 QualifiedNames 的分隔符
- firebase - 仅允许管理员写入数据 - Firebase 实时数据库 - 安全规则
- swift - 无法确定以下 Pod 错误的 Swift 版本
- java - Mockito thenReturn 不起作用,返回 Null
- django-login - 登录 django 后不出现注销按钮
- r - 是否有用于以下数据整理和转换的 R 代码
- java - Java 和 Espresso - 无法输入,需要支持输入法或可从类分配:类 SearchView
- sql - 会感谢一些对复杂子查询的 SQL 查询的帮助
- linux - docker 容器无法看到共享卷中的数据