I want to connect to API Kubernetes with Ansible.

I want to connect to API Kubernetes with Ansible. Ansible and Kubernetes are installed on different hosts. Unfortunately, I cannot find a normal description of how this works.
Please help with links to manuals where the process is described in detail.

  1. I want to understand if it is possible to create a key and a token by which I will easily connect to the API. I want to understand whether it is possible to create a key and a token without being bound to any namespace or service account.
  2. I want to understand how to create a key and a token in Kubernetes that ansible can use.
  3. I want to understand where to store the key and token on the ansible side. I want to understand where in the playbook to specify the key and token.

Thanks in advance!

Hi

There is already a collection to deal with Kubernetes.

  1. community.kubernetes (kubernetes.core) - https://github.com/ansible-collections/community.kubernetes
  2. community.okd (for OKD and OpenShift) - https://github.com/ansible-collections/community.okd

You can check out the code implemented in the module_utils.

Let me know if you have any questions.

Good afternoon! Thank you so much!
I use this collection when Ansible and Kubernetes are on the same host, in this scheme I do not experience any problems. I am interested in understanding how to connect to API Kubernetes, I did not find a sane description.

пятница, 20 ноября 2020 г. в 05:46:01 UTC+3, Abhijeet Kasurde:

I found only a normal description on how to connect AWX and Kubernetes, but I do not understand how to apply this to a regular Ansible.

понедельник, 23 ноября 2020 г. в 11:05:08 UTC+3, Андрей Метелкин:

As I understand it, no one did it?

понедельник, 23 ноября 2020 г. в 11:22:59 UTC+3, Андрей Метелкин:

In general, not what I wanted, but it suits me: I transferred the ~/.kube/config file from the Kubernetes master to my ansible machine.
The test playbook works great:

  • hosts: localhost
    module_defaults:
    group/k8s:
    host: https://192.168.IP.IP:PORT
    tasks:
  • name: create namespace
    k8s:
    name: test3namespace
    api_version: v1
    kind: Namespace
    state: present

The topic can be closed.

вторник, 24 ноября 2020 г. в 15:15:22 UTC+3, Андрей Метелкин: