使用curl https方式访问kubernetes集群的api,认证方式需要用到token,这里使用变量赋予APISERVER 和TOKEN的值
apiserver:
$ APISERVER=$(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ")
token:
$ TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t')
访问
$ curl --header "Authorization: Bearer $TOKEN" --insecure $APISERVER/api/v1
FAQ
由于匿名用户被禁止访问可能会出现以下报错:
"message": "nodes is forbidden: User \"system:anonymous\" cannot list resource \"nodes\" in API group \"\" at the cluster scope"
给匿名用户授权即可解决,测试环境可用此快速解决:
$ kubectl create clusterrolebinding test:anonymous --clusterrole=cluster-admin --user=system:anonymous
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)