gardener / dashboard

Web-based GUI for Gardener installations.
Apache License 2.0
208 stars 103 forks source link

fetch kubeconfig programmatically #222

Closed tareksha closed 6 years ago

tareksha commented 6 years ago

Hi,

I would like to fetch the kubeconfig of a cluster in my gardener project programmatically using REST calls (without a browser). Is there a REAPI API that I can call ?

I've noticed that the dashboard issues this request in order to fetch the kubeconfig of a cluster:

GET https://dashboard.garden.mydomain/api/namespaces/garden-myproject/shoots/mycluster/info

{
  "seedShootIngressDomain": "mycluster.myproject.ingress.blahblah",
  "kubeconfig": " ... ",
  "cluster_username": "...",
  "cluster_password": "...",
  "serverUrl": "https://api.mycluster.myproject.blahblah"
}

The request seems to contain a token in the Authorization header. Is it relevant? What REST doe this redirect to ?

petersutter commented 6 years ago

Hi @tareqhs,

with the dasboard you can create a service account / robot under the members section and download the kubeconfig for this service account. With that you can access the gardener cluster. Using this kubeconfig you can execute something like that to get the kubeconfig of your desired cluster.

kubectl -n garden-my-project get secret mycluster.kubeconfig -o json | jq -r .data.kubeconfig | base64 -d

IHTH

Best regards, Peter

petersutter commented 6 years ago

and when you use e.g. the kubectl -v=9 option you also see which api endpoint is called

GET https://my.gardener.host/api/v1/namespaces/garden-my-project/secrets/mycluster.kubeconfig
tareksha commented 6 years ago

hi @petersutter , thanks for the info. so there is no way to automate this on a cross-project level?

petersutter commented 6 years ago

No this is not possible with the service account that you can create under the members section in the dashboard. But in general it's possible but you need a more privileged user

petersutter commented 6 years ago

does this answer your question?

grolu commented 6 years ago

I will close the issue for now. Please reopen if your question is not answered.