k8s启动单点postgre
文章目录
- 创建yaml文件如下:
注意:因为我的k8s中设置了默认storageclass,所以yml文件中没有pv
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: harbocto.xxx.com.cn/public/postgres:12.4
imagePullPolicy: IfNotPresent
env:
- name: POSTGRES_PASSWORD
value: "liubei@2021"
- name: POSTGRES_USER
value: "liubei"
- name: POSTGRES_DB
value: "liubeidb"
ports:
- containerPort: 5432
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-data
persistentVolumeClaim:
claimName: postgres
---
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: postgres
spec:
type: NodePort
ports:
- port: 5432
targetPort: 5432
nodePort: 30200
selector:
app: postgres
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres
namespace: postgres
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi