简体   繁体   English

在 Secret default/mysql-secret 中找不到密钥 MYSQL_KEY

[英]couldn't find key MYSQL_KEY in Secret default/mysql-secret

I have the following file that creates a mysql-secret for mysql deployment pod.我有以下文件,它为mysql部署 pod 创建了一个mysql-secret

apiVersion: v1
kind: Secret
metadata:
  name: mysql-secret
type: Opaque
data:
  mysql-password: MTExMTEx
  mysql-root-password: MTExMTEx
  mysql-user: YQ==

The problem is that, previously I could deploy mysql on Kube.netes cluster using the secret key created by this command:问题是,以前我可以使用此命令创建的密钥在Kube.netes集群上部署mysql

kubectl create secret generic mysql-secret --from-literal MYSQL_KEY=11111

And using MYSQL_KEY I could pass it to other deployment files like auth as you can see below:使用MYSQL_KEY我可以将它传递给其他deployment文件,例如auth ,如下所示:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: auth
          env:
            - name: MYSQL_URI
              value: 'mysql://auth-mysql-srv:3306/users_auth'
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: MYSQL_KEY

But now I don't have a key using a yaml file to create the secret key and I get the following error because of that:但是现在我没有使用yaml文件创建密钥的密钥,因此出现以下错误:

 - deployment/auth-mysql-depl is ready. [3/5 deployment(s) still pending]
 - deployment/mysql: container mysql in error: &ContainerStateWaiting{Reason:CreateContainerConfigError,Message:couldn't find key MYSQL_KEY in Secret default/mysql-secret,}
    - pod/mysql-78bbf5f6f4-vbpkz: container mysql in error: &ContainerStateWaiting{Reason:CreateContainerConfigError,Message:couldn't find key MYSQL_KEY in Secret default/mysql-secret,}

How can I add a key: MY_SQL property to the secret.yaml file or find a way to eliminate it from the other deployment files like auth that uses it?我如何添加一个key: MY_SQL属性到secret.yaml文件或找到一种方法将它从其他deployment文件(如使用它的auth )中删除?

If I just eliminate key: MYSQL_KEY from auth deployment file I get this error:如果我只是从 auth deployment文件中删除key: MYSQL_KEY我会收到此错误:

 - The Deployment "auth-depl" is invalid: spec.template.spec.containers[0].env[1].valueFrom.secretKeyRef.key: Required value

EDIT: I tried to create the secret before I run skaffold dev using kubectl apply -f mysql-secret.yaml command and it worked.编辑:我尝试在使用kubectl apply -f mysql-secret.yaml命令运行skaffold dev之前创建秘密并且它有效。 My question is, how can I say to skafoold please run kubectl apply -f on mysql-secret.yaml file before the other yaml files?我的问题是,我怎么能告诉skafoold 请在mysql-secret.yaml文件上运行kubectl apply -f ,然后再运行其他yaml文件?

apiVersion: skaffold/v4beta1
kind: Config
build:
  artifacts:
  - image: auth
    context: auth-service
    sync:
      manual:
      - src: src/**/*.ts
        dest: .
    docker:
      dockerfile: Dockerfile
  - image: client
    context: client-service
    sync:
      manual:
      - src: lib/**/*.dart
        dest: .
    docker:
      dockerfile: Dockerfile
  local:
    push: false
manifests:
  rawYaml:
  - ./infra/k8s/*
deploy:
  kubectl: {}
  kubeContext: kind-kind

Looks like the deployment file is correct but your secret does not have the required keys.看起来部署文件是正确的,但您的秘密没有所需的密钥。 the keys are case sensitive.按键区分大小写。 In your secret.yaml file I do not see MYSQL_KEY .在您的 secret.yaml 文件中,我没有看到MYSQL_KEY Edit the file and add the key.编辑文件并添加密钥。

apiVersion: v1
kind: Secret
metadata:
  name: mysql-secret
type: Opaque
data:
  mysql-password: MTExMTEx
  mysql-root-password: MTExMTEx
  mysql-user: YQ==
  MYSQL_KEY: MTExMTEx

please note value of MYSQL_KEY in the above snippet is random.请注意上面代码段中 MYSQL_KEY 的值是随机的。 it should be base64 string of actual value应该是实际值的base64串

then run kubectl apply -f.然后运行 kubectl apply -f。 Off course, Kubectl tool should be installed and should point to the correct cluster.当然,应该安装 Kubectl 工具并指向正确的集群。

if this command runs well, your pods will be up in a few minutes.如果此命令运行良好,您的 pod 将在几分钟内启动。

Another way to edit the secret directly is to run kubectl edit secret secret-name or kubectl patch command.另一种直接编辑密钥的方法是运行kubectl edit secret secret-namekubectl patch命令。 By this way you can edit k8s objects directly.通过这种方式,您可以直接编辑 k8s 对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM