docker+k8s报错
问题点:docker容器中或者k8s的pod中执行systemctl相关后台服务
报错信息:Failed to get D-Bus connection: Operation not permitted
解决办法
docker:运行容器添加参数--privileged=true + /sbin/init
docker run -tid --name text --privileged=true image_name /sbin/init
k8s:启动pod的yaml中添加参数:注意yaml格式的对齐
command: ["/usr/sbin/init", "-c","--"]
securityContext:
privileged: true
- 具体yaml
apiVersion: v1
kind: Pod
metadata:
name: text2
namespace: text
spec:
containers:
- name: text2
image: centos:7
command: ["/usr/sbin/init", "-c","--"]
securityContext:
privileged: true