小编h1a*_*bel的帖子

使用 Kubernetes Secret for PostgreSQL ENV 导致应用程序 Pod 崩溃

我在将 Kubernetes Secret 的值注入 Pod env 时遇到问题。我有以下内容pg-secrets.yml

apiVersion: v1
kind: Secret
metadata:
  name: pg-secrets
type: Opaque
data:
  POSTGRES_USER: cG9zdGdyZXMK
  POSTGRES_PASSWORD: cGFzc3dvcmQK
#   postgres & password
Run Code Online (Sandbox Code Playgroud)

然后我将 POSTGRES_PASSWORD 从它注入到application-deployment.ymlENV:

apiVersion: apps/v1
kind: Deployment
   ...
    spec:
      containers:
        - name: realo
          image: abialiauski/realo
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
          env:
            - name: PG_USERNAME
              valueFrom:
                configMapKeyRef:
                  name: realo-configmap
                  key: PG_USERNAME
            - name: PG_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: pg-secrets
                  key: POSTGRES_PASSWORD
            - name: PG_HOST
              value: postgres
Run Code Online (Sandbox Code Playgroud)

并有这个application.yml

spring:
  application:
    name: …
Run Code Online (Sandbox Code Playgroud)

java postgresql spring-boot kubernetes kubernetes-secrets

1
推荐指数
1
解决办法
590
查看次数