This post will show you how to access other cluster service with an authorization token
It would like:
curl $APISERVER/api/v1/namespaces/default/services/httpbin:80/proxy/get --header "Authorization: Bearer $TOKEN" --insecure |
Deploy resource
Please know what you are going to deploy.
kustomize build github.com/RammusXu/toolkit/k8s/access-service-with-service-account-token |
Apply
kustomize build github.com/RammusXu/toolkit/k8s/access-service-with-service-account-token | kubectl apply -f - |
Get service account token
NAMESPACE=default |
curl $APISERVER/api/v1/namespaces/default/services/httpbin:http/proxy/get --header "Authorization: Bearer $TOKEN" --insecure |
Clean
kustomize build github.com/RammusXu/toolkit/k8s/access-service-with-service-account-token | kubectl delete -f - |
Troubleshooting
“services "httpbin" is forbidden: User "system:serviceaccount:default:default" cannot get resource "services/proxy" in API group "" in the namespace "default"“
It needs RBAC: services/proxy
kind: ClusterRole |
no endpoints available for service "httpbin"
"status": "Failure", |
The correct way to access are:
✅ |