Methods
This section outlines the methods available for interacting with the Kubernetes API through the Python client library.
Authentication
The Python client library provides several ways to authenticate to a Kubernetes cluster:
Service Account: This is the preferred way to authenticate when running inside a Kubernetes cluster. The client library will automatically use the service account token mounted in the pod.
Token File: You can provide a token file containing a valid access token.
In-Cluster Configuration: The client library can automatically discover and use in-cluster configuration when running inside a Kubernetes cluster.
Kubeconfig File: You can provide a path to a kubeconfig file containing cluster and authentication information.
Configuration Dictionary: You can provide a dictionary containing configuration options, including authentication information.
Resource Management
The Python client library provides methods for interacting with different types of Kubernetes resources. Some common methods include:
list_xxxx
: Retrieve all resource objects of a specific type. For example,list_namespaced_pod
retrieves all pods in a given namespace. This method is similar to thekubectl get
command.create_xxxx
: Create a new resource object. For example,create_namespaced_pod
creates a new pod in a given namespace. This method is similar to thekubectl create
command.delete_xxxx
: Delete a resource object. For example,delete_namespaced_pod
deletes a pod in a given namespace. This method is similar to thekubectl delete
command.get_xxxx
: Retrieve a specific resource object. For example,get_namespaced_pod
retrieves a pod in a given namespace. This method is similar to thekubectl get
command.patch_xxxx
: Apply a change to a specific field in a resource object. For example,patch_namespaced_pod
updates a pod in a given namespace. This method is similar to thekubectl patch
,kubectl label
, andkubectl annotate
commands.replace_xxxx
: Replace a resource object with a new one. For example,replace_namespaced_pod
replaces a pod in a given namespace. This method is similar to thekubectl replace
command.
Examples
See the examples directory for detailed examples of using the Python client library.
Documentation
For comprehensive documentation on the methods and resources available, please consult the following:
Additional Information
x-kubernetes-list-type
: This annotation is used to describe the topology of a list. Possible values areatomic
,set
, andmap
. The default value isatomic
.Quantity
: This type represents a fixed-point number and is used for representing quantities like resource requests and limits.ValidatingWebhook
andMutatingWebhook
: These objects describe admission webhooks, which are used to validate and mutate resources before they are created or updated.Ingress
: An Ingress object defines rules for allowing inbound connections to reach endpoints defined by a backend.
Contributing
The Kubernetes client library welcomes contributions from the community. Please review the README.md for more details.
Top-Level Directory Explanations
doc/ - This directory contains documentation files for the project.
doc/source/ - This directory contains the source files for the documentation.
examples/ - This directory contains example usage of the Kubernetes client library.
examples/dynamic-client/ - This directory contains examples of using the dynamic client to interact with Kubernetes.
examples/watch/ - This directory contains examples of using the watch function to monitor Kubernetes resources.
kubernetes/ - This directory contains the main Kubernetes client library.
kubernetes/base/ - This directory contains the base Kubernetes client library.
kubernetes/base/config/ - This directory contains configuration files for the base library.
kubernetes/base/dynamic/ - This directory contains the dynamic client implementation for the base library.
kubernetes/base/hack/ - This directory contains hack files for the base library.
kubernetes/base/leaderelection/ - This directory contains the leader election implementation for the base library.
kubernetes/base/watch/ - This directory contains the watch implementation for the base library.
kubernetes/client/ - This directory contains the top-level client for the Kubernetes client library.
kubernetes/client/api/ - This directory contains the API definitions for the client library.
kubernetes/client/models/ - This directory contains the data models used by the client library.
kubernetes/e2e_test/ - This directory contains end-to-end tests for the Kubernetes client library.
kubernetes/e2e_test/test_yaml/ - This directory contains YAML files used in the end-to-end tests.
kubernetes/test/ - This directory contains unit tests for the Kubernetes client library.
kubernetes/utils/ - This directory contains utility functions for the Kubernetes client library.
scripts/ - This directory contains scripts used in the development and build process.