Skip to content

Instantly share code, notes, and snippets.

@nuvious
Last active August 31, 2024 21:14
Show Gist options
  • Save nuvious/03e385c58c3c18489efc5fa2c4bd2fd4 to your computer and use it in GitHub Desktop.
Save nuvious/03e385c58c3c18489efc5fa2c4bd2fd4 to your computer and use it in GitHub Desktop.
NFS Stale Handle Liveness Probe
---
apiVersion: v1
data:
liveness.sh: |
#!/bin/bash
# Get list of nfs mounts
temp_file=$(mktemp)
# May need to change to nfs depending on base image
mount -t nfs4 > "$temp_file"
# Check every nfs mount
while read -r _ _ mount _; do
echo "Checking $mount"
if ! stat "$mount" > /dev/null 2>&1; then
# If a mount is inaccessible, exit 1 to fail the probe
echo "$mount is stale or not accessible"
exit 1
fi
done < "$temp_file"
rm "$temp_file"
exit 0
kind: ConfigMap
metadata:
creationTimestamp: null
name: liveness
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:latest
name: nginx
volumeMounts:
- name: html-root
mountPath: /usr/share/nginx/html
- name: liveness
mountPath: /usr/bin/liveness.sh
subPath: liveness.sh
resources: {}
ports:
- containerPort: 80
livenessProbe:
exec:
command:
- /bin/sh
- /usr/bin/liveness.sh
initialDelaySeconds: 30
periodSeconds: 60
timeoutSeconds: 5
volumes:
- name: html-root
nfs:
server: 192.168.1.200
path: /opt/nfs/nginx
readOnly: true
- name: liveness
configMap:
name: liveness
status: {}
#!/bin/bash
# Get list of nfs mounts
temp_file=$(mktemp)
# May need to change to nfs depending on base image
mount -t nfs4 > "$temp_file"
# Check every nfs mount
while read -r _ _ mount _; do
echo "Checking $mount"
if ! stat "$mount" > /dev/null 2>&1; then
# If a mount is inaccessible, exit 1 to fail the probe
echo "$mount is stale or not accessible"
exit 1
fi
done < "$temp_file"
rm "$temp_file"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment