写在最前

PostgreSQL(结合PostGIS扩展)是地理信息系统(GIS)领域的首选开源数据库解决方案,为空间数据存储、分析和可视化提供专业级支持

核心能力:

🌍 全功能空间引擎

  • 支持矢量/栅格数据、三维地理信息、拓扑网络

  • 提供600+空间函数(缓冲区分析、路径规划、空间聚合等)

📊 行业标准兼容

  • 符合OGC标准,兼容GeoJSON、KML、Shapefile等格式

  • 与QGIS、ArcGIS、GeoServer等工具无缝集成

高性能处理

  • 空间索引(R树/GIST)加速查询

  • 并行计算支持亿级空间数据分析

🔗 官网postgis.net
📌 推荐组合:PostgreSQL + PostGIS + QGIS + GeoServer

1. 前置要求

2. docker 部署

3. kubernetes 部署

目前实验就使用单机部署postgres,使用hostpath方式存储数据。

3.1 deployment

kind: Deployment
apiVersion: apps/v1
metadata:
  name: postgres
  namespace: default
  labels:
    app: postgres
  annotations:
    deployment.kubernetes.io/revision: '3'
    kubesphere.io/creator: admin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: postgres
      annotations:
        kubesphere.io/creator: admin
        kubesphere.io/imagepullsecrets: '{}'
    spec:
      volumes:
        - name: postgres-storage
          hostPath:
            path: /data/postgres
            type: DirectoryOrCreate
      containers:
        - name: postgres
          image: >-
            swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/postgres:17.5-alpine
          ports:
            - name: tcp-5432
              containerPort: 5432
              protocol: TCP
          env:
            - name: POSTGRES_PASSWORD
              value: '123456'
            - name: POSTGRES_USER
              value: postgres
            - name: POSTGRES_DB
              value: mydatabase
          resources: {}
          volumeMounts:
            - name: postgres-storage
              mountPath: /var/lib/postgresql/data
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600

3.2 service

方便调试我就是用NodePort暴露端口

kind: Service
apiVersion: v1
metadata:
  name: postgres
  namespace: default
  annotations:
    kubesphere.io/creator: admin
spec:
  ports:
    - protocol: TCP
      port: 5432
      targetPort: 5432
      nodePort: 30650
  selector:
    app: postgres
  clusterIP: 10.233.35.194
  clusterIPs:
    - 10.233.35.194
  type: NodePort
  sessionAffinity: None
  externalTrafficPolicy: Cluster
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  internalTrafficPolicy: Cluster