K8s 部署 PostgreSQL

1.Config

bash 复制代码
apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
  namespace: postgres
  labels:
    app: postgres
data:
  POSTGRES_DB: master
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: postgres

2. PersistentVolume

bash 复制代码
apiVersion: v1
kind: PersistentVolume
metadata:
  name: postgres-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  nfs:
    server: 192.168.11.210
    path: "/nfs/postgre-pv"

3.StatefulSet

bash 复制代码
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
  namespace: postgres
spec:
  serviceName: "postgres"
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:9.5
          envFrom:
            - configMapRef:
                name: postgres-config
          ports:
            - containerPort: 5432
              name: postgredb
          volumeMounts:
            - name: postgres-data
              mountPath: /var/lib/postgresql/data
              subPath: postgres
  volumeClaimTemplates:
    - metadata:
        name: postgres-data
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 2Gi

4.Service

bash 复制代码
apiVersion: v1
kind: Service
metadata:
  name: postgres
  namespace: postgres
  labels:
    app: postgres
spec:
  ports:
    - port: 5432
      name: postgres
  type: LoadBalancer
  selector:
    app: postgres

5.运行和验证

bash 复制代码
# kubectl create ns postgres
# kubectl create -f xxxx
# kubectl get service -n postgres
NAME       TYPE           CLUSTER-IP    EXTERNAL-IP      PORT(S)          AGE
postgres   LoadBalancer   10.43.81.59   192.168.11.210   5432:31919/TCP   40s
相关推荐
JunLan~1 小时前
Rocky Linux 系统安装/部署 Docker
linux·docker·容器
小袁搬码5 小时前
Windows中指定路径安装DockerDesktop
windows·docker·容器·docker desktop
qq_312920115 小时前
docker 部署 kvm 图形化管理工具 WebVirtMgr
运维·docker·容器
踏雪Vernon5 小时前
[OpenHarmony5.0][Docker][环境]OpenHarmony5.0 Docker编译环境镜像下载以及使用方式
linux·docker·容器·harmonyos
条纹布鲁斯6 小时前
dockerdsktop修改安装路径/k8s部署wordpress和ubuntu
docker·kubernetes
程序员学习随笔8 小时前
PostgreSQL技术内幕19:逻辑备份工具pg_dump、pg_dumpall
数据库·postgresql
CP-DD8 小时前
Docker 容器化开发 应用
运维·docker·容器
老司机张师傅9 小时前
【微服务实战之Docker容器】第七章-Dockerfile解析
容器·dockerfile·虚悬镜像·docker学习
登云时刻10 小时前
Kubernetes集群外连接redis集群和使用redis-shake工具迁移数据(一)
redis·kubernetes·bootstrap
吴半杯11 小时前
gateway漏洞(CVE-2022-22947)
docker·kubernetes·gateway