1
0
mirror of https://github.com/kata-containers/kata-containers.git synced 2025-04-30 04:34:27 +00:00

kata-deploy: Use host's systemctl

when interacting with systemd. We have occasionally faced issues with
compatibility between the systemctl version used inside the kata-deploy
container and the systemd version on the host. Instead of using a containerized
systemctl with bind mounted sockets, nsenter the host and run systemctl from
there. This provides less coupling between the kata-deploy container and the
host.

Fixes: 
Signed-off-by: Jeremi Piotrowski <jpiotrowski@microsoft.com>
This commit is contained in:
Jeremi Piotrowski 2023-08-02 11:16:11 +02:00
parent 29855ed0c6
commit 3230dec950
3 changed files with 14 additions and 30 deletions
tools/packaging/kata-deploy
kata-cleanup/base
kata-deploy/base
scripts

View File

@ -14,6 +14,7 @@ spec:
name: kubelet-kata-cleanup
spec:
serviceAccountName: kata-deploy-sa
hostPID: true
nodeSelector:
katacontainers.io/kata-runtime: cleanup
containers:
@ -38,18 +39,6 @@ spec:
value: "false"
securityContext:
privileged: true
volumeMounts:
- name: dbus
mountPath: /var/run/dbus/system_bus_socket
- name: systemd
mountPath: /run/systemd/system
volumes:
- name: dbus
hostPath:
path: /var/run/dbus/system_bus_socket
- name: systemd
hostPath:
path: /run/systemd/system
updateStrategy:
rollingUpdate:
maxUnavailable: 1

View File

@ -14,6 +14,7 @@ spec:
name: kata-deploy
spec:
serviceAccountName: kata-deploy-sa
hostPID: true
containers:
- name: kube-kata
image: quay.io/kata-containers/kata-deploy:latest
@ -47,10 +48,6 @@ spec:
mountPath: /etc/containerd/
- name: kata-artifacts
mountPath: /opt/kata/
- name: dbus
mountPath: /var/run/dbus/system_bus_socket
- name: systemd
mountPath: /run/systemd/system
- name: local-bin
mountPath: /usr/local/bin/
volumes:
@ -64,12 +61,6 @@ spec:
hostPath:
path: /opt/kata/
type: DirectoryOrCreate
- name: dbus
hostPath:
path: /var/run/dbus/system_bus_socket
- name: systemd
hostPath:
path: /run/systemd/system
- name: local-bin
hostPath:
path: /usr/local/bin/

View File

@ -25,6 +25,10 @@ die() {
exit 1
}
function host_systemctl() {
nsenter --target 1 --mount systemctl "${@}"
}
function print_usage() {
echo "Usage: $0 [install/cleanup/reset]"
}
@ -71,11 +75,11 @@ function get_container_runtime() {
die "invalid node name"
fi
if echo "$runtime" | grep -qE 'containerd.*-k3s'; then
if systemctl is-active --quiet rke2-agent; then
if host_systemctl is-active --quiet rke2-agent; then
echo "rke2-agent"
elif systemctl is-active --quiet rke2-server; then
elif host_systemctl is-active --quiet rke2-server; then
echo "rke2-server"
elif systemctl is-active --quiet k3s-agent; then
elif host_systemctl is-active --quiet k3s-agent; then
echo "k3s-agent"
else
echo "k3s"
@ -136,8 +140,8 @@ function configure_cri_runtime() {
configure_containerd
;;
esac
systemctl daemon-reload
systemctl restart "$1"
host_systemctl daemon-reload
host_systemctl restart "$1"
wait_till_node_is_ready
}
@ -371,10 +375,10 @@ function cleanup_containerd() {
function reset_runtime() {
kubectl label node "$NODE_NAME" katacontainers.io/kata-runtime-
systemctl daemon-reload
systemctl restart "$1"
host_systemctl daemon-reload
host_systemctl restart "$1"
if [ "$1" == "crio" ] || [ "$1" == "containerd" ]; then
systemctl restart kubelet
host_systemctl restart kubelet
fi
wait_till_node_is_ready