k8s 部署 PostgRest

PostgREST是一个可以直接将你的PostgreSQL数据库直接提供RESTful API 的稳定WEB服务。数据库结构和约束决定API的端点和操作。

运行PostgREST ,你就可以通过http访问数据库数据了

参考yaml文件

可以通过以下yml文件直接部署

#请注意修改变量

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgrest
  namespace: {{ .namespace }}
  labels:
    app: postgrest
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: postgrest
  template:
    metadata:
      labels:
        app: postgrest
    spec:
      imagePullSecrets:
      - name: qingcloud-registry
      containers:
      - name: postgrest
        image: postgrest:v7.0.1  #可使用最新
        imagePullPolicy: IfNotPresent
        ports:
        - name: postgrest
          containerPort: 3000
          protocol: TCP
        env:
        - name:  PGRST_DB_URI
          value: {{ .pgrst_db_uri }}
        - name: PGRST_DB_SCHEMA
          value: {{ .pgrst_db_schema }}
        - name: PGRST_DB_ANON_ROLE
          value: {{ .pgrst_db_anon_role }}
        - name: PGRST_OPENAPI_SERVER_PROXY_URI
          value: {{ .pgrst_openapi_server_proxy_uri }}
        - name: PGRST_JWT_SECRET
          value: {{ .pgrst_jwt_secret }}
      - name: swagger
        image: harbor.querycap.com/rk-edc/swagger-ui:latest
        imagePullPolicy: IfNotPresent
        ports:
        - name: swagger-ui
          containerPort: 8080
          protocol: TCP
        env:
          - name: API_URL
            value: {{ .pgrst_openapi_server_proxy_uri }}
---
apiVersion: v1
kind: Service
metadata:
  name: postgrest
  namespace: {{ .namespace }}
  labels:
    app: postgrest
spec:
  type: NodePort
  ports:
  - port: 3000
    targetPort: 3000
    nodePort: 32009
    protocol: TCP
    name: postgrest
  - port: 8080
    targetPort: 8080
    nodePort: 32010
    protocol: TCP
    name: swagger-ui
  selector:
    app: postgrest

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: postgrest
  namespace: {{ .namespace }}
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false" 
spec:
  rules:
  - host: {{ .rest_url }}
    http:
      paths:
      - path: 
        pathType: ImplementationSpecific
        backend:
          service:
            name: postgrest
            port: 
              number: 3000
  - host: {{ .swg_url }}
    http:
      paths:
      - path: 
        pathType: ImplementationSpecific
        backend:
          service:
            name: postgrest
            port: 
              number: 8080

变量信息

namespace: namespace   #命名空间

pgrst_db_uri: postgres://user:password@db:5432/app_db

pgrst_db_schema: public

pgrst_db_anon_role: web_anon   #新建一个角色并授权

pgrst_openapi_server_proxy_uri: http://127.0.0.1:3000

pgrst_jwt_secret: 28doNH52304dsa1GlFjPUSOgalxrS8vilP   #目前不知道怎么设置的

rest_url: rest.xxxx.com    #rest域名

swg_url: swg.xxxx.com      #swg域名

更改以上变量然后直接在k8s集群中apply就完事儿了