Search code examples
kubernetessystemdkata-containers

How to enable systemd within a k8s Pod


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?


Solution

  • Found the answer:

    Instead of launching bash, I am launching systemd:

    command:
          - /usr/lib/systemd/systemd