首页 > 解决方案 > 无法让容器在 k8s 中获取 apparmor 配置文件

问题描述

mount: tmpfs is write-protected, mounting read-only
mount: cannot mount tmpfs read-only
failed.

基于文档 re: annotations 和containers creator,这是我的部署文件的相关部分:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: unifi-video
  annotations:
    container.apparmor.security.beta.kubernetes.io/unifi-video: "unconfined"
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: unifi-video
    spec:
      hostname: unifi-video
      nodeSelector:
        kubernetes.io/hostname: mira-b.home
      volumes:
      - name: dockerdata
        persistentVolumeClaim:
          claimName: dockerdata-nas
      - name: cameradata
        persistentVolumeClaim:
          claimName: cameras-nas
      containers:
      - name: unifi-video
        image: pducharme/unifi-video-controller:3.9.7
        securityContext:
          capabilities:
            add:
              - SYS_ADMIN
              - DAC_READ_SEARCH

IT 特别呼吁

如果您收到此 tmpfs 挂载错误,请将 --security-opt apparmor:unconfined \ 添加到您的运行选项列表中。此错误已在 Ubuntu 上出现,但也可能出现在其他平台上。

但从我能找到的(现在搜索一个多小时)来看,实现这一点的方法是 k8s 是通过注释行。

我错过了什么吗?

标签: dockerkubernetes

解决方案


最终从 k8s 问题部分得到了答案。注释在错误的位置。这是执行此操作的正确方法:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: unifi-video
spec:
  replicas: 1
  template:
    metadata:
      annotations:
        container.apparmor.security.beta.kubernetes.io/unifi-video: unconfined
      labels:
        app: unifi-video

这导致成功部署了带有 apparmor 的容器,允许安装 tempfs。


推荐阅读