2

我正在尝试在 Kubernetes Kind 集群中部署一个容器。我尝试部署的容器需要设置几个 sysctls 标志。

部署失败

forbidden sysctl: "kernel.msgmnb" not whitelisted

更新

我已经按照建议添加了一个集群策略,创建了一个授予使用权限的角色并将集群角色分配给默认服务帐户:

---
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: sysctl-psp
spec:
  privileged: false  # Don't allow privileged pods!
  # The rest fills in some required fields.
  seLinux:
    rule: RunAsAny
  supplementalGroups:
    rule: RunAsAny
  runAsUser:
    rule: RunAsAny
  fsGroup:
    rule: RunAsAny
  volumes:
  - '*'
  allowedUnsafeSysctls:
  - kernel.msg*
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: role_allow_sysctl
rules:
- apiGroups: ['policy']
  resources: ['podsecuritypolicies']
  verbs:     ['*']
  resourceNames:
  - sysctl-psp
- apiGroups: ['']
  resources:
  - replicasets
  - services
  - pods
  verbs: ['*']
- apiGroups: ['apps']
  resources:
  - deployments
  verbs: ['*']

集群角色绑定是这样的:

kubectl -n <namespace> create rolebinding default:role_allow_sysctl --clusterrole=role_allow_sysctl --serviceaccount=<namespace>:default

然后我尝试在同一个命名空间中创建部署和服务:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-app
  labels:
    app: test-app
spec:
  selector:
    matchLabels:
      app: test-app
      tier: dev
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: test-app
        tier: dev
    spec:
      securityContext:
        sysctls:
        - name: kernel.msgmnb
          value: "6553600"
        - name: kernel.msgmax
          value: "1048800"
        - name: kernel.msgmni
          value: "32768"
        - name: kernel.sem
          value: "128 32768 128 4096"
      containers:
      - image: registry:5000/<container>:1.0.0
        name: test-app
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 10666
          name:port-1
---

问题仍然存在,但是,我产生了多个 pod,都失败并显示相同的消息forbidden sysctl: "kernel.msgmnb" not whitelisted

4

1 回答 1

1

我认为该 --alowed-unsafe-sysctls标志不适用于 Kind 节点,因为 Kind 节点本身就是容器,其 sysctl FS 是只读的。

我的解决方法是更改​​主机上所需的 sysctl 值。Kind 节点(以及它们的容器)将重用这些值。

于 2020-04-12T09:48:06.363 回答