The kubernetes Python library missing with V1Eviction API
trying to cordon a node. I get the error The kubernetes Python library missing with V1Eviction API
- name: Cordoning worker node to reboot.
kubernetes.core.k8s_drain:
state: cordon
name: "{{ ansible_hostname }}"
delegate_to: 127.0.0.1
Galaxy output
ansible-galaxy collection list|grep kube
community.kubernetes 2.0.1
community.kubevirt 1.0.0
kubernetes.core 2.3.2
ansible version:
ansible [core 2.12.10]
config file = /home/brad/infrastructure/ansible_upgrade/ansible.cfg
configured module search path = ['/home/brad/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /home/brad/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0]
jinja version = 2.10.1
libyaml = True
OS: Linux development1 5.4.0-135-generic #152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
output of -vvv
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_kubernetes.core.k8s_drain_payload_misro2xs/ansible_kubernetes.core.k8s_drain_payload.zip/ansible_collections/kubernetes/core/plugins/modules/k8s_drain.py", line 154, in <module>
ModuleNotFoundError: No module named 'kubernetes'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/ansible_kubernetes.core.k8s_drain_payload_misro2xs/ansible_kubernetes.core.k8s_drain_payload.zip/ansible_collections/kubernetes/core/plugins/modules/k8s_drain.py", line 157, in <module>
ModuleNotFoundError: No module named 'kubernetes'
fatal: [worker14.server.local -> 127.0.0.1]: FAILED! => {
"changed": false,
"error": "No module named 'kubernetes'",
"invocation": {
"module_args": {
"api_key": null,
"ca_cert": null,
"client_cert": null,
"client_key": null,
"context": null,
"delete_options": {
"delete_emptydir_data": false,
"disable_eviction": false,
"force": false,
"ignore_daemonsets": false,
"terminate_grace_period": null,
"wait_sleep": 5,
"wait_timeout": null
},
"host": null,
"impersonate_groups": null,
"impersonate_user": null,
"kubeconfig": null,
"name": "worker14",
"no_proxy": null,
"password": null,
"persist_config": null,
"proxy": null,
"proxy_headers": null,
"state": "cordon",
"username": null,
"validate_certs": null
}
},
"msg": "The kubernetes Python library missing with V1Eviction API"
}
@Daxcor69 Thanks for reporting this issue. Could you please let us know what is the version Kubernetes Python Client? like -
# pip list |grep kubernetes
kubernetes 23.3.0
brad@development1:~$ pip list |grep kubernetes
kubernetes 25.3.0
--- Logging error ---
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/utils/logging.py", line 177, in emit
self.console.print(renderable, overflow="ignore", crop=False, style=style)
File "/usr/local/lib/python3.8/dist-packages/pip/_vendor/rich/console.py", line 1673, in print
extend(render(renderable, render_options))
File "/usr/local/lib/python3.8/dist-packages/pip/_vendor/rich/console.py", line 1305, in render
for render_output in iter_render:
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/utils/logging.py", line 134, in __rich_console__
for line in lines:
File "/usr/local/lib/python3.8/dist-packages/pip/_vendor/rich/segment.py", line 249, in split_lines
for segment in segments:
File "/usr/local/lib/python3.8/dist-packages/pip/_vendor/rich/console.py", line 1283, in render
renderable = rich_cast(renderable)
File "/usr/local/lib/python3.8/dist-packages/pip/_vendor/rich/protocol.py", line 36, in rich_cast
renderable = cast_method()
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/self_outdated_check.py", line 130, in __rich__
pip_cmd = get_best_invocation_for_this_pip()
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/utils/entrypoints.py", line 58, in get_best_invocation_for_this_pip
if found_executable and os.path.samefile(
File "/usr/lib/python3.8/genericpath.py", line 101, in samefile
s2 = os.stat(f2)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/pip'
Call stack:
File "/usr/local/bin/pip", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/cli/main.py", line 70, in main
return command.main(cmd_args)
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/cli/base_command.py", line 101, in main
return self._main(args)
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/cli/base_command.py", line 223, in _main
self.handle_pip_version_check(options)
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/cli/req_command.py", line 190, in handle_pip_version_check
pip_self_version_check(session, options)
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/self_outdated_check.py", line 236, in pip_self_version_check
logger.warning("[present-rich] %s", upgrade_prompt)
File "/usr/lib/python3.8/logging/__init__.py", line 1458, in warning
self._log(WARNING, msg, args, **kwargs)
File "/usr/lib/python3.8/logging/__init__.py", line 1589, in _log
self.handle(record)
File "/usr/lib/python3.8/logging/__init__.py", line 1599, in handle
self.callHandlers(record)
File "/usr/lib/python3.8/logging/__init__.py", line 1661, in callHandlers
hdlr.handle(record)
File "/usr/lib/python3.8/logging/__init__.py", line 954, in handle
self.emit(record)
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/utils/logging.py", line 179, in emit
self.handleError(record)
Message: '[present-rich] %s'
Arguments: (UpgradePrompt(old='22.2.2', new='22.3.1'),)
Kubernetes version:
Client Version: v1.26.0 Kustomize Version: v4.5.7 Server Version: v1.26.0
I know it is the holidays.. any thoughts on how I can proceed?
@Daxcor69 I can't reproduce this. I just confirmed that the k8s_drain module works with collection version 2.3.2 and the python kubernetes library version 25.3.0. The error you are getting suggests that the python kubernetes library is not installed for the interpreter that's executing the module.
You can try specifying the path to the python interpreter that has the kubernetes library installed just to verify that it's working. Use something like:
- name: Cordoning worker node to reboot.
kubernetes.core.k8s_drain:
state: cordon
name: "{{ ansible_hostname }}"
delegate_to: 127.0.0.1
vars:
ansible_python_interpreter: /path/to/python