创建k8s admin 权限
minikube kubectl -- create serviceaccount admin -n kube-system
minikube kubectl -- create clusterrolebinding cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:admin
拿到admin secret秘钥token
复制到python3程序当中
import requests from kubernetes import client, config from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) token2 = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImhyNmU5dHV0aDRwM090bnFpaGs4TGFuVkMyUlpXR3YwU1BhN1hXNTViSXMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tdjV2eGsiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiMmM0MzM2NGMtZGZkYy00OTQ5LTg4OGYtNjZmNzgxOGI1ODE5Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.O9imc_s2-IM2bAZ1cFcNoTYptXN-kLQ2fFbcEVX7pJccZB9xTZzHa3eFDhDenn6nrQkZ_4r1wpTexvJLvTsGdN7_LIT2akcPlMrsJrwZybXbPP1FELNP1nHQRVcHUEQDZeLdJZ81CLvtMXI79RE5r3sk4JLWd-vfXfe2gu15GMCUxHXoOpREqfRLt-EKQIXI5BUO9acKE7vhamyN8QfqPJC_6bpDwv8N1ByTk6bltf2MNDMG5Z9HrJ92-Gp9f1WU1oxFSLsVymZdwLtIYxmWxb6cDjwsumntQTJEhpGYKKls5j7LgV-XYioMI_X7Qa34ZUpVZ5e-wW906gOM9BRLyg" configuration = client.Configuration() host = "https://xxx.xxx.xxx.xxx:8443" configuration.host = host configuration.verify_ssl = False configuration.api_key = {"authorization": "Bearer "+ token2} client.Configuration.set_default(configuration) v1 = client.CoreV1Api() ret = v1.list_pod_for_all_namespaces() for i in ret.items: print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
执行结果如下: