<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  DB_URL: &quot;BASE64&quot;
---
apiVersion: v1
kind: Namespace
metadata:
  name: my-ns
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: my-ns
  name: my-api
spec:
  selector:
    matchLabels:
      app: my-api
  replicas: 1
  revisionHistoryLimit: 5
  template:
    metadata:
      labels:
        app: my-api
    spec:
      containers:
        - name: my-api
          image: myimage:latest
          ports:
            - containerPort: 5000
          env:
            - name: DB_URL
              valueFrom:
                secretKeyRef:
                  name: mysecret
                  key: DB_URL
</code></pre>
<p>I've encountered <code>CreateContainerConfigError</code> after deploying above yaml file in my kubernetes cluster.</p>

PPShein
<p>This is because the deployment is using a secret <code>mysecret</code> which needs to exist in the namespace where the the deployment is being created. The namespace of the deployment is <code>my-ns</code> but secret is in <code>default</code> namespace because in the secret you have not mentioned any namespace.</p>
<p>Changing the secret yaml as below should fix it.</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: mysecret
  namespace: my-ns
type: Opaque
data:
  DB_URL: &quot;BASE64&quot;
</code></pre>
