我在这里使用Arianit Uka的库伯内特斯Postgres StateulSet示例存储库:https://github.com/arianitu/postgres-statefulset
使用Minikube,我的pod容器没有出现。秘密已经应用,似乎有POSTGRES_PASSWORD
env var很好。回购的代码中没有密码=
,所以我迷失了问题所在。检查日志会发现:
> $ k logs postgres-0 --all-containers=true ⬡ 8.11.4 [±hauser ●●]
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 default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data/pgdata -l logfile start
waiting for server to start....2019-08-25 07:22:31.295 UTC [41] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-08-25 07:22:31.307 UTC [42] LOG: database system was shut down at 2019-08-25 07:22:31 UTC
2019-08-25 07:22:31.310 UTC [41] LOG: database system is ready to accept connections
done
server started
/usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/create-dev-db.sh
CREATE DATABASE
GRANT
/usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/create-replica-user.sh
CREATE ROLE
2019-08-25 07:22:31.751 UTC [41] LOG: received fast shutdown request
waiting for server to shut down....2019-08-25 07:22:31.752 UTC [41] LOG: aborting any active transactions
2019-08-25 07:22:31.753 UTC [41] LOG: worker process: logical replication launcher (PID 48) exited with exit code 1
2019-08-25 07:22:31.755 UTC [43] LOG: shutting down
2019-08-25 07:22:31.774 UTC [41] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2019-08-25 07:22:31.862 GMT [1] LOG: skipping missing configuration file "/etc/replica.conf"
2019-08-25 07:22:31.862 GMT [1] LOG: skipping missing configuration file "/etc/replica.conf"
2019-08-25 07:22:31.865 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2019-08-25 07:22:31.865 UTC [1] LOG: listening on IPv6 address "::", port 5432
2019-08-25 07:22:31.869 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-08-25 07:22:31.888 UTC [68] LOG: database system was shut down at 2019-08-25 07:22:31 UTC
2019-08-25 07:22:31.893 UTC [1] LOG: database system is ready to accept connections
2019-08-25 07:23:20.352 UTC [75] FATAL: role "password=" does not exist
2019-08-25 07:23:23.595 UTC [82] FATAL: role "password=" does not exist
以下是minikube仪表板的外观:
@Rahman,我取出了密码秘密,现在在< code > stateful set-master . yml 和< code > stateful set-replica . yml 中只使用普通值:
env:
...
- name: POSTGRES_PASSWORD
value: master-password
- name: REPLICATION_PASSWORD
value: replica-password
我还注释了服务中的副本部分。yml
因为我目前只对运行单个pod/数据库感兴趣:
service.yml
apiVersion: v1
kind: Service
metadata:
labels:
app: postgres
name: postgres
spec:
type: ClusterIP
ports:
- name: postgres
port: 5432
protocol: TCP
targetPort: 5432
selector:
app: postgres
# ---
# apiVersion: v1
# kind: Service
# metadata:
# labels:
# app: postgres-replica
# name: postgres-replica
# spec:
# type: ClusterIP
# ports:
# - name: postgres-replica
# port: 5432
# protocol: TCP
# targetPort: 5432
# selector:
# app: postgres-replica
# ---
statefulset-master.yml公司
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
spec:
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
app: postgres
serviceName: postgres
replicas: 1
template:
metadata:
labels:
app: postgres
spec:
volumes:
- name: postgres-config
configMap:
name: postgres
# - name: shared
# emptyDir: {}
terminationGracePeriodSeconds: 10
containers:
- name: postgres
image: postgres:10.5
args: ['-c', 'config_file=/etc/postgres.conf', '-c', 'hba_file=/etc/pg_hba.conf']
imagePullPolicy: IfNotPresent
ports:
- name: postgres
containerPort: 5432
protocol: TCP
resources:
requests:
cpu: 100m
memory: 256Mi
env:
- name: POSTGRES_USER
value: postgres
- name: PGUSER
value: postgres
- name: POSTGRES_DB
value: postgres
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
- name: POSTGRES_PASSWORD
value: master-password
# valueFrom:
# secretKeyRef:
# key: password
# name: postgres
- name: REPLICATION_PASSWORD
value: replica-password
# valueFrom:
# secretKeyRef:
# key: replicaPassword
# name: postgres
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
livenessProbe:
exec:
command:
- sh
- -c
- exec pg_isready --host $POD_IP
failureThreshold: 6
initialDelaySeconds: 60
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
readinessProbe:
exec:
command:
- sh
- -c
- exec pg_isready --host $POD_IP
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1
timeoutSeconds: 3
volumeMounts:
- mountPath: /var/lib/postgresql/data/pgdata
name: postgres
subPath: postgres-db
- name: postgres-config
mountPath: /etc/postgres.conf
subPath: postgres.conf
- name: postgres-config
mountPath: /etc/master.conf
subPath: master.conf
- name: postgres-config
mountPath: /etc/pg_hba.conf
subPath: pg_hba.conf
- name: postgres-config
mountPath: /docker-entrypoint-initdb.d/create-replica-user.sh
subPath: create-replica-user.sh
- name: postgres-config
mountPath: /docker-entrypoint-initdb.d/create-dev-db.sh
subPath: create-dev-db.sh
# - name: shared
# mountPath: /User/Shared
- name: hauser
image: mikeumus/hauser
# volumeMounts:
# - name: shared
# mountPath: /User/Shared
volumeClaimTemplates:
- metadata:
name: postgres
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: "standard"
resources:
requests:
storage: 3Gi
statefulset-replica.yml状态
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres-replica
spec:
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
app: postgres-replica
serviceName: postgres-replica
replicas: 1
template:
metadata:
labels:
app: postgres-replica
spec:
volumes:
- name: postgres-config
configMap:
name: postgres
terminationGracePeriodSeconds: 10
initContainers:
- name: setup-replica-data-directory
image: postgres:10.5
env:
- name: PGPASSWORD
valueFrom:
secretKeyRef:
key: replicaPassword
name: postgres
command:
- sh
- -c
- |
if [ -z "$(ls -A /var/lib/postgresql/data/pgdata)" ]; then
echo "Running pg_basebackup to catch up replication server...";
pg_basebackup -R -h postgres -D /var/lib/postgresql/data/pgdata -P -U replication;
chown -R postgres:postgres $PGDATA;
else
echo "Skipping pg_basebackup because directory is not empty";
fi
volumeMounts:
- mountPath: /var/lib/postgresql/data/pgdata
name: postgres-replica
subPath: postgres-db
containers:
- name: postgres-replica
image: postgres:10.5
args: ['-c', 'config_file=/etc/postgres.conf']
imagePullPolicy: IfNotPresent
ports:
- name: postgres-rep
containerPort: 5432
protocol: TCP
resources:
requests:
cpu: 100m
memory: 256Mi
env:
- name: POSTGRES_USER
value: postgres
- name: PGUSER
value: postgres
- name: POSTGRES_DB
value: postgres
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
- name: POSTGRES_PASSWORD
value: master-password
# valueFrom:
# secretKeyRef:
# key: password
# name: postgres
- name: REPLICATION_PASSWORD
value: replica-password
# valueFrom:
# secretKeyRef:
# key: replicaPassword
# name: postgres
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
livenessProbe:
exec:
command:
- sh
- -c
- exec pg_isready --host $POD_IP
failureThreshold: 6
initialDelaySeconds: 60
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
readinessProbe:
exec:
command:
- sh
- -c
- exec pg_isready --host $POD_IP
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1
timeoutSeconds: 3
volumeMounts:
- mountPath: /var/lib/postgresql/data/pgdata
name: postgres-replica
subPath: postgres-db
- name: postgres-config
mountPath: /etc/postgres.conf
subPath: postgres.conf
- name: postgres-config
mountPath: /etc/replica.conf
subPath: replica.conf
volumeClaimTemplates:
- metadata:
name: postgres-replica
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: "standard"
resources:
requests:
storage: 3Gi
配置/create_configmap.sh
kubectl create configmap postgres --from-file=postgres.conf --from-file=master.conf --from-file=replica.conf --from-file=pg_hba.conf --from-file=create-replica-user.sh --from-file=create-dev-db.sh
配置/创建副本 user.sh
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE ROLE replication WITH REPLICATION PASSWORD '$REPLICATION_PASSWORD' LOGIN
EOSQL
下面是我启动/应用资源的顺序:
Minikube启动
cd config
我得到一些丢失的错误,除非我在配置目录中执行此操作…/create_configmap.sh
cd…
k应用-f./config/secret.yml
k应用-f./service.yml
k应用-f./statefulset-master.yml
链接到我的< code > postgres-statefulset 回购分支:https://gitlab.com/mikeumus/postgres-statefulset
问题不在于postgres-stateful
代码。“password=
”代码位于我作为另一个容器添加到statefulset-master.yml
的Hauser代码中
我最近安装了Ubuntu的最新版本,还不习惯。我在连接PostgreSQL和PGADMIN3时遇到了几个问题。 我找不到,在这一点上,我太害怕尝试追随任何其他帖子而使事情变得更糟。 我怎么才能让这件事成功呢?
我是个新手。 我为Mac安装了Postgres.App。我在玩psql命令时不小心丢失了postgres数据库。我不知道里面是什么。 我目前正在编写一个教程:http://www.rosslaird.com/blog/building-a-project-with-mezzanine/ 而且我被困在 错误消息: 那么我应该采取哪些步骤呢?删除一个与psql相关的所有内容并重新安装所有内容? 谢谢你
我是新来postgres和面临的困难,在连接到数据库后服务器重启。我在一个OS用户测试下创建了一个数据库pgdb。服务器重启后,我通过发出命令重新启动pgsql 启动postgreql-9.6服务:[OK] 如果我只是发出psql,我会被带到psql提示符,但是这里的数据路径与我之前设置的不同。当我尝试以postgres用户的身份连接到pgdb时,我得到错误: psql: FATAL:数据库"pg
我是一个新的postgres和面临困难连接到数据库后,服务器重新启动。我已经在一个OS用户测试下创建了一个数据库pgdb。服务器重新启动后,我通过发出以下命令重新启动pgsql PSQL:致命:角色“测试”不存在 请建议
为什么IntelliJ不使用我的配置中指定的角色,而要使用我的个人登录??不管我用什么角色,还是犯了同样的错误。 注意:如果我添加我的系统用户名作为角色,它可以工作,但我更愿意避免这一点。
我正在设置我的PostgreSQL 9.1。我不能用PostgreSQL做任何事情:can't,can't;所有操作都返回错误消息 是我的帐户名,并且我在此帐户下PostgreSQL 9.1。 类似的错误对于帐户仍然存在。