gpt4 book ai didi

kubernetes - Kubernetes Kind 中容器的白名单 sysctl

转载 作者:行者123 更新时间:2023-12-02 12:01:44 32 4
gpt4 key购买 nike

我正在尝试在 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: ['*']

集群角色绑定(bind)是这样的:

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,所有 pod 都失败并显示相同的消息 forbidden sysctl: "kernel.msgmnb"not whitelisted

最佳答案

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

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

关于kubernetes - Kubernetes Kind 中容器的白名单 sysctl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60704043/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com