Deploying in kubernetes, using hostpath mount directory without permission to create
noovertime7 opened this issue · comments
noovertime7 commented
Because there is no strogeclass in my k8s environment, so I use hostpath to mount /go/bin/data directory, the program failed to start, the error message I put in the screenshot, I commented out the #securityContext: related content, still there will be permission problems, hope to get a reply, thanks
Prabhat Sharma commented
Try this. Its working for me. Not the best choice, but should get you going in the interim.
# create statefulset
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: zinc
namespace: zinc-hostpath
labels:
name: zinc
spec:
serviceName: z
replicas: 1
selector:
matchLabels:
name: zinc
app: zinc
template:
metadata:
labels:
name: zinc
app: zinc
spec:
securityContext:
fsGroup: 2000
runAsUser: 0
runAsGroup: 3000
runAsNonRoot: false
containers:
- name: zinc
image: public.ecr.aws/h9e2j3o7/zinc:latest
env:
- name: ZINC_FIRST_ADMIN_USER
value: admin
- name: ZINC_FIRST_ADMIN_PASSWORD
value: Complexpass#123
- name: ZINC_DATA_PATH
value: /go/bin/data
# command: ["/bin/bash", "-c", "while true; do sleep 1; done"]
imagePullPolicy: Always
resources:
limits:
cpu: 1024m
memory: 2048Mi
requests:
cpu: 32m
memory: 50Mi
ports:
- containerPort: 4080
name: http
volumeMounts:
- name: data
mountPath: /go/bin/data
volumes:
- name: data
hostPath:
# directory location on host
path: /var/local
# this field is optional
type: DirectoryOrCreate