My NodeJS microservice is deployed to k8s cluster.
I am running this with my local Docker Desktop k8s environment.
I would like this microservice to access the k8s API server. For that, I guess I need to create a ServiceAccount
for it. So I did this:
apiVersion: v1
kind: ServiceAccount
metadata:
name: my-app-service-account
namespace: myapp-ns
Then, I also created a ClusterRole
to define the permissions:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: myapp-cluster-role
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
Finally, I created a ClusterRoleBinding
:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: my-app-role-binding
namespace: myapp-ns
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: myapp-cluster-role
subjects:
- kind: ServiceAccount
name: my-app-service-account
namespace: myapp-ns
I applied them to my cluster. Then, I noticed the created Service Account doesn't have a secret provisioned:
> k get sa -n myapp-ns
NAME SECRETS AGE
default 0 11h
my-app-service-account 0 1h
So, I created a secret
for my service account by applying the following manifest:
apiVersion: v1
kind: Secret
metadata:
name: my-sa-token
namespace: myapp-ns
annotations:
kubernetes.io/service-account.name: "my-app-service-account"
type: kubernetes.io/service-account-token
I can see that this secret
is created successfully:
> k get secret -n myapp-ns
NAME TYPE DATA AGE
my-sa-token kubernetes.io/dockerconfigjson 1 10s
Then, I check my previously created service account:
> k get sa -n myapp-ns
NAME SECRETS AGE
default 0 11h
my-app-service-account 0 1h
It still shows 0
secret associated with it.
Why is that? How can I have my service account to have a secret associated?