This repository has been archived by the owner on Oct 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
postStart preStop pod hook in lxcfs-daemonset.yaml to remount_lxcfs Does it work? #10
Comments
Thanks for suggestion, it looks good, can you provide a PR for that. |
@denverdino I tested the prestop and postStart hooks in my cluster to run the script. It has not been successful. I don't know what caused it. |
These are my yamls file contents apiVersion: apps/v1beta2
kind: DaemonSet
metadata:
name: lxcfs
labels:
app: lxcfs
spec:
selector:
matchLabels:
app: lxcfs
template:
metadata:
labels:
app: lxcfs
spec:
hostPID: true
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: lxcfs
image: 314315960/lxcfs-without-cleanup:3.0.4
imagePullPolicy: IfNotPresent
securityContext:
privileged: true
capabilities:
add:
- SYS_ADMIN
lifecycle:
postStart:
exec:
command: ["/usr/local/container_remount_lxcfs.sh"]
preStop:
exec:
command: ["/usr/local/cleanup.sh"]
volumeMounts:
- name: cgroup
mountPath: /sys/fs/cgroup
- name: lxcfs
mountPath: /var/lib/lxcfs
mountPropagation: Bidirectional
- name: usr-local
mountPath: /usr/local
- name: fusermount
mountPath: /bin/fusermount
- name: poststart
mountPath: /usr/local/container_remount_lxcfs.sh
subPath: container_remount_lxcfs.sh
- name: prestop
mountPath: /usr/local/cleanup.sh
subPath: cleanup.sh
volumes:
- name: cgroup
hostPath:
path: /sys/fs/cgroup
- name: usr-local
hostPath:
path: /usr/local
- name: lxcfs
hostPath:
path: /var/lib/lxcfs
type: DirectoryOrCreate
- name: fusermount
hostPath:
path: /bin/fusermount
- name: poststart
configMap:
name: remount-lxcfs
defaultMode: 0755
items:
- key: container_remount_lxcfs.sh
path: container_remount_lxcfs.sh
- name: prestop
configMap:
name: remount-lxcfs
defaultMode: 0755
items:
- key: cleanup.sh
path: cleanup.sh
apiVersion: v1
kind: ConfigMap
metadata:
name: remount-lxcfs
data:
container_remount_lxcfs.sh: |
#!/bin/bash
LXCFS="/var/lib/lxcfs"
containers=$(docker ps | awk '{print $2}' | grep -v Name)
for container in $containers;do
echo "remount $container"
PID=$(docker inspect $container | grep Pid | awk '{print $2}' | awk -F ',' '{print $1}' )
for file in meminfo cpuinfo stat uptime swaps diskstats;do
nsenter --target $PID --mount -- mount -B "$LXCFS/proc/$file" "/proc/$file"
done
done
cleanup.sh: |
#!/bin/bash
nsenter -m/proc/1/ns/mnt fusermount -u /var/lib/lxcfs 2> /dev/null || true
nsenter -m/proc/1/ns/mnt [ -L /etc/mtab ] || \
sed -i "/^lxcfs \/var\/lib\/lxcfs fuse.lxcfs/d" /etc/mtab Migrate the cleanup part of start.sh in the lxc-image directory to the cleanup.sh preStop hook script. [root@localhost lxcfs-image]# diff start.sh start-default.sh
3,4c3,7
< # Prepare
< mkdir -p /usr/local/lib/lxcfs /var/lib/lxcfs
---
> # Cleanup
> nsenter -m/proc/1/ns/mnt fusermount -u /var/lib/lxcfs 2> /dev/null || true
> nsenter -m/proc/1/ns/mnt [ -L /etc/mtab ] || \
> sed -i "/^lxcfs \/var\/lib\/lxcfs fuse.lxcfs/d" /etc/mtab
>
8a12,14
>
> # Prepare
> mkdir -p /usr/local/lib/lxcfs /var/lib/lxcfs |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
container_remount_lxcfs.sh
The text was updated successfully, but these errors were encountered: