kubernetes.core icon indicating copy to clipboard operation
kubernetes.core copied to clipboard

How is the k8s inventory plugin being used?

Open tima opened this issue 4 years ago • 5 comments

In ansible-collections/community.kubernetes#217, @fabianvf made some modifications to the k8s inventory plugin that we believe improve its overall operation, cuts down on the "noise" and just makes more sense. This begs the question -- how is this plugin being used? Does this refactoring make sense? What is the impact, if any, of the changes? Are there other improvements to be made to help users?

ADDENDUM: Is this plugin needed at all or is it supporting an anti-pattern (Kubernetes should be managing containers in its cluster) that it should be deprecated and removed?

tima avatar Sep 08 '20 18:09 tima

@tima I can imagine as following -

# kubectl -n test get pods
NAME           READY   STATUS    RESTARTS   AGE
nginx-server   1/1     Running   0          9m43s

# cat k8s.yml
plugin: community.kubernetes.k8s
connections:
  - namespaces:
    - test

# cat main.yml
---
- hosts: all
  tasks:
    - shell: hostname

# ansible-playbook -i k8s.yml main.yml --limit namspace_test_pods -vv
...
TASK [shell] *******************************************************************
task path: /Volumes/data/src/playbooks/k8s/inventory/main.yml:4
redirecting (type: connection) ansible.builtin.kubectl to community.kubernetes.kubectl
changed: [nginx-server_nginx-server] => {"changed": true, "cmd": "hostname", "delta": "0:00:00.480764", "end": "2020-09-14 10:16:47.995239", "rc": 0, "start": "2020-09-14 10:16:47.514475", "stderr": "", "stderr_lines": [], "stdout": "nginx-server", "stdout_lines": ["nginx-server"]}
...

Akasurde avatar Sep 14 '20 10:09 Akasurde

Hello @tima, this looks like a good candidate for the Bullhorn.

alinabuzachis avatar Jan 13 '21 13:01 alinabuzachis

Hi,

I also wonder if this is an anti pattern or not.

I have a use case where an app config is store in a secret for an Ansible based operator. The "native" options available in Kubernetes imply pod restart when config resource is changed. However, using Ansible, I could template the config resource in Kubernetes and keep in sync the respective file in all replicas, no pod restart needed. For that, the inventory plugin will be helpful.

For me, it seems an anti pattern from Kubernetes perspective. However, isn’t Ansible potential being limited without it? Wouldn’t Ansible become a template manager for Kubernetes?

jobcespedes avatar May 05 '21 15:05 jobcespedes

Sorry I didn't see your comment sooner @jobcespedes. Wouldn't one of the _info modules or even the k8s lookup provide you the same capabilities?

tima avatar Jul 02 '21 18:07 tima

They do the work, along with add_host. However, once you have more than one use case, it does not feel right to use Ansible tasks to build inventories and it does not help reusability.

jobcespedes avatar Jul 02 '21 19:07 jobcespedes