如何在一个Kubernetes Pod内检查其他容器的文件系统?

huangapple go评论50阅读模式
英文:

How to check other containers file systems within a k8s pod?

问题

我有一个包含两个容器的 Pod - nginxbusybox。现在我想从 busybox 容器访问 nginx 容器中的文件,比如在 busybox 容器中运行 'ls /etc/nginx' 来列出其中的文件。在 Kubernetes Pod 中是否有任何配置可以让我实现这个目标?

以下是我的当前 Pod 的 YAML 文件。

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: nginxbusybox
  name: nginxbusybox
spec:
  shareProcessNamespace: true
  containers:
  - image: nginx
    name: nginx
  - image: busybox
    name: busybox
    command:
    - sleep
    - '86400'

P.S. 这是为了调试一个不具备常见 Linux 工具的容器。

英文:

I have a Pod which contains two containers - nginx and busybox. Now I want to access the files within nginx container from the busybox container, say doing 'ls /etc/nginx' in busybox container to list the files there. Is there any configuration in k8s pod to allow me to achieve this?

Below is my current pod yaml file.

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: nginxbusybox
  name: nginxbusybox
spec:
  shareProcessNamespace: true
  containers:
  - image: nginx
    name: nginx
  - image: busybox
    name: busybox
    command:
    - sleep
    - '86400'

P.S. This is for debugging a container which don't have the common linux tools within.

答案1

得分: 1

我找到了一种实现方法。通过使用 'kubectl debug' 并检查 /proc/1/root/,我可以看到 nginx 容器中的文件系统。以下是这个样子。

如何在一个Kubernetes Pod内检查其他容器的文件系统?

英文:

OK, I've found a way to achieve this. By using the 'kubectl debug' and checking the /proc/1/root/, I could see the filesystem in the nginx container. Below's what this looks like.

如何在一个Kubernetes Pod内检查其他容器的文件系统?

huangapple
  • 本文由 发表于 2023年1月9日 19:21:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056545.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定