As an administrator, you can create a service account token secret. This allows you to distribute a service account token to applications that must authenticate to the API.
.Procedure
. Create a service account in your namespace by running the following command:
+
[source,terminal]
----
$ oc create sa <service_account_name> -n <your_namespace>
----
. Save the following YAML example to a file named `service-account-token-secret.yaml`. The example includes a `Secret` object configuration that you can use to generate a service account token:
+
[source,yaml]
----
apiVersion: v1
kind: Secret
metadata:
name: <secret_name> <1>
annotations:
kubernetes.io/service-account.name: "sa-name" <2>
type: kubernetes.io/service-account-token <3>
----
<1> Replace `<secret_name>` with the name of your service token secret.
<2> Specifies an existing service account name. If you are creating both the `ServiceAccount` and the `Secret` objects, create the `ServiceAccount` object first.
<3> Specifies a service account token secret type.
. Generate the service account token by applying the file:
+
[source,terminal]
----
$ oc apply -f service-account-token-secret.yaml
----
. Get the service account token from the secret by running the following command: