apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pv-claim
namespace: ops
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 13Gi
storageClassName: xxxxx
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: ops
labels:
app: postgres
spec:
selector:
matchLabels:
app: postgres
replicas: 1
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/postgres:15-alpine
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 4
memory: 8000Mi
env:
- name: POSTGRES_PASSWORD
value: 'xxx'
- name: POSTGRES_USER
value: 'xxx'
- name: POSTGRES_DB
value: 'postgres'
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
ports:
- containerPort: 5432
name: postgresport
volumeMounts:
- name: localtime
mountPath: /etc/localtime
- name: data-disk
mountPath: /var/lib/postgresql/data
volumes:
- name: localtime
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
- name: data-disk
persistentVolumeClaim:
claimName: postgres-pv-claim
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: ops
spec:
selector:
app: postgres
type: NodePort
ports:
- name: postgres
port: 5432
targetPort:
protocol: TCP