【问题标题】:Starting/Stopping services in a host as part of K8S pod deployment作为 K8S pod 部署的一部分,在主机中启动/停止服务
【发布时间】:2018-09-01 14:46:02
【问题描述】:

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

【问题讨论】:

  • 什么发行版?假设它是 systemd 和 systemctl 你需要?

标签: amazon-web-services amazon-ec2 kubernetes


【解决方案1】:

您可以将 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 设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-11
    • 2021-12-19
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 2022-06-28
    • 2019-02-03
    相关资源
    最近更新 更多