Skip to content

Instantly share code, notes, and snippets.

@pathcl
Last active March 12, 2020 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pathcl/c63cd46e7da2d75e12f5b3b167a57231 to your computer and use it in GitHub Desktop.
Save pathcl/c63cd46e7da2d75e12f5b3b167a57231 to your computer and use it in GitHub Desktop.
Example for crd/python kubernetes client
from pprint import pprint
from kubernetes import client, config
c = client.Configuration()
c.debug = True
config.load_kube_config(
config_file="/Users/lsanmartin/work/capv/out/k8s-m-mgmt/kubeconfig")
api = client.CustomObjectsApi()
# it's my custom resource defined as Dict
my_resource = {
"apiVersion": "cluster.x-k8s.io/v1alpha2",
"kind": "Cluster",
"metadata": {"name": "lab"},
}
# create the resource
api.create_namespaced_custom_object(
namespace="default",
group="cluster.x-k8s.io",
version="v1alpha2",
plural="clusters",
body=my_resource,
)
print("Resource created")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment