【问题标题】:Deploying postgres in Kubernetes在 Kubernetes 中部署 postgres
【发布时间】:2021-02-22 15:29:29
【问题描述】:

我正在尝试将 Postgress 部署到 kubernetes 中。这是 postgres 部署 yaml 文件。

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres-statefulset
  labels:
    adr.app: airflow-postgres
    app: postgres
spec:
  serviceName: "postgres"
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:12
        envFrom:
        - configMapRef:
            name: postgres-configuration
        ports:
        - containerPort: 5432
          name: postgresdb
        volumeMounts:
        - name: pv-data
          mountPath: /var/lib/postgresql/data
      volumes:
      - name: pv-data
        persistentVolumeClaim:
          claimName: postgress-volume

配置图,

apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-configuration
  labels:
    app: postgres
data:
  POSTGRES_DB: airflow
  POSTGRES_USER: airflow_user
  POSTGRES_PASSWORD: airflow_pwd1234

kubectl get configmap -n postgres

NAME                     DATA   AGE
postgres-configuration   3      19h

我们使用 scaleio 存储类。

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: postgress-pvc-volume
  labels:
    app: airflow-postgres
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  storageClassName: scaleio
kubectl get pvc -n postgres
NAME               STATUS   VOLUME                            CAPACITY   ACCESS MODES   STORAGECLASS   AGE
postgress-pvc-volume   Bound    test-6b35f52e132e458c9b03   8Gi        RWO            scaleio        97m

kubectl descibe pvc postgress-pvc-volume -n postgres

Events:
  Type    Reason                 Age                From                                                                                                Message
  ----    ------                 ----               ----                                                                                                -------
  Normal  ExternalProvisioning   21s (x2 over 21s)  persistentvolume-controller                                                                         waiting for a volume to be created, either by external provisioner "scaleio.aci.apple.com" or manually created by system administrator
  Normal  Provisioning           21s (x2 over 21s)  scaleio.aci.apple.com_csi-scaleio-controller-7ccf4b87bd-6zhws_0dfb47e3-369b-4c5f-8c8c-81bb3e5c276f  External provisioner is provisioning volume for claim "cse-ce-alloyd/postgress-pvc-volume"
  Normal  ProvisioningSucceeded  21s (x2 over 21s)  scaleio.aci.apple.com_csi-scaleio-controller-7ccf4b87bd-6zhws_0dfb47e3-369b-4c5f-8c8c-81bb3e5c276f  Successfully provisioned volume us-west-2a-ddade2aa51f1434abbb7

kubectl 描述 pod postgres -n postgres

Volumes:
  pv-data:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  postgress-pvc-volume
    ReadOnly:   false
  default-token-8m97k:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-8m97k
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason                  Age              From                     Message
  ----     ------                  ----             ----                     -------
  Normal   Scheduled               23s              default-scheduler        Successfully assigned cse-ce-alloyd/postgres-statefulset-0 to port--10260.test.com
  Normal   SuccessfulAttachVolume  23s              attachdetach-controller  AttachVolume.Attach succeeded for volume "us-west-2a-ddade2aa51f1434abbb7"
  Normal   Generated               13s              appcertfetcher           Application certificate generated
  Normal   Pulling                 13s              kubelet                  Pulling image "postgres:12"
  Normal   Pulled                  3s               kubelet                  Successfully pulled image "postgres:12"
  Normal   Pulled                  2s               kubelet                  Container image "postgres:12" already present on machine
  Normal   Created                 1s (x2 over 3s)  kubelet                  Created container postgres
  Normal   Started                 1s (x2 over 3s)  kubelet                  Started container postgres
  Warning  BackOff                 1s               kubelet                  Back-off restarting failed container

Pod 错误:-

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data/pgdata ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 20
selecting default shared_buffers ... 400kB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... Bus error
child process exited with exit code 135
initdb: removing contents of data directory "/var/lib/postgresql/data/pgdata"

我是 postgress 新手,不知道如何进一步发展。

【问题讨论】:

  • 我想知道一些 pv/pvc 定义实际上去了哪里。在部署 postgres 之前,您是否也部署了它们?在这种情况下也附上它。
  • 更新了新的部署
  • 实际上我仍然诊断出一些卷配置错误。 pv 大小是否与 pvc 大小匹配?
  • 我们创建 PVC,PV 由 kubernetes 团队控制。
  • @user1578872 你解决问题了吗?

标签: postgresql kubernetes deployment containers


【解决方案1】:

我不知道你用的是helm还是其他工具,但为什么不使用已经开发好的解决方案呢?

查看此存储库(googleapis 和 bitnami)

https://github.com/helm/charts/tree/master/stable/postgresql

https://github.com/bitnami/charts/tree/master/bitnami/postgresql

您可以将其用作图表中的依赖项并通过 values.yaml 注入配置

【讨论】:

    猜你喜欢
    • 2020-09-21
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 2021-11-27
    • 2019-06-25
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    相关资源
    最近更新 更多