gpt4 book ai didi

how to put secrets into a configMap with podman play kube(如何使用Podman Play Kube将秘密输入到配置映射中)

转载 作者:bug小助手 更新时间:2023-10-25 16:42:16 38 4
gpt4 key购买 nike



This is for podman play kube local-stack.yaml which has a postgres and grafana server

这是podman播放kube本地堆栈.yaml,它有一个postgres和grafana服务器


I want to create a distinct grafana user & password for the database, how can I make the ConfigMap include a password (even if it's insecure, this is local-stack.yaml -- not fort knox).

我想为数据库创建一个独特的grafana用户名和密码,如何使ConfigMap包含密码(即使它不安全,这是local-stack.yaml--而不是诺克斯堡)。


Based on other stack overflow answers I don't think podman ConfigMaps can have any interpolation done, and almost certainly NOT from a secret vault.

基于其他堆栈溢出的答案,我不认为podman配置地图可以做任何插值,几乎可以肯定不是从一个秘密金库。


---
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-init-db-script
data:
init-db-script.sql: |
CREATE DATABASE grafana_db;
CREATE USER grafana_user WITH ENCRYPTED PASSWORD '${GRAFANA_DB_PASSWORD}';
GRANT ALL PRIVILEGES ON DATABASE grafana_db TO grafana_user;

...
## the database
- name: postgres
image: postgres
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
value: "admin"
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-vault
key: pg_password
- name: GRAFANA_DB_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-vault
key: gf_password
- name: POSTGRES_DB
value: "postgres"
volumeMounts:
# If you would like to do additional initialization in an image derived from this one, add one or more *.sql, *.sql.gz, or *.sh scripts under /docker-entrypoint-initdb.d
- name: postgres-init-db-script
mountPath: /docker-entrypoint-initdb.d
- name: postgres-storage
mountPath: /var/lib/postgresql/data
...

I will update back here when I figure out a good answer.

当我找到一个好的答案时,我会在这里更新的。


I attempted to put the GF_DB_PASSWORD into the environment variable, that didn't work (the file written to the volume doesn't have the value interpolated)

我尝试将GF_DB_PASSWORD放入环境变量中,但没有成功(写入卷的文件没有内插值)


更多回答

⚠️ I want to remind future me that when testing the /docker-entrypoint-initdb.d scripts only run when the volume is empty! podman volume rm postgres-pvc

⚠️我想提醒您,在测试/docker-入口点-initdb.d脚本时,只有在卷为空时才会运行!波德曼音量RM Postgres-聚氯乙烯

优秀答案推荐

My best workable solution for an extremely insecure local-stack.yaml, with podman play kube is

对于极其不安全的本地stack.yaml和podman play Kube,我的最佳可行解决方案是


apiVersion: v1
kind: ConfigMap
metadata:
name: extremely-insecure-env
data:
POSTGRES_PASSWORD: bar
GF_DATABASE_PASSWORD: baz
---
apiVersion: v1
kind: Pod
metadata:
name: local-stack
spec:
initContainers:
- name: set-permissions
image: busybox
volumeMounts:
- name: postgres-init-db-script
mountPath: /docker-entrypoint-initdb.d
command: ["/bin/sh", "-c"]
args:
- "chmod +x /docker-entrypoint-initdb.d/init-db-script.sh"
containers:
## the database
- name: postgres
image: postgres
ports:
- containerPort: 5432
envFrom:
- configMapRef:
name: extremely-insecure-env
optional: false
env:
- name: POSTGRES_USER
value: "admin"
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-vault
key: pg_password
# we get GRAFANA_DB_PASSWORD from the extremely-insecure-env
# - name: GRAFANA_DB_PASSWORD
# valueFrom:
# secretKeyRef:
# name: postgres-vault
# key: gf_password
- name: POSTGRES_DB
value: "postgres"

volumeMounts:
# If you would like to do additional initialization in an image derived from this one, add one or more *.sql, *.sql.gz, or *.sh scripts under /docker-entrypoint-initdb.d
- name: postgres-init-db-script
mountPath: /docker-entrypoint-initdb.d
- name: postgres-storage
mountPath: /var/lib/postgresql/data


---
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-init-db-script
data:
init-db-script.sh: |
#!/bin/bash

# Connect to the PostgreSQL database using psql and execute the commands separately to avoid transaction block issues
psql -U "${POSTGRES_USER}" -d "${POSTGRES_DB}" -c "CREATE DATABASE grafana_db;"
psql -U "${POSTGRES_USER}" -d grafana_db -c "CREATE USER grafana_user WITH ENCRYPTED PASSWORD '${GF_DATABASE_PASSWORD}';"
psql -U "${POSTGRES_USER}" -d grafana_db -c "GRANT ALL PRIVILEGES ON DATABASE grafana_db TO grafana_user;"


更多回答

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com