Created
April 29, 2020 20:52
-
-
Save voor/65a92645cba6d29a1db34cc456d042c8 to your computer and use it in GitHub Desktop.
Node remediation with the magic of chroot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl run -i --rm --tty photonos-on-host --overrides=' | |
{ | |
"spec": { | |
"containers": [ | |
{ | |
"name": "photonos-on-host", | |
"image": "photon:3.0", | |
"args": ["bash"], | |
"stdin": true, | |
"stdinOnce": true, | |
"tty": true, | |
"volumeMounts": [ | |
{ | |
"mountPath": "/host/", | |
"name": "hostpath-mount" | |
} | |
] | |
} | |
], | |
"volumes": [ | |
{ | |
"name": "hostpath-mount", | |
"hostPath": { | |
"path": "/" | |
} | |
} | |
] | |
} | |
} | |
' --image=photon:3.0 --restart=Never -- bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: node-remediation | |
labels: | |
yum: node-remediation | |
data: | |
remediate.sh: | | |
#!/usr/bin/env bash | |
set -euo pipefail | |
HOSTPATH_VOLUME="${HOSTPATH_VOLUME:-/host}" | |
echo "Making package cache" | |
chroot "${HOSTPATH_VOLUME}" yum makecache | |
echo "Adding NFS-Utils" | |
chroot "${HOSTPATH_VOLUME}" yum install -y nfs-utils | |
--- | |
apiVersion: apps/v1 | |
kind: DaemonSet | |
metadata: | |
name: node-remediation | |
spec: | |
selector: | |
matchLabels: | |
yum: node-remediation | |
updateStrategy: | |
type: RollingUpdate | |
template: | |
metadata: | |
labels: | |
name: node-remediation | |
yum: node-remediation | |
spec: | |
initContainers: | |
- image: photon:3.0 | |
name: node-initializer | |
command: ["/run/remediate.sh"] | |
env: | |
- name: HOSTPATH_VOLUME | |
value: /host | |
securityContext: | |
privileged: true | |
volumeMounts: | |
- name: hostpath-mount | |
mountPath: /host | |
- name: node-remediation | |
mountPath: /run/remediate.sh | |
subPath: remediate.sh | |
containers: | |
- image: "registry.tkg.vmware.run/pause:3.1" | |
name: pause | |
volumes: | |
- name: hostpath-mount | |
hostPath: | |
path: / | |
- name: node-remediation | |
configMap: | |
name: node-remediation | |
defaultMode: 0744 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment