Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.5k
#884: Cleanup examples folder#938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Python Client Examples | ||
| This directory contains various examples of how to use the Python client. | ||
| Please read the description at the top of each example for more information | ||
| about what the script does and any prequisites. Most scripts also include | ||
| comments throughout the code. | ||
| ## Setup | ||
| These scripts require Python 2.7 or 3.5+ and the Kubernetes client which can be | ||
| installed following the directions | ||
| [here](https://github.com/kubernetes-client/python#installation). | ||
| ## Contributions | ||
| If you find a problem please file an | ||
| [issue](https://github.com/kubernetes-client/python/issues). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,4 +12,4 @@ | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # Empty init file to make examples folder a python module. | ||
scottilee marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # Empty init file to make examples folder a python module | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,37 +12,38 @@ | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # This example use an example CRD from this tutorial: | ||
| # https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/ | ||
| # | ||
| # The following yaml manifest has to be applied first: | ||
| # | ||
| # apiVersion: apiextensions.k8s.io/v1beta1 | ||
| # kind: CustomResourceDefinition | ||
| # metadata: | ||
| # name: crontabs.stable.example.com | ||
| # spec: | ||
| # group: stable.example.com | ||
| # versions: | ||
| # - name: v1 | ||
| # served: true | ||
| # storage: true | ||
| # scope: Namespaced | ||
| # names: | ||
| # plural: crontabs | ||
| # singular: crontab | ||
| # kind: CronTab | ||
| # shortNames: | ||
| # - ct | ||
| """ | ||
| Uses a Custom Resource Definition (CRD) to create a custom object, in this case | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this first sentence needed? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you're asking? Let me know if you'd prefer something else. | ||
| a CronTab. This example use an example CRD from this tutorial: | ||
| https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/ | ||
| The following yaml manifest has to be applied first: | ||
| apiVersion: apiextensions.k8s.io/v1 | ||
| kind: CustomResourceDefinition | ||
| metadata: | ||
| name: crontabs.stable.example.com | ||
| spec: | ||
| group: stable.example.com | ||
| versions: | ||
| - name: v1 | ||
| served: true | ||
| storage: true | ||
| scope: Namespaced | ||
| names: | ||
| plural: crontabs | ||
| singular: crontab | ||
| kind: CronTab | ||
| shortNames: | ||
| - ct | ||
| """ | ||
| from pprint import pprint | ||
| from kubernetes import client, config | ||
| def main(): | ||
| config.load_kube_config() | ||
| api = client.CustomObjectsApi() | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,47 +12,46 @@ | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # Simple example to show loading config from the cluster | ||
| # | ||
| # It works only from a pod. You can start an image with Python | ||
| # (for example python:latest), exec into the pod, install the library, | ||
| # then try out this example. | ||
| # | ||
| # If you get 403 errors from API server you will have to configure | ||
| # RBAC to add the permission to list pods. | ||
| # | ||
| # --- | ||
| # kind: ClusterRole | ||
| # apiVersion: rbac.authorization.k8s.io/v1 | ||
| # metadata: | ||
| # name: pods-list | ||
| # rules: | ||
| # - apiGroups: [""] | ||
| # resources: ["pods"] | ||
| # verbs: ["list"] | ||
| # --- | ||
| # kind: ClusterRoleBinding | ||
| # apiVersion: rbac.authorization.k8s.io/v1 | ||
| # metadata: | ||
| # name: pods-list | ||
| # subjects: | ||
| # - kind: ServiceAccount | ||
| # name: default | ||
| # namespace: default | ||
| # roleRef: | ||
| # kind: ClusterRole | ||
| # name: pods-list | ||
| # apiGroup: rbac.authorization.k8s.io | ||
| # --- | ||
| # | ||
| # Doc: https://kubernetes.io/docs/reference/access-authn-authz/rbac/ | ||
| """ | ||
| Shows how to load a Kubernetes config from within a cluster. This script | ||
| must be run within a pod. You can start a pod with a Python image (for | ||
roycaihw marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| example, `python:latest`), exec into the pod, install the library, then run | ||
| this example. | ||
| If you get 403 errors from the API server you will have to configure RBAC to | ||
| add permission to list pods by applying the following manifest: | ||
| --- | ||
| kind: ClusterRole | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| metadata: | ||
| name: pods-list | ||
| rules: | ||
| - apiGroups: [""] | ||
| resources: ["pods"] | ||
| verbs: ["list"] | ||
| --- | ||
| kind: ClusterRoleBinding | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| metadata: | ||
| name: pods-list | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: default | ||
| namespace: default | ||
| roleRef: | ||
| kind: ClusterRole | ||
| name: pods-list | ||
| apiGroup: rbac.authorization.k8s.io | ||
| Documentation: https://kubernetes.io/docs/reference/access-authn-authz/rbac/ | ||
| """ | ||
| from kubernetes import client, config | ||
| def main(): | ||
| # it works only if this script is run by K8s as a POD | ||
| config.load_incluster_config() | ||
| v1 = client.CoreV1Api() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,6 +12,11 @@ | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ | ||
| Creates deployment, service, and ingress objects. The ingress allows external | ||
scottilee marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| network access to the cluster. | ||
| """ | ||
| from kubernetes import client, config | ||
| @@ -73,7 +78,7 @@ def create_ingress(networking_v1_beta1_api): | ||
| }), | ||
| spec=client.NetworkingV1beta1IngressSpec( | ||
| rules=[client.NetworkingV1beta1IngressRule( | ||
| host="boddulabs.com", | ||
| host="example.com", | ||
| http=client.NetworkingV1beta1HTTPIngressRuleValue( | ||
| paths=[client.NetworkingV1beta1HTTPIngressPath( | ||
| path="/", | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,14 +12,18 @@ | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ | ||
| Allows you to pick a context and then lists all pods in the chosen context. | ||
| Please install the pick library before running this example. | ||
| """ | ||
| from kubernetes import client, config | ||
| # install pick using "pip install pick". It is not included | ||
| # as a dependency because it only used in examples | ||
| from pick import pick | ||
| from kubernetes.client import configuration | ||
| from pick import pick # install pick using `pip install pick` | ||
| def main(): | ||
scottilee marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| contexts, active_context = config.list_kube_config_contexts() | ||
| if not contexts: | ||
| print("Cannot find any context in kube-config file.") | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.