美文网首页
k8s的api调用(python)

k8s的api调用(python)

作者: heliping_peter | 来源:发表于2018-02-09 18:38 被阅读85次
    1. 脚本
      使用yaml,注意requests中的auth
    import requests
    import yaml
    f = open('2048.yaml')
    y = yaml.load(f)
    yYaml = yaml.dump(y)
    
    url = 'http://192.168.123.170/apis/extensions/v1beta1/namespaces/default/deployments'
    head = {'Content-Type' : 'application/yaml'}
    
    r = requests.post(url,data=yYaml,headers=head,auth=('admin','admin'))
    print(r.text)
    

    2.yaml文件

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: abc-2048
      labels:
        app: abc-2048
    spec:
      template:
        metadata:
          name: abc-2048
          labels:
            app: abc-2048
        spec:
          containers:
          - name: abc-2048
            image: daocloud.io/daocloud/dao-2048:latest
            ports:
            - containerPort: 80
    

    相关文章

      网友评论

          本文标题:k8s的api调用(python)

          本文链接:https://www.haomeiwen.com/subject/uqrqtftx.html