SSHFS Mount for k8s - Alpine-based image to help mounting remote directories via SSHFS in k8s pods
1.0K
A lightweight Alpine-based Docker image for mounting remote directories via SSHFS in Kubernetes pods.
| Variable | Required | Default | Description |
|---|---|---|---|
REMOTE_HOST | Yes | - | SSH server hostname or IP |
REMOTE_USER | Yes | - | SSH username |
REMOTE_PATH | Yes | - | Remote directory path to mount |
MOUNT_POINT | No | /books | Local mount point |
SSH_KEY_PATH | No | /ssh-key/ssh-privatekey | Path to SSH private key |
SSHFS_OPTIONS | No | See below | SSHFS mount options |
Default SSHFS Options:
allow_other,default_permissions,ro,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3
apiVersion: apps/v1
kind: Deployment
metadata:
name: ebook-browser
namespace: ebook-browser
spec:
replicas: 1
selector:
matchLabels:
app: ebook-browser
template:
metadata:
labels:
app: ebook-browser
spec:
securityContext:
fsGroup: 1001
initContainers:
- name: sshfs-mount
image: bbdrummer/sshfs-mount-k8s:latest
securityContext:
privileged: true
capabilities:
add:
- SYS_ADMIN
env:
- name: REMOTE_HOST
value: "your-server.com"
- name: REMOTE_USER
value: "bookuser"
- name: REMOTE_PATH
value: "/data/ebooks"
- name: MOUNT_POINT
value: "/books"
volumeMounts:
- name: books
mountPath: /books
mountPropagation: Bidirectional
- name: ssh-key
mountPath: /ssh-key
readOnly: true
containers:
- name: ebook-browser
image: your-app:latest
volumeMounts:
- name: books
mountPath: /books
readOnly: true
volumes:
- name: books
emptyDir: {}
- name: ssh-key
secret:
secretName: ebook-ssh-key
defaultMode: 0600
# Generate SSH key pair
ssh-keygen -t ed25519 -f ebook-ssh-key -N "" -C "ebook-browser@kubernetes"
# Add public key to remote server
ssh-copy-id -i ebook-ssh-key.pub [email protected]
# Create Kubernetes secret
kubectl create secret generic ebook-ssh-key \
--from-file=ssh-privatekey=ebook-ssh-key \
--namespace=ebook-browser
# Clean up local keys
rm ebook-ssh-key ebook-ssh-key.pub
docker build -t sshfs-mount-k8s:latest .
docker run --rm --privileged \
-e REMOTE_HOST=your-server.com \
-e REMOTE_USER=user \
-e REMOTE_PATH=/data \
-v /path/to/ssh-key:/ssh-key:ro \
sshfs-mount-k8s:latest
authorized_keysServerAliveInterval and ServerAliveCountMax valuesprivileged: true security contextSYS_ADMIN capability if privileged mode is restricted# Check init container logs
kubectl logs -n ebook-browser deployment/ebook-browser -c sshfs-mount
# Check if mount is active
kubectl exec -n ebook-browser deployment/ebook-browser -c ebook-browser -- mountpoint /books
ro (read-only) mount optionro option) when possibleSame as the parent project.
Content type
Image
Digest
sha256:4a4218932…
Size
7.7 MB
Last updated
8 months ago
docker pull bbdrummer/sshfs-mount-k8s