k8s中安装PostgreSQL、pgadmin及yaml编写示例代码

2023-06-01 00:00:00 代码 示例 编写

k8s中安装PostgreSQL、pgadmin及yaml文件:

PostgreSQL的yaml文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: postgres
  name: postgres
  namespace: moonfdd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - env:
            - name: POSTGRES_PASSWORD
              value: "moonfdd"
          image: "postgres"
          imagePullPolicy: IfNotPresent
          name: postgres
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: volv
      volumes:
        - hostPath:
            path: /root/k8s/moonfdd/postgres/var/lib/postgresql/data
            type: DirectoryOrCreate
          name: volv
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: postgres
  name: postgres
  namespace: moonfdd
spec:
  ports:
    - port: 5432
      protocol: TCP
      targetPort: 5432
  selector:
    app: postgres
  type: NodePort

PostgreSQL测试截图:

postgresql1.png

postgresql2.png


pgadmin的yaml文件:

# 依赖postgres.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: pgadmin
  name: pgadmin
  namespace: moonfdd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pgadmin
  template:
    metadata:
      labels:
        app: pgadmin
    spec:
      containers:
        - env:
            - name: PGADMIN_DEFAULT_EMAIL
              value: "[email protected]"
            - name: PGADMIN_DEFAULT_PASSWORD
              value: "moonfdd"
          image: "dpage/pgadmin4"
          imagePullPolicy: IfNotPresent
          name: pgadmin
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: pgadmin
  name: pgadmin
  namespace: moonfdd
spec:
  ports:
    - port: 80
      protocol: TCP
      targetPort: 80
  selector:
    app: pgadmin
  type: NodePort

pgadmin测试截图:

pgadmin1.png

pgadmin2.png

相关文章