I want to connect to API Kubernetes with Ansible.

63 views
Skip to first unread message

Андрей Метелкин

unread,
Nov 19, 2020, 10:31:38 AM11/19/20
to Ansible Project
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!

Abhijeet Kasurde

unread,
Nov 19, 2020, 9:46:01 PM11/19/20
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/282e2245-35b8-4f3d-8c6b-84c9181afc6an%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Андрей Метелкин

unread,
Nov 23, 2020, 3:05:08 AM11/23/20
to Ansible Project
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:

Андрей Метелкин

unread,
Nov 23, 2020, 3:22:59 AM11/23/20
to Ansible Project
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, Андрей Метелкин:

Андрей Метелкин

unread,
Nov 24, 2020, 7:15:22 AM11/24/20
to Ansible Project
As I understand it, no one did it?

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

Андрей Метелкин

unread,
Nov 25, 2020, 6:57:01 AM11/25/20
to Ansible Project
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, Андрей Метелкин:
Reply all
Reply to author
Forward
0 new messages