开发者社区 > 云原生 > 容器服务 > 正文

使systemctl在debian拉伸图像中的容器内工作

我想systemctl从运行kubernetes节点的容器内部访问(ami:运行debian stretch)

工作设置:
节点AMI:kope.io/k8s-1.10-debian-jessie-amd64-hvm-ebs-2018-08-17

节点目录安装在容器中以进行systemctl工作:

在/ var /运行/ DBUS
/运行/ systemd
/斌/ systemctl
的/ etc / systemd /系统
不工作设置:
节点AMI:kope.io/k8s-1.11-debian-stretch-amd64-hvm-ebs-2018-08-17

节点目录安装在容器中以进行systemctl工作:

在/ var /运行/ DBUS
/运行/ systemd
/斌/ systemctl
的/ etc / systemd /系统
调试以尝试解决问题
使用debian-stretch不支持systemctl相同安装的映像来调试此问题debian-jessie

1)我开始通过在其中安装上述卷来启动nginx部署

kubectl apply -f https://k8s.io/examples/application/deployment.yaml

kubectl exec -it nginx-deployment /bin/bash

root@nginx-deployment-788f65877d-pzzrn:/# systemctl
systemctl: error while loading shared libraries: libsystemd-shared-
232.so: cannot open shared object file: No such file or directory
2)由于上述问题显示文件libsystemd-shared-232.so未找到。我通过查看节点找到了实际路径。

admin@ip-10-0-20-11:~$ sudo find / -iname 'libsystemd-shared-232.so'
/lib/systemd/libsystemd-shared-232.so
3)安装/lib/systemd在nginx pod中并再次运行systemctl

kubectl exec -it nginx-deployment /bin/bash

root@nginx-deployment-587d866f54-ghfll:/# systemctl
systemctl: error while loading shared libraries: libcap.so.2:cannot
open shared object file: No such file or directory
4)现在systemctl失败了

root@nginx-deployment-587d866f54-ghfll:/# systemctl
systemctl: error while loading shared libraries: libcap.so.2: cannot
open shared object file: No such file or directory
5)为了解决上述错误,我再次搜索节点,libcap.so.2在下面的路径中找到它。

admin@ip-10-0-20-11:~$ sudo find / -iname 'libcap.so.2'
/lib/x86_64-linux-gnu/libcap.so.2
6)看到上面的目录未安装在我的pod中。我在nginx pod中安装了以下路径。

/lib/x86_64-linux-gnu mounted in the nginx pod(deployment)
7)添加上述安装后,nginx pod无法启动。得到以下错误:

$ k logs nginx-deployment-f9c5ff956-b9wn5
standard_init_linux.go:178: exec user process caused "no such file
or directory"
如何进一步调试。并且所有安装都需要使systemctl在debian拉伸环境中从容器内部工作。

展开
收起
k8s小能手 2019-01-11 11:27:28 3406 0
1 条回答
写回答
取消 提交回答
  • 整合最优质的专家资源和技术资料,问答解疑

    您可以只在容器中安装systemd,而不是从主机安装一些库文件。

    $ apt-get -y install systemd
    现在,这不一定会systemctl成功。您需要在系统中systemd生成的容器中运行/sbin/init。/sbin/init需要以root身份运行所以基本上你必须使用Kubernetes上privileged的pod或容器安全上下文中的标志来运行它。现在,这是不安全的,并且在一个容器中运行systemd 有很长的历史,Docker的人主要反对它(安全性),Red Hat的人说它是必需的。

    然而,红帽人们想出了一种让它在没有unprivileged旗帜的情况下工作的方法。你需要:

    /run 作为容器中的tmpfs安装。
    /sys/fs/cgroup 以只读方式安装即可。
    /sys/fs/cgroup/systemd/ 以读/写方式安装。
    用来 STOPSIGNAL SIGRTMIN+3
    在Kubernetes你需要emptyDir安装一个tmpfs。其他可以作为主机卷安装。

    2019-07-17 23:25:15
    赞同 展开评论 打赏

国内唯一 Forrester 公共云容器平台领导者象限。

相关产品

  • 容器镜像服务
  • 容器服务Kubernetes版
  • 相关电子书

    更多
    阿里云文件存储 NAS 在容器场景的最佳实践 立即下载
    何种数据存储才能助力容器计算 立即下载
    《容器网络文件系统CNFS》 立即下载