kubernetes - MountPath 未列出文件
问题描述
全部,
我部署了下面的 yaml 文件并部署了它。我正在学习 Volume、VolumeMount 和 MountPath。
我看到在容器的挂载路径中指定的containerdrive文件夹(我做了 kubectl exec -it podname),并且在containerdrive 中我希望看到路径中指定的文件夹“ /home/rgn/kubernetes/scripts ”中的文件的主机路径。但事实并非如此,实际上 containerdrive 是空的。
看来我对 Volume、VolumeMount 和 MountPath 的理解是错误的。我错过了什么?有人可以指出我正确的方向吗?
谢谢,rgn
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.15.4
ports:
- containerPort: 80
volumeMounts:
- mountPath: /containerdrive
name: test-volume
volumes:
- name: test-volume
hostPath:
# directory location on host
path: /home/rgn/kubernetes/scripts
# this field is optional
# type: DirectoryOrCrate
解决方案
看来我对 Volume、VolumeMount 和 MountPath 的理解是错误的。我错过了什么?有人可以指出我正确的方向吗?
hostPath: # directory location on host path: /home/rgn/kubernetes/scripts
该卷将Kubernetes (k8s) 主机节点的文件系统hostPath
中的文件或目录安装到您的 Pod 中。这不是大多数 Pod 需要的东西,但它为某些应用程序提供了强大的逃生舱口。这是指运行容器的 k8s 节点上的路径。path
nginx
要回答您的具体情况:请确保该目录/home/rgn/kubernetes/scripts
存在于您的 k8s 节点上。
我刚刚在我自己的 gke 集群(2 个节点)上运行了部署问题
$kubectl get nodes
NAME
gke-ubuntu-mnnv
gke-ubuntu-nw9v
$ kubectl apply -f deployment.yaml
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE NODE
nginx-deployment-ddbfb785d-fggpq 1/1 Running 0 19s gke-ubuntu-nw9v
$ kubectl exec nginx-deployment-ddbfb785d-fggpq -- ls -la containerdrive
total 8
drwxr-xr-x 2 root root 4096 Jun 22 11:54 .
drwxr-xr-x 1 root root 4096 Jun 22 11:55 ..
-rw-r--r-- 1 root root 0 Jun 22 11:54 gke-ubuntu-nw9v-file
$ kubectl describe deployments nginx-deployment
...
Mounts:
/containerdrive from test-volume (rw)
Volumes:
test-volume:
Type: HostPath (bare host directory volume)
Path: /tmp/knp
HostPathType:
...
# and on k8s node itself:
$ ls -lah /tmp/knp/
total 8.0K
drwxr-xr-x 2 root root 4.0K Jun 22 11:54 .
drwxrwxrwt 10 root root 4.0K Jun 22 12:08 ..
-rw-r--r-- 1 root root 0 Jun 22 11:54 gke-ubuntu-nw9v-file
我希望输出有助于清楚地看到整个画面。:)
此外,正如 David Maze 所提到的,将您依赖的所有脚本编译到容器本身中可能是一个好主意。
推荐阅读
- azure-ad-b2c - 重置用户密码不适用于 Azure B2C
- algorithm - 圆形区域内的查询点
- haskell - 为什么应用于具有相同函数的不同输入的多态函数的类型推断失败
- numpy - Anaconda 环境安装包 Numpy-Base
- java - 从 java 代码执行 shell 脚本并将终端的输出附加到 .txt 文件
- firebase - 为管理员使用 Firebase 自定义声明(Firestore 和云存储)
- spring-boot - 警告:bounce_queue_lifetime 大于 maximal_queue_lifetime - 调整bounce_queue_lifetime
- ruby-on-rails - 将自定义域分配给 S3 存储桶
- javascript - 在 javascript 中重命名 JSON 键
- c# - 将多个字典合二为一