当前位置: 首页 > news >正文

k8s安装hostPath方式存储的PostgreSQL15

1.配置 PostgreSQL 的 ConfigMap

cat > postgres-configmap.yaml << EOF
apiVersion: v1
kind: ConfigMap
metadata:name: postgres-configlabels:app: postgresnamespace: dev
data:POSTGRES_DB: postgresdbPOSTGRES_USER: postgresadminPOSTGRES_PASSWORD: admin12345
EOFkubectl create -f postgres-configmap.yaml 

2. 持久化卷 Persistent Storage Volume

在这里,我们使用本地目录/路径作为永久存储资源(/mnt/data)

cat > postgres-pv-pvc.yaml << EOF
kind: PersistentVolume
apiVersion: v1
metadata:name: postgres-pv-volumelabels:type: localapp: postgres
spec:storageClassName: manualcapacity:storage: 5GiaccessModes:- ReadWriteManyhostPath:path: "/mnt/data"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:name: postgres-pv-claimlabels:app: postgres
spec:storageClassName: manualaccessModes:- ReadWriteManyresources:requests:storage: 5Gi
EOFkubectl apply -f  postgres-pv-pvc.yaml

3. PostgreSQL Deployment

cat >  postgres-deployment.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:name: postgres-deployment
spec:strategy:type: Recreateselector:matchLabels:app: postgresreplicas: 1template:metadata:labels:app: postgresspec:containers:- name: postgresimage:  postgres:15.3imagePullPolicy: "IfNotPresent"ports:- containerPort: 5432envFrom:- configMapRef:name: postgres-configvolumeMounts:- mountPath: /var/lib/postgresql/dataname: postgredbvolumes:- name: postgredbpersistentVolumeClaim:claimName: postgres-pv-claim
EOFkubectl apply -f  postgres-deployment.yaml            

4. PostgreSQL Service

cat > postgres-service.yaml << EOF
apiVersion: v1
kind: Service
metadata:name: postgres-servicelabels:app: postgres
spec:type: NodePortports:- port: 5432targetPort: 5432protocol: TCPselector:app: postgres
EOFkubectl create -f postgres-service.yaml 
  1. 查看运行结果
# kubectl get svc postgres
NAME               TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
postgres-service   NodePort   10.245.62.239   <none>        5432:32312/TCP   6h10m
http://www.lryc.cn/news/274886.html

相关文章:

  • 51单片机之按键和数码管
  • 【Oracle】 - 数据库的实例、表空间、用户、表之间关系
  • ssm基于HTML5的交流论坛的设计与实现+vue论文
  • JDBC*
  • Zookeeper注册中心实战
  • 1-02VS的安装与测试
  • ctfshow——PHP特性
  • K8S陈述式资源管理
  • 详解Python内置函数 !!!
  • 使用Vue3 + Vite创建uni-app项目(Webstorm)
  • 【js】js实现多个视频连续播放:
  • 使用openssl 生成pfx格式证书时报错:unable to load certificates
  • 微信小程序 分享按钮 监听用户分享成功
  • 数据结构-怀化学院期末题
  • 跟cherno手搓游戏引擎【1】:配置与入口点
  • 25计算机专业考研经验贴之准备篇
  • 机器人相关知识
  • 八股文打卡day22——操作系统(5)
  • SQL Server 权限管理
  • ReentrantLock底层原理学习一
  • 数字孪生在增强现实(AR)中的应用
  • 【数据仓库与联机分析处理】多维数据模型
  • 【网络面试(3)】浏览器委托协议栈完成消息的收发
  • Kotlin: Jetpack — ViewModel简单应用
  • 【Java技术专题】「攻破技术盲区」攻破Java技术盲点之unsafe类的使用指南(打破Java的安全管控— sun.misc.unsafe)
  • 私有云平台搭建openstack和ceph结合搭建手册
  • debug mccl 02 —— 环境搭建及初步调试
  • ros python 接收GPS RTK 串口消息再转发 ros 主题消息
  • 2024年网络安全竞赛-页面信息发现任务解析
  • ARM DMA使用整理