How to persist postgresql through nfs-server on kuebernetes
Today, I will talk to you about how to persist postgresql through nfs-server on kuebernetes. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Kubernetes provides a variety of ways to persist data. See the official website here that we use nfs-server to persist data. Just start deploying our Postgresql.
1. Initialize the configuration of postgresql
File: 01-postgresql-configmap.yaml
ApiVersion: v1
Kind: ConfigMap
Metadata:
Name: postgres-config
Namespace: kube-ops
Labels:
App: postgres-prom
Data:
POSTGRES_DB: postgresdb
POSTGRES_USER: postgresadmin
POSTGRES_PASSWORD: admin1232. Create the corresponding storage volume
File: 02-postgresql-pv.yaml, note here that we need to prepare nfs-server in advance and expose the / data directory for network storage
ApiVersion: v1
Kind: PersistentVolume
Metadata:
Name: postgres-pv-volume
Spec:
Capacity:
Storage: 10Gi
AccessModes:
-ReadWriteOnce
PersistentVolumeReclaimPolicy: Recycle
Nfs:
Server: 192.168.10.234path: / data
-
ApiVersion: v1
Kind: PersistentVolumeClaim
Metadata:
Name: postgres-pv-claim
Namespace: kube-ops
Spec:
AccessModes:
-ReadWriteOnce
Resources:
Requests:
Storage: 10Gi3. Deploy PostgraSQL
When existing services use nfs as local persistent storage, we initialize errors when we start postgresql directly, so we can use subPath: postgresql to distinguish
File: 03-postgresql-dp.yaml
ApiVersion: extensions/v1beta1
Kind: Deployment
Metadata:
Name: postgres-prom
Namespace: kube-ops
Spec:
Replicas: 1template:
Metadata:
Labels:
App: postgres-prom
Spec:
Containers:
-name: postgres
Image: postgres:10.4imagePullPolicy: "IfNotPresent" ports:
-containerPort: 5432envFrom:
-configMapRef:
Name: postgres-config
VolumeMounts:
-mountPath: / var/lib/postgresql/data
SubPath: postgresql
Name: postgredb
Volumes:
-name: postgredb
PersistentVolumeClaim:
ClaimName: postgres-pv-claim4. Expose postgresql services
File: 04-postgresql-svc.yaml
ApiVersion: v1
Kind: Service
Metadata:
Name: postgres
Namespace: kube-ops
Labels:
App: postgres-prom
Spec:type: NodePort
Ports:
-port: 5432selector:
App: postgres-prom
These are the files needed to deploy postgresql, and when everything is ready, we can begin to deploy
Kubectl apply-f.
➜13-1-postgresql git: (master) ✗ (☸ kubernetes-admin@kubernetes:default) k get pods-n kube-ops-o wide-l app=postgres-prom
NAME READY STATUS RESTARTS AGE IP NODE
Postgres-prom-6f54c97948-fp8th 1/1 Running 0 18m 10.244.2.63 dev-k8s-node1
After reading the above, do you have any further understanding of how to persist postgresql through nfs-server on kuebernetes? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.