There's more...

An even more programmatic way to utilize Kubernetes API is to use the client library (https://kubernetes.io/docs/reference/client-libraries/). Making good use of these client tools not only saves you time in resource management, but also produce a robust and reliable CI/CD environment. Here, we would like to introduce the Kubernetes client library for Python: https://github.com/kubernetes-client/python. To start, you should install the Python library for Kubernetes:

$ pip install kubernetes

Then, please put the following Python file at the same location as the JSON configuration file, nginx-deployment.json, where firing kubectl does work on the system:

$ cat create_deployment.py
from kubernetes import client, config
import json
config.load_kube_config()
resource_config = json.load(open("./nginx-deployment.json"))
api_instance = client.AppsV1Api()
response = api_instance.create_namespaced_deployment(body=resource_config, namespace="default")
print("success, status={}".format(response.status))

You don't even enable the Kubernetes proxy now; continue to run this script directly and see what happens:

$ python create_deployment.py
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.252.56