繁体   English   中英

作为K8S Pod部署的一部分,在主机中启动/停止服务

[英]Starting/Stopping services in a host as part of K8S pod deployment

我们基于具有公司标准服务和实用程序的自定义VM映像运行K8S群集。 吊舱/容器如何访问这些容器/容器? 例如,如何在主机中启动服务作为部署/取消部署的一部分

您可以将systemd套接字安装到Pod的容器中。 从那里,您需要polkit权限以非特权用户身份运行命令,或者您需要以特权容器身份运行容器。 这样做的Pod规范如下:

kind: Pod
metadata:
  name: dbus-pod
  labels:
    app: dbus
spec:
  containers:
  - name: dbus-container
    image: centos:7
    command: ['systemctl','status','sshd']
    securityContext:
      privileged: true
    volumeMounts:
    - name: run-dbus
      mountPath: /var/run/dbus
    - name: run-systemd
      mountPath: /run/systemd
    - name: bin-systemctl
      mountPath: /usr/bin/systemctl
      readOnly: true
    - name: etc-systemd
      mountPath: /etc/systemd/system
      readOnly: true
  restartPolicy: Never
  volumes:
  - name: run-dbus
    hostPath:
    path: /var/run/dbus
  - name: run-systemd
    hostPath:
    path: /run/systemd
  - name: bin-systemctl
    hostPath:
    path: /usr/bin/systemctl
  - name: etc-systemd
    hostPath:
    path: /etc/systemd/system

然后,您必须弄清楚如何在群集上安排Pod。 如果要在每个节点上运行一次,则可以创建一个DaemonSet并将其删除。 如果您有选择器来定义Pod的运行位置,则Job可能更合适。

还有像go-systemd这样的项目,它通过/var/run/dbus套接字控制dbus,并代替所有systemd / systemctl设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM