Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the Kubernetes REST end points using bearer token

Tags:

kubernetes

Requirement: We need to access the Kubernetes REST end points from our java code. Our basic operations using the REST end points are to Create/Update/Delete/Get the deployments.

We have downloaded the kubectl and configured the kubeconfig file of the cluster in our Linux machine. We can perform operations in that cluster using the kubectl. We got the bearer token of that cluster running the command 'kubectl get pods -v=8'. We are using this bearer token in our REST end points to perform our required operations.

Questions:

  1. What is the better way to get the bearer token?
  2. Will the bearer token gets change during the lifecycle of the cluster?
like image 915
Farooq Rahman Avatar asked May 20 '19 05:05

Farooq Rahman


People also ask

How do I get Kubernetes bearer token?

To obtain the token, you need to create a service account (ServiceAccount) and associate it with the cluster role. Each created service account will have a token stored in the Kubernetes Secret API. The updated kubeconfig will be located in the $HOME/. kube/config home directory.

How do I access k8 API?

Go client. To get the library, run the following command: go get k8s.io/client-go@kubernetes-<kubernetes-version-number> See https://github.com/kubernetes/client-go/releases to see which versions are supported. Write an application atop of the client-go clients.


1 Answers

Q: What is the better way to get the bearer token?

A: Since you have configured access to the cluster, you might use

kubectl describe secrets

Q: Will the bearer token gets change during the lifecycle of the cluster?

A: Static tokens do not expire.

Please see Accessing Clusters and Authenticating for more details.

like image 83
mebius99 Avatar answered Sep 30 '22 00:09

mebius99