I want to setup a in-cluster NFS-Server in Kubernetes to provide shares for my pods (nginx webroot etc.).
In theory there should be a persistent volume, a volume claim and the NFS-Server, which, as I understand is a deployment.
To use the PV and PVC I need to assign the NFS-Server's IP-Adress, which I don't know, because it automatically generated when I expose the NFS-Server with a service.
The same problem appears if I want to deploy the nfs-server deployment itself, because I am using the PVC as volumes. But I can't deploy the PV and PVCs without giving them the NFS-Server IP.
I think I am lost, maybe you can help me.
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-nfs-pv1
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
path: "/exports/www"
server: SERVER_NAME:PORT
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-nfs-pv1
labels:
type: local
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 500Mi
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nfs-server
spec:
replicas: 1
selector:
matchLabels:
role: nfs-server
template:
metadata:
labels:
role: nfs-server
spec:
containers:
- name: nfs-server
image: gcr.io/google_containers/volume-nfs:0.8
ports:
- name: nfs
containerPort: 2049
- name: mountd
containerPort: 20048
- name: rpcbind
containerPort: 111
securityContext:
privileged: true
volumeMounts:
- mountPath: /exports/www
name: pv-nfs-pv1
volumes:
- name: pv-nfs-pv1
gcePersistentDisk:
pdName: pv-nfs-pv1
# fsType: ext4
1) You create NFS-server deployment.
2) You expose NFS-server deployment by creating service, say "nfs-server", exposing TCP port 2049 (assuming you use NFSv4).
3) You create PV with the following information:
nfs:
path: /exports/www
server: nfs-server
4) You create PVC and mount it wherever you need it.