Skip to content
Snippets Groups Projects
Commit bbf91399 authored by Thomas Goirand's avatar Thomas Goirand
Browse files

New upstream version 26.1.0

parent c0cbcdf0
No related branches found
No related tags found
No related merge requests found
Showing
with 1137 additions and 44 deletions
name: Deploy Wiki
on:
push:
paths:
- 'kubernetes/docs/**'
branches:
- master
jobs:
deploy-wiki:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Install rsync
run: |
sudo apt install rsync grsync
- name: Clone Wiki
run: |
git config --global --add safe.directory "/github/workspace"
git config --global --add safe.directory "/github/workspace/wiki"
git clone https://github.com/kubernetes-client/python.wiki.git wiki
message=$(git log -1 --format=%B)
- name: Copy to wiki repository
run: |
rsync -av --delete kubernetes/docs/ wiki/ --exclude .git
- name: Push wiki
run: |
cd wiki
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "$message"
git push
\ No newline at end of file
......@@ -13,24 +13,24 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
- name: Create Kind Cluster
uses: helm/kind-action@v1.2.0
uses: helm/kind-action@v1.5.0
with:
cluster_name: kubernetes-python-e2e-master-${{ matrix.python-version }}
# The kind version to be used to spin the cluster up
# this needs to be updated whenever a new Kind version is released
version: v0.11.1
version: v0.17.0
# Update the config here whenever a new client snapshot is performed
# This would eventually point to cluster with the latest Kubernetes version
# as we sync with Kubernetes upstream
config: .github/workflows/kind-configs/cluster-1.18.yaml
config: .github/workflows/kind-configs/cluster-1.25.yaml
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.3.2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
......
......@@ -15,11 +15,11 @@ jobs:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
- name: Create Kind Cluster
uses: helm/kind-action@v1.2.0
uses: helm/kind-action@v1.4.0
with:
cluster_name: kubernetes-python-e2e-release-11.0-${{ matrix.python-version }}
# The kind version to be used to spin the cluster up
......@@ -30,7 +30,7 @@ jobs:
# as we sync with Kubernetes upstream
config: .github/workflows/kind-configs/cluster-1.15.yaml
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.3.2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
......
......@@ -15,11 +15,11 @@ jobs:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
- name: Create Kind Cluster
uses: helm/kind-action@v1.2.0
uses: helm/kind-action@v1.4.0
with:
cluster_name: kubernetes-python-e2e-release-12.0-${{ matrix.python-version }}
# The kind version to be used to spin the cluster up
......@@ -30,7 +30,7 @@ jobs:
# as we sync with Kubernetes upstream
config: .github/workflows/kind-configs/cluster-1.16.yaml
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.3.2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
......
......@@ -15,11 +15,11 @@ jobs:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
- name: Create Kind Cluster
uses: helm/kind-action@v1.2.0
uses: helm/kind-action@v1.4.0
with:
cluster_name: kubernetes-python-e2e-release-17.0-${{ matrix.python-version }}
# The kind version to be used to spin the cluster up
......@@ -30,7 +30,7 @@ jobs:
# as we sync with Kubernetes upstream
config: .github/workflows/kind-configs/cluster-1.17.yaml
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.3.2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
......
......@@ -15,11 +15,11 @@ jobs:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
- name: Create Kind Cluster
uses: helm/kind-action@v1.2.0
uses: helm/kind-action@v1.4.0
with:
cluster_name: kubernetes-python-e2e-release-18.0-${{ matrix.python-version }}
# The kind version to be used to spin the cluster up
......@@ -30,7 +30,7 @@ jobs:
# as we sync with Kubernetes upstream
config: .github/workflows/kind-configs/cluster-1.18.yaml
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.3.2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
......
name: End to End Tests - release-26.0
on:
push:
branches:
- release-26.0
pull_request:
branches:
- release-26.0
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Create Kind Cluster
uses: helm/kind-action@v1.5.0
with:
cluster_name: kubernetes-python-e2e-release-26.0-${{ matrix.python-version }}
# The kind version to be used to spin the cluster up
# this needs to be updated whenever a new Kind version is released
version: v0.17.0
# Update the config here whenever a new client snapshot is performed
# This would eventually point to cluster with the latest Kubernetes version
# as we sync with Kubernetes upstream
config: .github/workflows/kind-configs/cluster-1.26.yaml
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -r test-requirements.txt
- name: Install package
run: python -m pip install -e .
- name: Run End to End tests
run: pytest -vvv -s kubernetes/e2e_test
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:v1.25.3@sha256:f1de3b0670462f43280114eccceab8bf1b9576d2afe0582f8f74529da6fd0365
- role: worker
image: kindest/node:v1.25.3@sha256:f1de3b0670462f43280114eccceab8bf1b9576d2afe0582f8f74529da6fd0365
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:v1.26.0@sha256:3264cbae4b80c241743d12644b2506fff13dce07fcadf29079c1d06a47b399dd
- role: worker
image: kindest/node:v1.26.0@sha256:3264cbae4b80c241743d12644b2506fff13dce07fcadf29079c1d06a47b399dd
......@@ -7,17 +7,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.10"]
python-version: ["3.7", "3.8", "3.10", "3.11"]
include:
- python-version: "3.9"
use_coverage: 'coverage'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.3.2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
......@@ -44,7 +44,7 @@ jobs:
- name: Upload coverage to Codecov
if: "matrix.use_coverage"
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
fail_ci_if_error: false
verbose: true
This diff is collapsed.
......@@ -15,7 +15,7 @@ Follow either of the two links above to access the appropriate CLA and instructi
## Composition of This Repository and Where/How to Contribute
The Kubernetes Python client consists of this main repository (repo) and the base repo, the [python-base](https://github.com/kubernetes-client/python-base) repository. The main repository contains mostly files that are generated by the OpenAPI generator from [this OpenAPI spec](scripts/swagger.json). The base repo is the utility part of the python client and allows developers to create their own kubernetes clients. The base repo is a submodule of the main repo.
The Kubernetes Python client contains mostly files that are generated by the OpenAPI generator from [this OpenAPI spec](scripts/swagger.json). In the repo there is also the utility part, which allows developers to create their own kubernetes clients ([kubernetes/base](kubernetes/base)). The base repo was once a submodule of the main repo, but is now integrated into the main repo. The archived code is available ([here](https://github.com/kubernetes-client/python-base)).
### Where to Submit Your Patch
......@@ -25,16 +25,17 @@ The following folders are automatically generated. You will need to submit a pat
- [kubernetes/docs](kubernetes/docs).
In this main repo, the following folders contain developer written codes and the patches should be submitted as pull requests here:
- [kubernetes/base](kubernetes/base)
- [kubernetes/config](kubernetes/config)
- [kubernetes/dynamic](kubernetes/dynamic)
- [kubernetes/e2e_test](kubernetes/e2e_test)
- [kubernetes/leaderelection](kubernetes/leaderelection)
- [kubernetes/stream](kubernetes/stream)
- [kubernetes/utils](kubernetes/utils)
- [kubernetes/watch](kubernetes/watch)
- [examples](examples)
- [scripts](scripts).
The following folders and symbolic links in this main repo are in fact from the base repo. The base repo contains developer written codes only. The patches should be sent to the base repo instead:
- kubernetes/base
- kubernetes/config
- kubernetes/stream
- kubernetes/watch.
### Contributing A Patch
......@@ -79,11 +80,3 @@ If you write a new end to end (e2e) test, or change behaviors that affect e2e te
2. Run the unit tests. In the root directory of the main repo, run ```python -m unittest discover```.
3. Check the test results and make corresponding fixes.
## Update the Base Submodule in the Main Repo After Your python-base PR Is Merged
Your contribution to the base repo will not be automatically reflected in the main repo after your PR is merged. Instead, please update the ```base``` submodule in your fork of the main repo as follows:
```bash
$ git submodule update --remote
```
You may now add a release note to [CHANGELOG.md](CHANGELOG.md) if needed and then commit and push to your fork. You can now send a PR to this main repo to complete your contribution.
......@@ -92,6 +92,10 @@ supported versions of Kubernetes clusters.
- [client 20.y.z](https://pypi.org/project/kubernetes/20.13.0/): Kubernetes 1.19 or below (+-), Kubernetes 1.20 (✓), Kubernetes 1.21 or above (+-)
- [client 21.y.z](https://pypi.org/project/kubernetes/21.7.0/): Kubernetes 1.20 or below (+-), Kubernetes 1.21 (✓), Kubernetes 1.22 or above (+-)
- [client 22.y.z](https://pypi.org/project/kubernetes/22.6.0/): Kubernetes 1.21 or below (+-), Kubernetes 1.22 (✓), Kubernetes 1.23 or above (+-)
- [client 23.y.z](https://pypi.org/project/kubernetes/23.6.0/): Kubernetes 1.22 or below (+-), Kubernetes 1.23 (✓), Kubernetes 1.24 or above (+-)
- [client 24.y.z](https://pypi.org/project/kubernetes/24.2.0/): Kubernetes 1.23 or below (+-), Kubernetes 1.24 (✓), Kubernetes 1.25 or above (+-)
- [client 25.y.z](https://pypi.org/project/kubernetes/25.3.0/): Kubernetes 1.24 or below (+-), Kubernetes 1.25 (✓), Kubernetes 1.26 or above (+-)
- [client 26.y.z](https://pypi.org/project/kubernetes/26.1.0/): Kubernetes 1.25 or below (+-), Kubernetes 1.26 (✓), Kubernetes 1.27 or above (+-)
> See [here](#homogenizing-the-kubernetes-python-client-versions) for an explanation of why there is no v13-v16 release.
......@@ -129,17 +133,25 @@ between client-python versions.
| 12.0 Alpha/Beta | Kubernetes main repo, 1.16 branch | ✗ |
| 12.0 | Kubernetes main repo, 1.16 branch | ✗ |
| 17.0 Alpha/Beta | Kubernetes main repo, 1.17 branch | ✗ |
| 17.0 | Kubernetes main repo, 1.17 branch | |
| 17.0 | Kubernetes main repo, 1.17 branch | |
| 18.0 Alpha/Beta | Kubernetes main repo, 1.18 branch | ✗ |
| 18.0 | Kubernetes main repo, 1.18 branch | |
| 18.0 | Kubernetes main repo, 1.18 branch | |
| 19.0 Alpha/Beta | Kubernetes main repo, 1.19 branch | ✗ |
| 19.0 | Kubernetes main repo, 1.19 branch | |
| 19.0 | Kubernetes main repo, 1.19 branch | |
| 20.0 Alpha/Beta | Kubernetes main repo, 1.20 branch | ✗ |
| 20.0 | Kubernetes main repo, 1.20 branch | |
| 20.0 | Kubernetes main repo, 1.20 branch | |
| 21.0 Alpha/Beta | Kubernetes main repo, 1.21 branch | ✗ |
| 21.0 | Kubernetes main repo, 1.21 branch | |
| 21.0 | Kubernetes main repo, 1.21 branch | |
| 22.0 Alpha/Beta | Kubernetes main repo, 1.22 branch | ✗ |
| 22.0 | Kubernetes main repo, 1.22 branch | ✓ |
| 22.0 | Kubernetes main repo, 1.22 branch | ✗ |
| 23.0 Alpha/Beta | Kubernetes main repo, 1.23 branch | ✗ |
| 23.0 | Kubernetes main repo, 1.23 branch | ✗ |
| 24.0 Alpha/Beta | Kubernetes main repo, 1.24 branch | ✗ |
| 24.0 | Kubernetes main repo, 1.24 branch | ✓ |
| 25.0 Alpha/Beta | Kubernetes main repo, 1.25 branch | ✗ |
| 25.0 | Kubernetes main repo, 1.25 branch | ✓ |
| 26.0 Alpha/Beta | Kubernetes main repo, 1.26 branch | ✗ |
26.0 | Kubernetes main repo, 1.26 branch | ✓ |
> See [here](#homogenizing-the-kubernetes-python-client-versions) for an explanation of why there is no v13-v16 release.
......@@ -204,3 +216,5 @@ This will cause a failure in non-exec/attach calls. If you reuse your api clien
recreate it between api calls that use _stream_ and other api calls.
See more at [exec example](examples/pod_exec.py).
**[⬆ back to top](#Installation)**
......@@ -256,7 +256,7 @@ the target branch to "release-x.y". If the release is a pre-release, check the
## Announcement
Send an announcement email to kubernetes-dev@googlegroups.com with the subject: [ANNOUNCE] kubernetes python-client $VERSION is released
Send an announcement email to dev@kubernetes.io with the subject: [ANNOUNCE] kubernetes python-client $VERSION is released
## Cleanup
......
# Kubernetes Python Client
[![](https://travis-ci.org/kubernetes-client/python.svg?branch=master)](https://travis-ci.org/kubernetes-client/python)
[![](https://badge.fury.io/py/kubernetes.svg)](https://badge.fury.io/py/kubernetes)
[![](https://codecov.io/gh/kubernetes-client/python/branch/master/graph/badge.svg)](https://codecov.io/gh/kubernetes-client/python "Non-generated packages only")
[![](https://img.shields.io/pypi/pyversions/kubernetes.svg)](https://pypi.python.org/pypi/kubernetes)
[![](https://img.shields.io/badge/Kubernetes%20client-Silver-blue.svg?style=flat&colorB=C0C0C0&colorA=306CE8)](http://bit.ly/kubernetes-client-capabilities-badge)
[![](https://img.shields.io/badge/kubernetes%20client-beta-green.svg?style=flat&colorA=306CE8)](http://bit.ly/kubernetes-client-support-badge)
Python client for the [kubernetes](http://kubernetes.io/) API.
## Installation
From source:
```
git clone --recursive https://github.com/kubernetes-client/python.git
cd python
python setup.py install
```
From [PyPI](https://pypi.python.org/pypi/kubernetes/) directly:
```
pip install kubernetes
```
## Examples
list all pods:
```python
from kubernetes import client, config
# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()
v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
```
watch on namespace object:
```python
from kubernetes import client, config, watch
# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()
v1 = client.CoreV1Api()
count = 10
w = watch.Watch()
for event in w.stream(v1.list_namespace, _request_timeout=60):
print("Event: %s %s" % (event['type'], event['object'].metadata.name))
count -= 1
if not count:
w.stop()
print("Ended.")
```
More examples can be found in [examples](examples/) folder. To run examples, run this command:
```shell
python -m examples.example1
```
(replace example1 with one of the filenames in the examples folder)
## Documentation
All APIs and Models' documentation can be found at the [Generated client's README file](kubernetes/README.md)
## Compatibility
`client-python` follows [semver](http://semver.org/), so until the major version of
client-python gets increased, your code will continue to work with explicitly
supported versions of Kubernetes clusters.
#### Compatibility matrix of supported client versions
- [client 9.y.z](https://pypi.org/project/kubernetes/9.0.1/): Kubernetes 1.12 or below (+-), Kubernetes 1.13 (✓), Kubernetes 1.14 or above (+-)
- [client 10.y.z](https://pypi.org/project/kubernetes/10.1.0/): Kubernetes 1.13 or below (+-), Kubernetes 1.14 (✓), Kubernetes 1.14 or above (+-)
- [client 11.y.z](https://pypi.org/project/kubernetes/11.0.0/): Kubernetes 1.14 or below (+-), Kubernetes 1.15 (✓), Kubernetes 1.16 or above (+-)
- [client 12.y.z](https://pypi.org/project/kubernetes/12.0.1/): Kubernetes 1.15 or below (+-), Kubernetes 1.16 (✓), Kubernetes 1.17 or above (+-)
- [client 17.y.z](https://pypi.org/project/kubernetes/17.17.0/): Kubernetes 1.16 or below (+-), Kubernetes 1.17 (✓), Kubernetes 1.18 or above (+-)
- [client 18.y.z](https://pypi.org/project/kubernetes/18.20.0/): Kubernetes 1.17 or below (+-), Kubernetes 1.18 (✓), Kubernetes 1.19 or above (+-)
- [client 19.y.z](https://pypi.org/project/kubernetes/19.15.0/): Kubernetes 1.18 or below (+-), Kubernetes 1.19 (✓), Kubernetes 1.20 or above (+-)
- [client 20.y.z](https://pypi.org/project/kubernetes/20.13.0/): Kubernetes 1.19 or below (+-), Kubernetes 1.20 (✓), Kubernetes 1.21 or above (+-)
- [client 21.y.z](https://pypi.org/project/kubernetes/21.7.0/): Kubernetes 1.20 or below (+-), Kubernetes 1.21 (✓), Kubernetes 1.22 or above (+-)
- [client 22.y.z](https://pypi.org/project/kubernetes/22.6.0/): Kubernetes 1.21 or below (+-), Kubernetes 1.22 (✓), Kubernetes 1.23 or above (+-)
- [client 23.y.z](https://pypi.org/project/kubernetes/23.3.0/): Kubernetes 1.22 or below (+-), Kubernetes 1.23 (✓), Kubernetes 1.24 or above (+-)
> See [here](#homogenizing-the-kubernetes-python-client-versions) for an explanation of why there is no v13-v16 release.
Key:
* `✓` Exactly the same features / API objects in both client-python and the Kubernetes
version.
* `+` client-python has features or API objects that may not be present in the Kubernetes
cluster, either due to that client-python has additional new API, or that the server has
removed old API. However, everything they have in common (i.e., most APIs) will work.
Please note that alpha APIs may vanish or change significantly in a single release.
* `-` The Kubernetes cluster has features the client-python library can't use, either due
to the server has additional new API, or that client-python has removed old API. However,
everything they share in common (i.e., most APIs) will work.
See the [CHANGELOG](./CHANGELOG.md) for a detailed description of changes
between client-python versions.
| Client version | Canonical source for OpenAPI spec | Maintenance status |
|-----------------|--------------------------------------|-------------------------------|
| 5.0 Alpha/Beta | Kubernetes main repo, 1.9 branch | ✗ |
| 5.0 | Kubernetes main repo, 1.9 branch | ✗ |
| 6.0 Alpha/Beta | Kubernetes main repo, 1.10 branch | ✗ |
| 6.0 | Kubernetes main repo, 1.10 branch | ✗ |
| 7.0 Alpha/Beta | Kubernetes main repo, 1.11 branch | ✗ |
| 7.0 | Kubernetes main repo, 1.11 branch | ✗ |
| 8.0 Alpha/Beta | Kubernetes main repo, 1.12 branch | ✗ |
| 8.0 | Kubernetes main repo, 1.12 branch | ✗ |
| 9.0 Alpha/Beta | Kubernetes main repo, 1.13 branch | ✗ |
| 9.0 | Kubernetes main repo, 1.13 branch | ✗ |
| 10.0 Alpha/Beta | Kubernetes main repo, 1.14 branch | ✗ |
| 10.0 | Kubernetes main repo, 1.14 branch | ✗ |
| 11.0 Alpha/Beta | Kubernetes main repo, 1.15 branch | ✗ |
| 11.0 | Kubernetes main repo, 1.15 branch | ✗ |
| 12.0 Alpha/Beta | Kubernetes main repo, 1.16 branch | ✗ |
| 12.0 | Kubernetes main repo, 1.16 branch | ✗ |
| 17.0 Alpha/Beta | Kubernetes main repo, 1.17 branch | ✗ |
| 17.0 | Kubernetes main repo, 1.17 branch | ✓ |
| 18.0 Alpha/Beta | Kubernetes main repo, 1.18 branch | ✗ |
| 18.0 | Kubernetes main repo, 1.18 branch | ✓ |
| 19.0 Alpha/Beta | Kubernetes main repo, 1.19 branch | ✗ |
| 19.0 | Kubernetes main repo, 1.19 branch | ✓ |
| 20.0 Alpha/Beta | Kubernetes main repo, 1.20 branch | ✗ |
| 20.0 | Kubernetes main repo, 1.20 branch | ✓ |
| 21.0 Alpha/Beta | Kubernetes main repo, 1.21 branch | ✗ |
| 21.0 | Kubernetes main repo, 1.21 branch | ✓ |
| 22.0 Alpha/Beta | Kubernetes main repo, 1.22 branch | ✗ |
| 22.0 | Kubernetes main repo, 1.22 branch | ✓ |
| 23.0 Alpha/Beta | Kubernetes main repo, 1.23 branch | ✗ |
| 23.0 | Kubernetes main repo, 1.23 branch | ✓ |
> See [here](#homogenizing-the-kubernetes-python-client-versions) for an explanation of why there is no v13-v16 release.
Key:
* `✓` Changes in main Kubernetes repo are manually ([should be automated](https://github.com/kubernetes-client/python/issues/177)) published to client-python when they are available.
* `✗` No longer maintained; please upgrade.
Kubernetes supports [three minor releases](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/release/versioning.md#supported-releases-and-component-skew) at a time. "Support" means we expect users to be running that version in production, though we may not port fixes back before the latest minor version. For example, when v1.3 comes out, v1.0 will no longer be supported. In consistent with Kubernetes support policy, we expect to support **three GA major releases** (corresponding to three Kubernetes minor releases) at a time.
Note: There would be no maintenance for alpha/beta releases except the latest one.
**Exception to the above support rule:** Since we are running behind on releases, we will support Alpha/Beta releases for a greater number of clients until we catch up with the upstream version.
## Homogenizing the Kubernetes Python Client versions
The client releases v12 and before following a versioning schema where the major version was 4 integer positions behind the Kubernetes minor on which the client is based on. For example, v12.0.0 is based on Kubernetes v1.16, v11.0.0 is based on Kubernetes v1.15 and so on.
This created a lot of confusion tracking two different version numbers for each client release. It was decided to homogenize the version scheme starting from the Kubernetes Python client based on Kubernetes v1.17. The versioning scheme of the client from this release would be vY.Z.P where Y and Z are the Kubernetes minor and patch release numbers from Kubernets v1.Y.Z and P is the client specific patch release numbers to accommodate changes and fixes done specifically to the client. For more details, refer [this issue](https://github.com/kubernetes-client/python/issues/1244).
## Community, Support, Discussion
If you have any problem on using the package or any suggestions, please start with reaching the [Kubernetes clients slack channel](https://kubernetes.slack.com/messages/C76GB48RK/), or filing an [issue](https://github.com/kubernetes-client/python/issues) to let us know. You can also reach the maintainers of this project at [SIG API Machinery](https://github.com/kubernetes/community/tree/master/sig-api-machinery), where this project falls under.
### Code of Conduct
Participation in the Kubernetes community is governed by the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
## Troubleshooting
### SSLError on macOS
If you get an SSLError, you likely need to update your version of python. The
version that ships with macOS may not be supported.
Install the latest version of python with [brew](https://brew.sh/):
```
brew install python
```
Once installed, you can query the version of OpenSSL like so:
```
python -c "import ssl; print (ssl.OPENSSL_VERSION)"
```
You'll need a version with OpenSSL version 1.0.0 or later.
### Hostname doesn't match
If you get an `ssl.CertificateError` complaining about hostname match, your installed packages does not meet version [requirements](requirements.txt).
Specifically check `ipaddress` and `urllib3` package versions to make sure they met requirements in [requirements.txt](requirements.txt) file.
### Why Exec/Attach calls doesn't work
Starting from 4.0 release, we do not support directly calling exec or attach calls. you should use stream module to call them. so instead
of `resp = api.connect_get_namespaced_pod_exec(name, ...` you should call `resp = stream(api.connect_get_namespaced_pod_exec, name, ...`.
Using Stream will overwrite the requests protocol in _core_v1_api.CoreV1Api()_
This will cause a failure in non-exec/attach calls. If you reuse your api client object, you will need to
recreate it between api calls that use _stream_ and other api calls.
See more at [exec example](examples/pod_exec.py).
"""
This example covers the following:
- Create deployment
- Annotate deployment
"""
from kubernetes import client, config
import time
def create_deployment_object():
container = client.V1Container(
name="nginx-sample",
image="nginx",
image_pull_policy="IfNotPresent",
ports=[client.V1ContainerPort(container_port=80)],
)
# Template
template = client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": "nginx"}),
spec=client.V1PodSpec(containers=[container]))
# Spec
spec = client.V1DeploymentSpec(
replicas=1,
selector=client.V1LabelSelector(
match_labels={"app": "nginx"}
),
template=template)
# Deployment
deployment = client.V1Deployment(
api_version="apps/v1",
kind="Deployment",
metadata=client.V1ObjectMeta(name="deploy-nginx"),
spec=spec)
return deployment
def create_deployment(apps_v1_api, deployment_object):
# Create the Deployment in default namespace
# You can replace the namespace with you have created
apps_v1_api.create_namespaced_deployment(
namespace="default", body=deployment_object
)
def annotate_deployment(apps_v1_api, deployment_name, annotations):
# Annotate the Deployment in default namespace
# You can replace the namespace with you have created
apps_v1_api.patch_namespaced_deployment(
name=deployment_name, namespace='default', body=annotations)
def main():
# Loading the local kubeconfig
config.load_kube_config()
apps_v1_api = client.AppsV1Api()
deployment_obj = create_deployment_object()
create_deployment(apps_v1_api, deployment_obj)
time.sleep(1)
before_annotating = apps_v1_api.read_namespaced_deployment(
'deploy-nginx', 'default')
print('Before annotating, annotations: %s' %
before_annotating.metadata.annotations)
annotations = [
{
'op': 'add', # You can try different operations like 'replace', 'add' and 'remove'
'path': '/metadata/annotations',
'value': {
'deployment.kubernetes.io/str': 'nginx',
'deployment.kubernetes.io/int': '5'
}
}
]
annotate_deployment(apps_v1_api, 'deploy-nginx', annotations)
time.sleep(1)
after_annotating = apps_v1_api.read_namespaced_deployment(
name='deploy-nginx', namespace='default')
print('After annotating, annotations: %s' %
after_annotating.metadata.annotations)
if __name__ == "__main__":
main()
from kubernetes import client, config, utils
def main():
config.load_kube_config()
k8s_client = client.ApiClient()
# example nginx deployment
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()
\ No newline at end of file
from kubernetes import client,config,utils
def main():
config.load_kube_config()
k8s_client = client.ApiClient()
yaml_dir = 'examples/yaml_dir/'
utils.create_from_directory(k8s_client, yaml_dir,verbose=True)
if __name__ == "__main__":
main()
from kubernetes import client,config,utils
def main():
config.load_kube_config()
k8s_client = client.ApiClient()
yaml_file = 'examples/configmap-demo-pod.yml'
utils.create_from_yaml(k8s_client,yaml_file,verbose=True)
if __name__ == "__main__":
main()
---
apiVersion: v1
kind: ConfigMap
metadata:
name: game-demo
data:
# property-like keys; each key maps to a simple value
player_initial_lives: "3"
ui_properties_file_name: "user-interface.properties"
# file-like keys
game.properties: |
enemy.types=aliens,monsters
player.maximum-lives=5
user-interface.properties: |
color.good=purple
color.bad=yellow
allow.textmode=true
---
apiVersion: v1
kind: Pod
metadata:
name: configmap-demo-pod
spec:
containers:
- name: demo
image: alpine
command: ["sleep", "3600"]
env:
# Define the environment variable
- name: PLAYER_INITIAL_LIVES # Notice that the case is different here
# from the key name in the ConfigMap.
valueFrom:
configMapKeyRef:
name: game-demo # The ConfigMap this value comes from.
key: player_initial_lives # The key to fetch.
- name: UI_PROPERTIES_FILE_NAME
valueFrom:
configMapKeyRef:
name: game-demo
key: ui_properties_file_name
volumeMounts:
- name: config
mountPath: "/config"
readOnly: true
volumes:
# You set volumes at the Pod level, then mount them into containers inside that Pod
- name: config
configMap:
# Provide the name of the ConfigMap you want to mount.
name: game-demo
# An array of keys from the ConfigMap to create as files
items:
- key: "game.properties"
path: "game.properties"
- key: "user-interface.properties"
path: "user-interface.properties"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment