<p>I have the following file that creates a <code>mysql-secret</code> for <code>mysql</code> deployment pod.</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: mysql-secret
type: Opaque
data:
  mysql-password: MTExMTEx
  mysql-root-password: MTExMTEx
  mysql-user: YQ==
</code></pre>
<p>The problem is that, previously I could deploy <code>mysql</code> on <code>Kubernetes</code> cluster using the secret key created by this command:</p>
<pre><code>kubectl create secret generic mysql-secret --from-literal MYSQL_KEY=11111
</code></pre>
<p>And using <code>MYSQL_KEY</code> I could pass it to other <code>deployment</code> files like <code>auth</code> as you can see below:</p>
<pre><code>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
</code></pre>
<p>But now I don't have a key using a <code>yaml</code> file to create the secret key and I get the following error because of that:</p>
<pre><code> - deployment/auth-mysql-depl is ready. [3/5 deployment(s) still pending]
 - deployment/mysql: container mysql in error: &amp;ContainerStateWaiting{Reason:CreateContainerConfigError,Message:couldn't find key MYSQL_KEY in Secret default/mysql-secret,}
    - pod/mysql-78bbf5f6f4-vbpkz: container mysql in error: &amp;ContainerStateWaiting{Reason:CreateContainerConfigError,Message:couldn't find key MYSQL_KEY in Secret default/mysql-secret,}
</code></pre>
<p>How can I add a <code>key: MY_SQL</code> property to the <code>secret.yaml</code> file or find a way to eliminate it from the other <code>deployment</code> files like <code>auth</code> that uses it?</p>
<p>If I just eliminate <code>key: MYSQL_KEY</code> from auth <code>deployment</code> file I get this error:</p>
<pre><code> - The Deployment &quot;auth-depl&quot; is invalid: spec.template.spec.containers[0].env[1].valueFrom.secretKeyRef.key: Required value
</code></pre>
<p>EDIT: I tried to create the secret before I run <code>skaffold dev</code> using <code>kubectl apply -f mysql-secret.yaml</code> command and it worked. My question is, how can I say to <code>skafoold</code> please run <code>kubectl apply -f</code> on <code>mysql-secret.yaml</code> file before the other <code>yaml</code> files?</p>
<pre><code>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
</code></pre>

best_of_man
<p>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 <code>MYSQL_KEY</code>. Edit the file and add the key.</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: mysql-secret
type: Opaque
data:
  mysql-password: MTExMTEx
  mysql-root-password: MTExMTEx
  mysql-user: YQ==
  MYSQL_KEY: MTExMTEx
</code></pre>
<p><em>please note value of MYSQL_KEY in the above snippet is random. it should be base64 string of actual value</em></p>
<p>then run kubectl apply -f . <em>Off course, Kubectl tool should be installed and should point to the correct cluster.</em></p>
<p>if this command runs well, your pods will be up in a few minutes.</p>
<p>Another way to edit the secret directly is to run <code>kubectl edit secret secret-name</code> or <code>kubectl patch </code> command. By this way you can edit k8s objects directly.</p>
