使用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()

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐