【问题标题】:Kubernetes env-fileKubernetes 环境文件
【发布时间】:2020-03-13 16:33:28
【问题描述】:

env.example

MYSQL_PASSWORD=password
MYSQL_DATABASE=db
MYSQL_ROOT_PASSWORD=password
MYSQL_USER=user

我创造了秘密

kubectl create secret generic prod-secrets --from-file=env.example

mysql yaml 文件中指定的秘密

spec:
      containers:
      - name: mysql-container
        image: mysql:dev
        imagePullPolicy: "IfNotPresent"
        envFrom:
          - secretRef:
             name: prod-secrets
        ports:
        - containerPort: 3306
         # container (pod) path
        volumeMounts:
          - name: mysql-persistent-storage
            mountPath: /data/db

Pod 进入CrashLoopBackOff

这是来自kubectl describe pod

环境变量来自:

prod-secrets Secret 可选:false

环境:

这个设置有什么问题?

秘密输出:

kubectl describe secret prod-secrets
Name:         prod-secrets
Namespace:    default
Labels:       <none>
Annotations:  <none>

Type:  Opaque

Data
====
env.example:  96 bytes

编辑

在尝试了回答的建议后,pod 仍然崩溃

mysql-container-ffdc44fc6-w9qqm     0/1     Error     1          23s
mysql-container-ffdc44fc6-w9qqm     0/1     CrashLoopBackOff   1          34s
mysql-container-ffdc44fc6-w9qqm     1/1     Running            2          34s
mysql-container-ffdc44fc6-w9qqm     0/1     Error              2          44s
mysql-container-ffdc44fc6-w9qqm     0/1     CrashLoopBackOff   2          56s
mysql-container-ffdc44fc6-w9qqm     1/1     Running            3          72s
mysql-container-ffdc44fc6-w9qqm     0/1     Error              3          82s

秘密显示正确

kubectl describe secret prod-secrets
Name:         prod-secrets
Namespace:    default
Labels:       <none>
Annotations:  <none>

Type:  Opaque

Data
====
MYSQL_DATABASE:       7 bytes
MYSQL_PASSWORD:       8 bytes
MYSQL_ROOT_PASSWORD:  8 bytes
MYSQL_USER:           4 bytes

我只运行 1 节点集群(1 个主节点),这会导致这个问题吗?

找到并发布:

在 env 文件中将 root 指定为 DB_USER,一旦我更改它就开始工作了

【问题讨论】:

  • kubectl 的输出描述了秘密 prod-secrets
  • 刚刚发布,谢谢

标签: kubernetes kubectl


【解决方案1】:

使用选项 --from-env-file

创建密钥
kubectl create secret prod-secrets \
       --from-env-file=env.example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-06
    • 2019-10-26
    • 1970-01-01
    • 2022-11-05
    • 1970-01-01
    • 2019-10-05
    • 2020-04-07
    • 2018-06-13
    相关资源
    最近更新 更多