python 通过k8s API采集k8s 集群信息
【代码】python 通过k8s API采集k8s 集群信息。
·
curl 方式获取k8s 中的deployments
curl \
--header "Authorization: Bearer eyJhbGciOiJSUzI1NiIs_OVpAqcsnBZeqwwiwfkFWiykIobYEMgbMzbXa27r02Q_mGnqGzA6PiUq1SKDTq_SlBhAO_dCdnaZ6eOJ71ew" \
--insecure \
-X GET https://10.20.12.13:6443/apis/apps/v1/namespaces/flink-dev/deployments
python获取k8s api
import requests
headers = {
'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IERVlsdjlVMWxNd3dIOHJEMUVBV1phMEhuUkFaNUt1Z1EifQ.eyJpc3MiOiJrdWJlcmw',
}
response = requests.get('https://10.20.12.13:6443:6443/apis/apps/v1/namespaces/flink-dev/deployments', headers=headers, verify=False)
print(response.json())
获取 k8s pods日志接口
GET /api/v1/namespaces/{namespace}/pods/{name}/log
更多方式获取k8s 集群信息 kube/config
python(shell\curl )通过k8s API获取pods、deployment、namespace等集群信息
神奇网站 curl 转python请求
更多接口参考
https://support.huaweicloud.com/api-cci/readCoreV1NamespacedPodLog.html
https://www.cnblogs.com/moonwang/p/15599213.html
更多推荐
已为社区贡献2条内容
所有评论(0)