I can connect to the Kubernetes API from a container running inside the cluster with an OIDC token like so:
kubectl —token $token get pod
I would now like to prepare a kubeconfig such that other programs that don’t support --token
can connect as well. I am trying this in the specific context of docker buildx create --driver kubernetes ...; docker buildx build .
where the 2nd part needs to create a deployment
. Here's how I have proceeded:
tmp=$(mktemp -p $PWD)
kubectl config --kubeconfig $tmp set-cluster cluster \
--server https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT \
--certificate-authority /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
kubectl config --kubeconfig $tmp set-credentials user --auth-provider oidc \
--auth-provider-arg idp-issuer-url=... \
--auth-provider-arg client-id=... \
--auth-provider-arg id-token=$token
kubectl config --kubeconfig $tmp set-context context --cluster cluster --user user
kubectl config --kubeconfig $tmp use-context context
export KUBECONFIG=$tmp
kubectl get pod
kubectl get pod
now fails with "Unable to connect to the server: No valid id-token, and cannot refresh without refresh-token". Why does it deem $token
invalid when it has worked just before with kubectl get pod --token
(and still does)? How can create a kubeconfig "envelope" around $token
such that kubectl get pod
will accept it and won't fail? (I've not specified refresh-token
because it shouldn't be needed in the case of a valid token and because I don't have it readily available inside the container.)