gpt4 book ai didi

Kubernetes 卷安装设置类型检查失败

转载 作者:行者123 更新时间:2023-12-02 18:57:25 25 4
gpt4 key购买 nike

我无法在 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您有信息:

A hostPath volume mounts a file or directory from the host node's filesystem into your Pod.

minikube 中,当您使用 hostPath 时,节点被视为不是您的机器,而是 Minikube VM,是在 minikube start

期间创建的

测试

由于我没有你的文件,所以我使用了nginx。请记住,您应该对要安装的目录拥有适当的权限。我在 nginx 中使用了 tmp,该目录对每个人都有完全访问权限。

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时。

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

结论

当您在 Minikube 上使用 HostPath 时,您需要记住 filesystem 不是您的机器,而是Minikube VM 是在 minikube start 期间创建的。

关于Kubernetes 卷安装设置类型检查失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66011511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com