Kubernetes states / Module not working

59 views
Skip to first unread message

Rutger Verhoeven

unread,
Dec 27, 2024, 6:30:46 AM12/27/24
to Salt-users
Hello all,

I am trying to use the kubernetes module in salt 3006.9 and 3007.1 but i keep getting the folllowing error:

----------
          ID: label_master
    Function: kubernetes.node_label_present
        Name: node-role.kubernetes.io/master
      Result: False
     Comment: State 'kubernetes.node_label_present' was not found in SLS 'rke2'
              Reason: 'kubernetes' __virtual__ returned False: kubernetes module could not be loaded
     Changes:  

Ive tried installing with:
package
pipx
pip3
python3 -m pip install kubernetes --break-system-packages

Installed the kubernetes modules in a venv (virtual python evenvironment). 
I also tried to install saltext-kubernetes but i didnt get that to work either.

And even though all these methods don't work, i think the kubernetes module should just work out of the box.  

I used the following commands to check if the kubernetes module exists and neither of them gave back a positive result:

salt-call sys.list_modules | grep kubernetes
salt '*' sys.list_modules | grep kubernetes
salt-call --local pip.list | grep kubernetes
pip3 show kubernetes

Any help would be appreciated, since i don't know why the kubernetes module could not be found.

Kind regards,

Rutger

Dmitry Golubenko

unread,
Dec 27, 2024, 6:52:05 AM12/27/24
to salt-...@googlegroups.com
> Hello all,
>
> I am trying to use the kubernetes module in salt 3006.9 and 3007.1
> but i keep getting the folllowing error:
>
> ----------
>           ID: label_master
>     Function: kubernetes.node_label_present
>         Name: node-role.kubernetes.io/master
>       Result: False
>      Comment: State 'kubernetes.node_label_present' was not found in
> SLS 'rke2'
>               Reason: 'kubernetes' __virtual__ returned False:
> kubernetes module could not be loaded
>      Changes:  
>
> Ive tried installing with:
> package
> pipx
> pip3
> python3 -m pip install kubernetes --break-system-packages
>
> Installed the kubernetes modules in a venv (virtual python
> evenvironment). 
> I also tried to install saltext-kubernetes but i didnt get that to
> work either.

latest salt releases packed with own python(aka onedir install), try to
install modules needed for k8s with salt-pip


Rutger Verhoeven

unread,
Dec 27, 2024, 1:18:37 PM12/27/24
to salt-...@googlegroups.com
Hey,

To be honest, I cannot believe how frustrating this is. I dont mind configuring my kubernetes config files etc.
But it also seems there is no guide or anything on how to achieve this. Simply to launch kubernetes commands from salt?

I tried again to install the kubernetes module. And although when i do the command underneath it seems to install.

sudo salt-call pip.list | grep -C 1 "kubernetes"
        1.0.1
    kubernetes:
        31.0.0

When i try to run kubernetes.nodes i get the following message:

sudo salt-call kubernetes.nodes context=/home/rutger/kubernetes/rke2.yaml
'kubernetes.nodes' is not available.

I got some weird error when i try to install with salt-pip:

sudo salt-pip install kubernetes
Requirement already satisfied: kubernetes in /opt/saltstack/salt/extras-3.10 (31.0.0)
Requirement already satisfied: certifi>=14.05.14 in /opt/saltstack/salt/lib/python3.10/site-packages (from kubernetes) (2023.7.22)
Requirement already satisfied: six>=1.9.0 in /opt/saltstack/salt/lib/python3.10/site-packages (from kubernetes) (1.16.0)
Requirement already satisfied: python-dateutil>=2.5.3 in /opt/saltstack/salt/lib/python3.10/site-packages (from kubernetes) (2.8.2)
Requirement already satisfied: pyyaml>=5.4.1 in /opt/saltstack/salt/lib/python3.10/site-packages (from kubernetes) (6.0.1)
Requirement already satisfied: google-auth>=1.0.1 in /opt/saltstack/salt/extras-3.10 (from kubernetes) (2.37.0)
Requirement already satisfied: websocket-client!=0.40.0,!=0.41.*,!=0.42.*,>=0.32.0 in /opt/saltstack/salt/extras-3.10 (from kubernetes) (1.8.0)
Requirement already satisfied: requests in /opt/saltstack/salt/lib/python3.10/site-packages (from kubernetes) (2.31.0)
Requirement already satisfied: requests-oauthlib in /opt/saltstack/salt/extras-3.10 (from kubernetes) (2.0.0)
Requirement already satisfied: oauthlib>=3.2.2 in /opt/saltstack/salt/extras-3.10 (from kubernetes) (3.2.2)
Requirement already satisfied: urllib3>=1.24.2 in /opt/saltstack/salt/lib/python3.10/site-packages (from kubernetes) (1.26.18)
Requirement already satisfied: durationpy>=0.7 in /opt/saltstack/salt/extras-3.10 (from kubernetes) (0.9)
Requirement already satisfied: cachetools<6.0,>=2.0.0 in /opt/saltstack/salt/extras-3.10 (from google-auth>=1.0.1->kubernetes) (5.5.0)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /opt/saltstack/salt/extras-3.10 (from google-auth>=1.0.1->kubernetes) (0.4.1)
Requirement already satisfied: rsa<5,>=3.1.4 in /opt/saltstack/salt/extras-3.10 (from google-auth>=1.0.1->kubernetes) (4.9)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/saltstack/salt/lib/python3.10/site-packages (from requests->kubernetes) (3.2.0)
Requirement already satisfied: idna<4,>=2.5 in /opt/saltstack/salt/lib/python3.10/site-packages (from requests->kubernetes) (3.7)
Requirement already satisfied: pyasn1<0.7.0,>=0.4.6 in /opt/saltstack/salt/extras-3.10 (from pyasn1-modules>=0.2.1->google-auth>=1.0.1->kubernetes) (0.6.1)
ERROR: Exception:
Traceback (most recent call last):
  File "/opt/saltstack/salt/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 105, in _run_wrapper
    status = _inner_run()
  File "/opt/saltstack/salt/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 96, in _inner_run
    return self.run(options, args)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/relenv/runtime.py", line 638, in wrapper
    return func(self, options, args)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 67, in wrapper
    return func(self, options, args)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 468, in run
    lib_locations = get_lib_location_guesses(
  File "/opt/saltstack/salt/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 650, in get_lib_location_guesses
    scheme = get_scheme(
  File "/opt/saltstack/salt/lib/python3.10/site-packages/relenv/runtime.py", line 673, in wrapper
    scheme.platlib = TARGET.PATH
  File "<string>", line 4, in __setattr__
dataclasses.FrozenInstanceError: cannot assign to field 'platlib'


In addition i initially tried to install salt-pop and i keep getting this message:

sudo pip3 install salt-pip
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
   
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
   
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
   
    See /usr/share/doc/python3.11/README.venv for more information.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

Which is also frustrating. Why? I only have one salt-master on my vm. Again I am forced to use a python3 virtual environment.

When performing the suggestion that i should install it using pipx:

pipx install kubernetes --include-deps
'kubernetes' already seems to be installed. Not modifying existing installation in '/home/rutger/.local/pipx/venvs/kubernetes'. Pass '--force' to force installation.

Kind regards,


Rutger.

Op vr 27 dec 2024 om 12:52 schreef Dmitry Golubenko <dmitry.g...@xiag.ch>:
--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/salt-users/d3a581540734467461dd95e4eb112c99aede4dba.camel%40xiag.ch.

Phipps, Thomas

unread,
Dec 27, 2024, 6:56:55 PM12/27/24
to salt-...@googlegroups.com
so lots of things here to unpack.. first that salt-pip error is from updating pip in the salt environment. don't do that. if you are lucky
`/opt/saltstack/salt/bin/python3 -m pip install pip==24.0` will fix it. if not. you have to uninstall all of salt and reinstall it.

next the kub library salt is expecting is very old. like 3.0.0 old.

next use https://github.com/salt-extensions/saltext-kubernetes instead. the internal salt stuff is being replaced by that. and will go away in 3008.
no updates to the current internal module will come and it REALLY needs them.


Rutger Verhoeven

unread,
Dec 28, 2024, 12:23:33 PM12/28/24
to Salt-users
Thank you all for the tips.

I took a breather and reinstalled salt to 3006.9. I found the instructions to install salt-ext kubernetes (https://salt-extensions.github.io/saltext-kubernetes/topics/installation.html)

It turns out (as usual) i took a wrong approach. I know understand that i can use the k8s functions by using module.run.

However now i try to use the k8s functions i keep getting error 111 :
I have tried several options.  But it seems i do not understand how this works. The documentation lacks alot of context for me

salt code:
label_master_test:
module.run:
- name: k8s.get_labels
- node: {{ grains['id'] }}
- env:
KUBECONFIG: /etc/rancher/rke2/rke2.yaml
- context: default

output:
----------
          ID: label_master_test
    Function: module.run
        Name: k8s.get_labels
      Result: True
     Comment: Module function k8s.get_labels executed
     Started: 18:13:30.747986
    Duration: 39.543 ms
     Changes:  
              ----------
              ret:
                  ----------
                  labels:
                      ----------
                      error:
                          [Errno 111] Connection refused

Any help and especially explanation is appreciative!


Kind regards,


Rutger


Op zaterdag 28 december 2024 om 00:56:55 UTC+1 schreef whyt...@bad4.us:
Reply all
Reply to author
Forward
0 new messages