Home > Net >  Why cannot K8s pod read stored secret?
Why cannot K8s pod read stored secret?

Time:01-18

I cannot access a secret I created. I inserted a secret in K8s secret store and am simply trying to test access to it with this yaml...

apiVersion: v1
kind: Namespace
metadata:
  name: space1
---
apiVersion: v1
kind: Pod
metadata:
  name: space1
  namespace: space1
spec:
  containers:
  - name: space1-pod
    image: repo/python-image:latest
    imagePullPolicy: Always
    command: ['sh', '-c', 'echo "Username: $USER" "Password: $PASSWORD"']
    env:
      - name: USER
        valueFrom:
          secretKeyRef:
            name: tool-user
            key: username
      - name: PASSWORD
        valueFrom:
          secretKeyRef:
            name:tool-user
            key: password
  restartPolicy: Always

The status of the "pod is waiting to start: CreateContainerConfigError". And I receive this error...

Error: secret "tool-user" not found

Despite the result I get from "kubectl get secrets" which clearly shows...

    NAME                  TYPE                                  DATA   AGE
tool-user         Opaque                                2      4d1h

CodePudding user response:

kubectl get secrets shows secrets from a default namespace, add -n space1 to see secrets from the namespace your pod runs in.

CodePudding user response:

secrets are namespaced objects. Make sure the secret "tool-user" is created on the "secret1" namespace.

  • Related