如何使用pvc创建postgres掌舵图

时间:2020-05-12 12:47:31

标签: kubernetes kubernetes-helm

我想用pvc创建postgres掌舵人,请让我知道如何做, 尝试片假https://www.katacoda.com/courses/kubernetes/helm-package-manager 用pvc创建Postgres掌舵图。

2 个答案:

答案 0 :(得分:2)

我们可以从PostgreSQL舵图文档中读取,它可以与以下parameters一起使用:

+----------------------------+-----------------------------------------------------------------+---------------+
|         Parameter          |                           Description                           |    Default    |
+----------------------------+-----------------------------------------------------------------+---------------+
| persistence.enabled        | Enable data persistence                                         | true          |
| persistence.existingClaim  | Use a existing PVC which must be created manually before bound  | nil           |
| persistence.storageClass   | Specify the storageClass used to provision the volume           | nil           |
| persistence.mountPath      | Path to mount data volume at                                    | nil           |
| persistence.accessMode     | Access mode of data volume                                      | ReadWriteOnce |
| persistence.size           | Size of data volume                                             | 8Gi           |
| persistence.annotations    | Persistent Volume Claim annotations                             | {}            |
+----------------------------+-----------------------------------------------------------------+---------------+

持久性

默认情况下,数据使用PostgreSQL状态集中的PVC模板保留。您可以将persistence.enabled参数的持久性设置为false。 Kubernetes集群中需要默认的StorageClass来动态配置卷。在persistence.storageClass中指定另一个StorageClass,或者如果已经存在要使用的持久卷,则设置persistence.existingClaim

这意味着您只需要创建自己的Persistent Volume即可,例如:

pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"

pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi

一旦部署并限制了边界,就可以安装PostgreSQL图表:

helm install my-release bitnami/postgresql --set persistence.existingClaim=task-pv-claim

答案 1 :(得分:1)

我使用以下PVCvalues.yaml和Chart.yaml进行部署

pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: postgres-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 25Gi

values.yaml

postgresql:
  cpu: 1000m
  memory: 1Gi
  persistence:
    enabled: true
    existingClaim: postgres-pvc
  volumePermissions:
    enabled: true
  replication:
    enabled: false
  initdbScripts:
    psql.sql: |
      CREATE USER user WITH PASSWORD 'pass';
      ALTER USER user WITH SUPERUSER;

Chart.yaml

apiVersion: v2
name: pgname
description: A Short description

type: application

version: 0.1.3

appVersion: 1.16.2

dependencies:
  - name: postgresql
    version: 7.x.x
    repository: https://kubernetes-charts.storage.googleapis.com/
    condition: postgresql.enabled
    tags:
      - services
      - db
      - write

我在以下目录结构中有上述文件。

.
├── Chart.yaml
├── charts
│   └── postgresql-7.7.3.tgz
└── values.yaml

.,我执行helm dependency updatehelm install release_name .进行安装。在此之前kubectl apply -f pvc.yaml

注意 ,您需要在同一个命名空间中