Loading

K8s 部署 PostgreSQL

Config

apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
  namespace: postgres
  labels:
    app: postgres
data:
  POSTGRES_DB: master
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: postgres

PersistentVolume

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"

StatefulSet

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

Service

apiVersion: v1
kind: Service
metadata:
  name: postgres
  namespace: postgres
  labels:
    app: postgres
spec:
  ports:
    - port: 5432
      name: postgres
  type: LoadBalancer
  selector:
    app: postgres

$ 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

posted @ 2021-06-07 15:34  LB477  阅读(4385)  评论(0编辑  收藏  举报