我阅读了一些教程,介绍如何在容器中挂载卷并直接在主机/节点上运行脚本。以下是列举的例子。
DeamonSet荚规格
hostPID: true
nodeSelector:
cloud.google.com/gke-local-ssd: "true"
volumes:
- name: setup-script
configMap:
name: local-ssds-setup
- name: host-mount
hostPath:
path: /tmp/setup
initContainers:
- name: local-ssds-init
image: marketplace.gcr.io/google/ubuntu1804
securityContext:
privileged: true
volumeMounts:
- name: setup-script
mountPath: /tmp
- name: host-mount
mountPath: /host
command:
- /bin/bash
- -c
- |
set -e
set -x
# Copy setup script to the host
cp /tmp/setup.sh /host
# Copy wait script to the host
cp /tmp/wait.sh /host
# Wait for updates to complete
/usr/bin/nsenter -m/proc/1/ns/mnt -- chmod u+x /tmp/setup/wait.sh
# Give execute priv to script
/usr/bin/nsenter -m/proc/1/ns/mnt -- chmod u+x /tmp/setup/setup.sh
# Wait for Node updates to complete
/usr/bin/nsenter -m/proc/1/ns/mnt /tmp/setup/wait.sh
# If the /tmp folder is mounted on the host then it can run the script
/usr/bin/nsenter -m/proc/1/ns/mnt /tmp/setup/setup.sh
containers:
- image: "gcr.io/google-containers/pause:2.0"
name: pause(有一个用于组成.sh文件的configmap。我跳过了)
"/usr/bin/nsenter m/proc/1/ns/mnt“是什么意思?这是在主机上运行某些东西的命令吗?什么是"/proc/1/ns/mnt“?
发布于 2022-03-23 09:35:57
让我们从名称空间开始,详细了解这一点:
容器中的命名空间有助于在进程之间隔离资源。名称空间控制内核中的资源并分配给进程。这为可能在系统中运行的不同容器提供了很好的隔离。
尽管如此,这也会使这些对名称空间的访问限制变得更加复杂。接下来是nsenter命令,它将允许conatiners访问名称空间。类似于sudo命令的东西。.This命令可以让我们访问挂载、UTS、IPC、网络、PID、用户、cgroup和时间命名空间。
您的示例中的-m是-挂载,它将访问该文件指定的挂载命名空间。
https://stackoverflow.com/questions/71583725
复制相似问题