簡體   English   中英

有什么方法可以使用Kubernetes運行超級特權容器嗎?

[英]Is there any way to run super-privileged containers using Kubernetes?

我希望Pod中的所有進程都看到相同的網絡和進程表,並與主機進程共享任何IPC。 我知道當我們使用docker時,可以利用以下命令。

docker run -it --privileged --ipc=host --net=host --pid=host   \
           -v /:/host -v /run:/run -v /etc/localtime:/etc/localtime   \
           --name privcontainer centos7 /bin/bash

另一方面,有什么方法可以使用Kubernetes運行超級特權容器? 如果可能的話,我想知道編寫pod yaml文件的方法。

容器規范的SecurityContext上有一個privileged標志。

查看文檔以獲取更多詳細信息。

我只能從v1.4文檔中找到一個示例:

apiVersion: v1
kind: Pod
metadata:
  name: hello-world
spec:
  containers:
    - name: hello-world-container
      # The container definition
      # ...
      securityContext:
        privileged: true   ###Here is what you are looking for
        seLinuxOptions:
          level: "s0:c123,c456"

這里有更多信息

我相信您已經知道了,但是一般來說,特權用戶將刪除所有容器安全設置,並向群集開放潛在的安全漏洞。

要禁用容器PID的命名空間,從而允許該容器查看主機上的所有進程,需要在pod規范中指定hostPID: true

如果要從Pod中檢查Kubernetes主機,可能會發現此清單很有用:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: debug
spec:
  selector:
    matchLabels:
      app: debug
  template:
    metadata:
      labels:
        app: debug
      name: debug
    spec:
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      hostNetwork: true
      hostPID: true
      containers:
      - name: linux
        image: alpine
        args:
        - sleep
        - "3600"
        securityContext:
          privileged: true
          runAsGroup: 0
          runAsUser: 0
        volumeMounts:
        - mountPath: /mnt/host
          name: host
      volumes:
      - hostPath:
          path: /
          type: ""
        name: host

這將實例化群集上每個節點(包括控制平面節點,如果您可以看到它們)上的“調試”窗格。 該Pod可以訪問主機上的所有PID,可以看到其所有網絡,並且可以在/mnt/host瀏覽節點文件系統。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM