SECRET_NAME=$(kubectl get serviceaccounts default -o template --template="{{ (index .secrets 0).name }}")
kubectl get secret $SECRET_NAME -o template --template="{{.data.token}}" | base64 -d
copy result
create file ~/.kube/config
:
apiVersion: v1
clusters:
- cluster:
insecure-skip-tls-verify: true
server: https://<vagrant_box_ip>:6443
name: k8s
contexts:
- context:
cluster: k8s
user: "serviceaccount"
name: k8s
current-context: k8s
kind: Config
preferences: {}
users:
- name: serviceaccount
user:
token: <paste_token_from_previous_step_here>
- copy out and use k8s CA certificate from Vagrant box instead of
insecure-skip-tls-verify: true
The copy part needs needs to be automated and in the scope of vagrant-service-manager plugin. In addition to copy the cert, the required environment variable
KUBECONFIG
should be set with config path on host machine. https://cloud.google.com/container-engine/docs/kubectl/config