docker+k8s报错

问题点:docker容器中或者k8s的pod中执行systemctl相关后台服务
报错信息:Failed to get D-Bus connection: Operation not permitted

file

解决办法
docker:运行容器添加参数–privileged=true + /sbin/init

file

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

总结:

1. 添加参数之后,container内的root拥有真正的root权限
2. 权限参数命令在init文件中

海汼部落原创文章,原文链接:http://www.hainiubl.com/topics/75603

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐