CreateContainerConfigError found when I deploy pods in kubernetes with secret

8/23/2020
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  DB_URL: "BASE64"
---
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

I've encountered CreateContainerConfigError after deploying above yaml file in my kubernetes cluster.

-- PPShein
amazon-eks
kubernetes

1 Answer

8/23/2020

This is because the deployment is using a secret mysecret which needs to exist in the namespace where the the deployment is being created. The namespace of the deployment is my-ns but secret is in default namespace because in the secret you have not mentioned any namespace.

Changing the secret yaml as below should fix it.

apiVersion: v1
kind: Secret
metadata:
  name: mysecret
  namespace: my-ns
type: Opaque
data:
  DB_URL: "BASE64"
-- Arghya Sadhu
Source: StackOverflow