<small id='ArF6v'></small><noframes id='ArF6v'>

        <bdo id='ArF6v'></bdo><ul id='ArF6v'></ul>

      1. <i id='ArF6v'><tr id='ArF6v'><dt id='ArF6v'><q id='ArF6v'><span id='ArF6v'><b id='ArF6v'><form id='ArF6v'><ins id='ArF6v'></ins><ul id='ArF6v'></ul><sub id='ArF6v'></sub></form><legend id='ArF6v'></legend><bdo id='ArF6v'><pre id='ArF6v'><center id='ArF6v'></center></pre></bdo></b><th id='ArF6v'></th></span></q></dt></tr></i><div id='ArF6v'><tfoot id='ArF6v'></tfoot><dl id='ArF6v'><fieldset id='ArF6v'></fieldset></dl></div>
        <tfoot id='ArF6v'></tfoot>
        <legend id='ArF6v'><style id='ArF6v'><dir id='ArF6v'><q id='ArF6v'></q></dir></style></legend>

        kubernetes Python API 客户端:执行完整的 yaml 文件

        时间:2023-09-13
        <i id='PzikN'><tr id='PzikN'><dt id='PzikN'><q id='PzikN'><span id='PzikN'><b id='PzikN'><form id='PzikN'><ins id='PzikN'></ins><ul id='PzikN'></ul><sub id='PzikN'></sub></form><legend id='PzikN'></legend><bdo id='PzikN'><pre id='PzikN'><center id='PzikN'></center></pre></bdo></b><th id='PzikN'></th></span></q></dt></tr></i><div id='PzikN'><tfoot id='PzikN'></tfoot><dl id='PzikN'><fieldset id='PzikN'></fieldset></dl></div>

              <bdo id='PzikN'></bdo><ul id='PzikN'></ul>
              1. <tfoot id='PzikN'></tfoot>

                <small id='PzikN'></small><noframes id='PzikN'>

                <legend id='PzikN'><style id='PzikN'><dir id='PzikN'><q id='PzikN'></q></dir></style></legend>
                    <tbody id='PzikN'></tbody>
                • 本文介绍了kubernetes Python API 客户端:执行完整的 yaml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  Kubernetes 有一个非常好的官方 Python API 客户端.API 客户端假定您将创建单个资源(例如 pod 或服务),并假定您将使用 Python 对象来组合和创建 API 请求.

                  Kubernetes has a very nice official Python API client. The API client assumes that you will be creating individual resources (such as pods, or services) and assumes that you will be using Python objects to compose and create API requests.

                  但是,我想通过 Python 接口运行任意 kubernetes YAML 文件(包含一个或多个 k8s 资源).我想知道是否可以利用 Python kubernetes 客户端应用任意 YAML 文件?

                  However, I'd like to run arbitrary kubernetes YAML files (containing one or more k8s resources) via a Python interface. I was wondering if the Python kubernetes client can be leveraged to apply arbitrary YAML files?

                  我基本上是在寻找 Python 等价物:

                  I'm basically looking for the Python equivalent of:

                  kubectl apply -f some-file-containing-multiple-resources.yaml
                  

                  我正在寻找可以基本上加载 kubeconfig 并通过 Python 以相当 Pythonic 的方式应用 yaml 的东西.

                  I'm looking for something where I can basically load the kubeconfig and apply the yaml via Python in a fairly Pythonic way.

                  我知道我可能可以用 Python 子进程调用来包装 kubectl 命令,但我希望有比这更 Pythonic 的东西,并希望核心 K8s Python 客户端可以做类似的事情.或者,如果有另一个 Python 包做类似的事情.

                  I know I can probably wrap the kubectl command with a Python subprocess call, but I was hoping for something more Pythonic than that and hoped that the core K8s Python client could do something like that. Or, if there is another Python package that does something similar.

                  Python kubernetes 客户端可以调用任意k8s yaml 文件吗?如果不能,有什么可以调用的吗?

                  Can the Python kubernetes client call arbitrary k8s yaml files and if not, is there something that can?

                  感谢您的阅读 - 感谢您提供的任何建议.

                  Thanks for reading - I appreciate any advice you have to offer.

                  推荐答案

                  examples 目录中似乎有这样的示例.特别是 https://github.com/kubernetes-client/python/blob/6709b753b4ad2e09aa472b6452bbad9f96e264e3/examples/create_deployment_from_yaml.py 这样做:

                  There appears to be examples of this in the examples directory. In particular https://github.com/kubernetes-client/python/blob/6709b753b4ad2e09aa472b6452bbad9f96e264e3/examples/create_deployment_from_yaml.py which does:

                  from os import path
                  
                  import yaml
                  
                  from kubernetes import client, config
                  
                  
                  def main():
                      # Configs can be set in Configuration class directly or using helper
                      # utility. If no argument provided, the config will be loaded from
                      # default location.
                      config.load_kube_config()
                  
                      with open(path.join(path.dirname(__file__), "nginx-deployment.yaml")) as f:
                          dep = yaml.safe_load(f)
                          k8s_beta = client.ExtensionsV1beta1Api()
                          resp = k8s_beta.create_namespaced_deployment(
                              body=dep, namespace="default")
                          print("Deployment created. status='%s'" % str(resp.status))
                  
                  
                  if __name__ == '__main__':
                      main()
                  

                  这篇关于kubernetes Python API 客户端:执行完整的 yaml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:换行符和破折号在 jinja 中无法正常工作 下一篇:Loaddata 未正确处理时间戳和时区

                  相关文章

                  最新文章

                • <small id='taRfq'></small><noframes id='taRfq'>

                  <i id='taRfq'><tr id='taRfq'><dt id='taRfq'><q id='taRfq'><span id='taRfq'><b id='taRfq'><form id='taRfq'><ins id='taRfq'></ins><ul id='taRfq'></ul><sub id='taRfq'></sub></form><legend id='taRfq'></legend><bdo id='taRfq'><pre id='taRfq'><center id='taRfq'></center></pre></bdo></b><th id='taRfq'></th></span></q></dt></tr></i><div id='taRfq'><tfoot id='taRfq'></tfoot><dl id='taRfq'><fieldset id='taRfq'></fieldset></dl></div>

                  1. <tfoot id='taRfq'></tfoot>
                    <legend id='taRfq'><style id='taRfq'><dir id='taRfq'><q id='taRfq'></q></dir></style></legend>
                    • <bdo id='taRfq'></bdo><ul id='taRfq'></ul>