Reputation: 645
I am trying to mount remote path inside docker container image using sshfs, which will going to run on kubernetes cluster.
Problem
The issue is there is not error & after run the server nginx does not respond. If I comment the CMD
part its working.
Nginx Pod Status is CrashLoopBackOff
but when not running the sshfs, its working
Dockerfile-nginx
FROM nginx:1.20.2-alpine
RUN apk update && apk upgrade && apk add sshfs
COPY nginx/key.pem /home/files
RUN echo "user_allow_other" | tee -a /etc/fuse.conf
RUN mkdir -p /mnt/shared
RUN chmod 600 /home/files/key.pem
CMD sh -c "sshfs [email protected]:/home /mnt/shared -o debug -o allow_other -o idmap=user,uid=$(id -u),gid=$(id -g) -o ssh_command='ssh -i /home/files/key.pem -o StrictHostKeyChecking=no'"
Kubernetes Pod
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: kube_nginx:latest
imagePullPolicy: Never
ports:
- containerPort: 80
securityContext:
privileged: true
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
Thank you in advance
Upvotes: 1
Views: 1366
Reputation: 645
I resolved the issue.
If anyone facing this issue here is the entire code
Dockerfile-nginx
FROM nginx:1.20.2-alpine
RUN apk update && apk upgrade && apk add sshfs
COPY nginx/key.pem /home/files
RUN mkdir -p /mnt/shared
RUN chmod 600 /home/files/key.pem
CMD sh -c "sshfs [email protected]:/home /mnt/shared -o IdentityFile=/home/files/key.pem -o StrictHostKeyChecking=no && nginx -g 'daemon off;'"
Kubernetes Pod
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
hostPID: true
containers:
- name: nginx
image: kube_nginx:latest
imagePullPolicy: Never
ports:
- containerPort: 80
securityContext:
privileged: true
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
Upvotes: 1