Reputation: 7829
I have a yaml file that creates a namespace, a persistent volume, a persistent volume claim and a statefulset that uses the pvc. When I run this file with kubectl apply -f myfile.yaml
, I don't get any errors.
apiVersion: v1
kind: Namespace
metadata:
name: mynamespace
---
apiVersion: v1
kind: PersistentVolume
metadata:
namespace: mynamespace
name: postgres-pv
labels:
name: postgres-volume
spec:
storageClassName: manual # same storage class as pvc
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
server: 10.0.0.11 # ip addres of nfs server
path: "/mnt/kubernetes-nfs-volume/customer1/postgres" # path to directory
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: mynamespace
name: postgres-pvc
labels:
name: postgres-volume
spec:
storageClassName: manual
accessModes:
- ReadWriteMany # must be the same as PersistentVolume
resources:
requests:
storage: 5Gi
---
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-configuration
namespace: mynamespace
labels:
app: postgres
data:
POSTGRES_DB: databasename
POSTGRES_USER: mydatabaseuser
POSTGRES_PASSWORD: mysupersecretpassword
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
namespace: mynamespace
name: postgres-statefulset
labels:
app: postgres
spec:
serviceName: "postgres"
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:13
envFrom:
- configMapRef:
name: postgres-configuration
ports:
- containerPort: 5432
name: postgresdb
volumeMounts:
- name: pv-data
mountPath: /var/lib/postgresql/data
volumes:
- name: pv-data
persistentVolumeClaim:
claimName: postgres-pvc
---
apiVersion: v1
kind: Service
metadata:
namespace: mynamespace
name: postgres
labels:
app: postgres
spec:
type: NodePort
ports:
- port: 5432
selector:
app: postgres
Next, when I run kubectl describe -n mynamespace postgres-statefulset
, I get the following output:
Looks good so far! However, running kubectl get statefulset -n mynamespace
returns this:
What am I doing wrong? Also, the PV and PVC have been set up correctly, as I can use them with an nginx deployment for testing purposes succesfully. I have deleted everything in my cluster before running this script.
The output of kubectl get events -n mynamespace
is as follows:
Upvotes: 0
Views: 2298
Reputation: 7829
Found it out myself. On the fileserver with the NFS disk, I had to update /etc/exports
to include no_root_squash
on the folder that the postgres container uses as a mount. I figured this out by checking the logs of the pod, which had the error message chown: changing ownership of ‘/var/lib/postgresql/data’: Operation not permitted
and googling that error.
Upvotes: 1