K8S - get config map data issue

12/9/2019

we need that each pod which use our binary will have the ability to read a specific config map

we use for that the Go API to read the config map.

https://github.com/kubernetes/client-go

The tricky part here that some of the pods have the following config automountServiceAccountToken: false (unfortunately we cannot change it :( )

Hence Im getting the following error:

 open /var/run/secrets/kubernetes.io/serviceaccount/token:no such file or directory

Any idea how to avoid this ?

is there is other solution how to provide specific env variable to be available on all the pods and all the namespace ?

https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#use-the-default-service-account-to-access-the-api-server

-- Jenny M
azure
go
kubernetes

1 Answer

12/9/2019

You'll need to create the token manually:

apiVersion: v1
kind: Secret
metadata:
  name: build-robot-secret
  annotations:
    kubernetes.io/service-account.name: default # I assume you use the default service account
type: kubernetes.io/service-account-token

Then mount this secret as a file into the pod:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: redis
    volumeMounts:
    - name: foo
      mountPath: "/var/run/secrets/kubernetes.io/serviceaccount"
  volumes:
  - name: foo
    secret:
      secretName: build-robot-secret
-- Dávid Molnár
Source: StackOverflow