使用kubectl apply命令重新配置postgres

时间:2019-03-04 08:12:05

标签: postgresql kubernetes kubectl minikube

我正在尝试更改本地minikube集群中的postgres数据库的设置。我错误地部署了数据库,但未指定postgres用户,密码和数据库。

问题:当我添加新的环境变量并使用kubectl apply -f postgres-deployment.yml时,postgres不会创建由环境变量指定的用户,密码或数据库。

这是部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: postgres
  template:
    metadata:
      labels:
        component: postgres
    spec:
      volumes:
        - name: postgres-storage
          persistentVolumeClaim:
            claimName: database-persistent-volume-claim
      containers:
        - name: postgres
          image: postgres
          ports:
            - containerPort: 5432
          volumeMounts:
            - name: postgres-storage
              mountPath: /var/lib/postgresql/data
              subPath: postgres
          env:
            - name: PGUSER
              value: admin
            - name: PGPASSWORD
              value: password
            - name: PGDATABSE
              value: testdb

应用部署文件时如何更改postgres的设置?

1 个答案:

答案 0 :(得分:0)

您可以共享Pod的日志吗?

kubectl logs <pod_name>

Postgres正在使用具有已定义变量名称的初始化脚本:

POSTGRES_USER
POSTGRES_PASSWORD
POSTGRES_DB

试试这个

apiVersion: v1
kind: ReplicationController
metadata:
  name: postgres
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:9.6
          env:
            - name: POSTGRES_USER
              value: admin
            - name: POSTGRES_PASSWORD
              value: password
            - name: POSTGRES_DB
              value: testdb
            - name: PGDATA
              value: /var/lib/postgresql/data/pgdata
          ports:
            - containerPort: 5432
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: pg-data
      volumes:
        - name: pg-data
          emptyDir: {}