0

I want to inject the following secret key/value in pods: test-with=1 and testwith=1. First I create the secret:

kubectl create secret generic test --from-literal=test-with=1 --from-literal=testwith=0

Then I create a yaml file for a pod with the following specification:

containers:
  ...
  envFrom:
    - secretRef:
        name: test

The pod is running, but the result of env command inside the container only shows:

...
TERM=xterm
testwith=0
...

The test-with=1 does not show up. How can i declare the secret to see the key/value?

Xaving
  • 329
  • 1
  • 11

2 Answers2

1

Variables with delimitations in names are displayed at the top when viewed through printenv.

Checked:

$ kubectl create secret generic test --from-literal=test-with=1 --from-literal=testwith=0

$ kubectl get secret/test -o yaml
apiVersion: v1
data:
  test-with: MQ==
  testwith: MA==
kind: Secret
metadata:
  ...
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: check-env
spec:
  volumes:
  - name: shared-data
    emptyDir: {}
  containers:
  - name: nginx
    image: nginx
    envFrom:
    - secretRef:
        name: test
    volumeMounts:
    - name: shared-data
      mountPath: /usr/share/nginx/html
  hostNetwork: true
  dnsPolicy: Default
EOF
$ kubectl exec -it shell-demo -- printenv | grep test

test-with=1
testwith=0

GKE v1.18.16-gke.502

Arslanbekov Denis
  • 1,674
  • 12
  • 26
0

I don't see any issue. Here is how I replicated it:

kubectl create secret generic test --from-literal=test-with=1 --from-literal=testwith=0

cat<<EOF | kubectl apply -f- 
    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        run: cent
      name: cent
    spec:
      containers:
      - image: centos:7
        name: cent
        command:
        - sleep
        - "9999"
        envFrom:
          - secretRef:
              name: test
EOF

➜  ~ kubectl exec -it cent -- bash
[root@cent /]# env  | grep test
test-with=1
testwith=0

Most probably this is image issue

Matt
  • 7,419
  • 1
  • 11
  • 22