Skip to content

Instantly share code, notes, and snippets.

@voor
Created April 29, 2020 20:52
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save voor/65a92645cba6d29a1db34cc456d042c8 to your computer and use it in GitHub Desktop.
Node remediation with the magic of chroot
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
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