Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ installed following the directions

If you find a problem please file an
[issue](https://github.com/kubernetes-client/python/issues).


---

## Running Examples Locally

### Prerequisites

- Python 3.8 or newer
- Kubernetes Python client installed:
```bash
pip install kubernetes
15 changes: 13 additions & 2 deletions examples/apply_from_dict.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import sys
from kubernetes.client.rest import ApiException


from kubernetes import client, config, utils
def main():
config.load_kube_config()
Expand All @@ -6,5 +10,12 @@ def main():
example_dict = {'apiVersion': 'apps/v1', 'kind': 'Deployment', 'metadata': {'name': 'k8s-py-client-nginx'}, 'spec': {'selector': {'matchLabels': {'app': 'nginx'}}, 'replicas': 1, 'template': {'metadata': {'labels': {'app': 'nginx'}}, 'spec': {'containers': [{'name': 'nginx', 'image': 'nginx:1.14.2', 'ports': [{'containerPort': 80}]}]}}}}
utils.create_from_dict(k8s_client, example_dict)

if __name__ == '__main__':
main()
if __name__ == "__main__":
try:
main()
except ApiException as e:
print(f"Kubernetes API error: {e}", file=sys.stderr)
sys.exit(1)
except Exception as e:
print(f"Unexpected error: {e}", file=sys.stderr)
sys.exit(2)