英文:
How to enable systemd within a k8s Pod
问题
我正在我的K8s集群上运行Kata容器,并希望在容器中使用systemd。
使用以下Dockerfile来构建我的镜像:
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y systemd systemd-sysv && apt-get clean && rm -rf /var/lib/apt/lists/*
# 禁用一些不需要的服务,可能会引发问题
CMD ["/sbin/init"]
这是我的Pod的YAML文件:
apiVersion: v1
kind: Pod
metadata:
name: pod6
spec:
runtimeClassName: kata-qemu
containers:
- name: c1
image: my-ubuntu-systemd:latest
imagePullPolicy: Always
command:
- bash
securityContext:
privileged: true
capabilities:
add: ["SYS_ADMIN"]
volumeMounts:
- name: cgroup
mountPath: /sys/fs/cgroup
readOnly: true
- name: tmp
mountPath: /tmp
subPath: tmp
- name: tmp
mountPath: /run
subPath: run
- name: tmp
mountPath: /run/lock
subPath: run-lock
volumes:
- name: cgroup
hostPath:
path: /sys/fs/cgroup
type: Directory
- name: tmp
emptyDir:
medium: Memory
sizeLimit: 128Mi
当我进入Pod后,出现以下问题:
root@pod6:/# systemctl status
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
我该如何解决这个问题?
英文:
I am running a kata containers on my k8s cluster and would like to use systemd within the pod.
Using the following dockerfile to build my image:
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y systemd systemd-sysv && apt-get clean && rm -rf /var/lib/apt/lists/*
# Disable some services that we do not need and which can cause issues
CMD ["/sbin/init"]
And this is my yaml file for the pod:
apiVersion: v1
kind: Pod
metadata:
name: pod6
spec:
runtimeClassName: kata-qemu
containers:
- name: c1
image: my-ubuntu-systemd:latest
imagePullPolicy: Always
command:
- bash
securityContext:
privileged: true
capabilities:
add: ["SYS_ADMIN"]
volumeMounts:
- name: cgroup
mountPath: /sys/fs/cgroup
readOnly: true
- name: tmp
mountPath: /tmp
subPath: tmp
- name: tmp
mountPath: /run
subPath: run
- name: tmp
mountPath: /run/lock
subPath: run-lock
volumes:
- name: cgroup
hostPath:
path: /sys/fs/cgroup
type: Directory
- name: tmp
emptyDir:
medium: Memory
sizeLimit: 128Mi
Once I am in the pod, getting the following:
root@pod6:/# systemctl status
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
What can I do to fix this?
答案1
得分: 0
找到答案:
不是启动bash,而是启动systemd:
命令:
- /usr/lib/systemd/systemd
英文:
Found the answer:
Instead of launching bash, I am launching systemd:
command:
- /usr/lib/systemd/systemd
答案2
得分: 0
在命令中使用 systemd
对我来说行不通,因为我需要将脚本作为命令/参数运行。如果您手动进入容器并执行,它可以正常工作,但如果命令/参数中有类似 bash my-script.sh
的内容,它会挂起。
在这种情况下,https://stackoverflow.com/questions/73714080/entrypoint-of-systemd-container-for-gitlab-ci 更相关。
英文:
Using systemd
in command doesn't work for me in the case that I need to run a script as command/args. It works fine if you manually exec into the container, but it hangs if you have something like bash my-script.sh
as command/args.
https://stackoverflow.com/questions/73714080/entrypoint-of-systemd-container-for-gitlab-ci is more relevant in that case.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论