python 使用requests调用 kubernetes API创建deploy
python 调用k8s api 创建deploy
·
使用Python3 k8s集群1.18
import requests
import json, yaml
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) ## 关闭警告
k8s_token = "" ## 集群admin角色token
server_url = "https://192.168.153.x:6443/apis/apps/v1/namespaces/default/deployments"
def create_deploy():
headers = {
'Authorization': k8s_token,
"Content-Type": "application/json"
}
deploy_f = open("/root/deploy.yaml") ## 读取k8s yaml文件
a = yaml.safe_load(deploy_f)
requests.post(url=server_url, verify=False, headers=headers, json=a)
r = requests.get(url="https://192.168.153.x:6443/apis/apps/v1/namespaces/default/deployments", headers=headers, verify=False)
print(r.json())
create_deploy()
更多推荐
已为社区贡献4条内容
所有评论(0)