Home > front end >  How do I create a Service Account in Kubernetes and associate a Token to the new Service Account
How do I create a Service Account in Kubernetes and associate a Token to the new Service Account

Time:11-26

I tried creating just a simple Service account in Kubernetes by running the command on my AWS EC2 cli kubectl create serviceaccount jenkins --dry-run=client -o yaml > jenkins-sa.yaml and I have my kube/config file on my /home/ec2-user.

I applied the new config jenkins-sa.yaml by running kubectl apply -f jenkins-sa.yaml and then I tried to see more info about the newly created service account by running kubectl describe serviceaccount jenkins which displays some information but without the secret token that should be associated to the jenkins service account by default.

Please I would be grateful if someone can point out what i'm doing wrong because I'm pretty new to Kubernetes. Below is a screenshot

enter image description here

CodePudding user response:

You have to create the token secret manually. Here is a YAML example:

apiVersion: v1
kind: Secret
type: kubernetes.io/service-account-token
metadata:
  name: jenkins-sa-token
  namespace: default
  annotations:
    kubernetes.io/service-account.name: "jenkins"

This will create a sercvice account token secret for your jenkins service account with name jenkins-sa-token.

CodePudding user response:

Starting kubernetes 1.24, token is not generated by default. You can see the changelog for more details. You can manually create token using

Kubectl create token

  • Related