Skip to content

Instantly share code, notes, and snippets.

@dmnt3d

dmnt3d/cli.sh

Forked from voor/cli.sh
Created May 2, 2020
Embed
What would you like to do?
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