# I want to connect to API Kubernetes with Ansible.

**URL:** <https://forum.ansible.com/t/i-want-to-connect-to-api-kubernetes-with-ansible/34210>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [November 19, 2020, 3:31pm UTC](https://forum.ansible.com/t/i-want-to-connect-to-api-kubernetes-with-ansible/34210 "2020-11-19T15:31:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![user77](https://avatars.discourse-cdn.com/v4/letter/u/a183cd/32.png) [@user77](https://forum.ansible.com/u/user77)\
**Post date:** [November 19, 2020, 3:31pm UTC](https://forum.ansible.com/t/i-want-to-connect-to-api-kubernetes-with-ansible/34210/1 "2020-11-19T15:31:38Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [November 20, 2020, 2:45am UTC](https://forum.ansible.com/t/i-want-to-connect-to-api-kubernetes-with-ansible/34210/2 "2020-11-20T02:45:17Z")

</div>

Hi

There is already a collection to deal with Kubernetes.

1. community.kubernetes (kubernetes.core) - [https://github.com/ansible-collections/community.kubernetes](https://github.com/ansible-collections/community.kubernetes)
2. community.okd (for OKD and OpenShift) - [https://github.com/ansible-collections/community.okd](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.

---

<div class="post-metadata">

**Author:** ![user77](https://avatars.discourse-cdn.com/v4/letter/u/a183cd/32.png) [@user77](https://forum.ansible.com/u/user77)\
**Post date:** [November 23, 2020, 8:05am UTC](https://forum.ansible.com/t/i-want-to-connect-to-api-kubernetes-with-ansible/34210/3 "2020-11-23T08:05:07Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![user77](https://avatars.discourse-cdn.com/v4/letter/u/a183cd/32.png) [@user77](https://forum.ansible.com/u/user77)\
**Post date:** [November 23, 2020, 8:22am UTC](https://forum.ansible.com/t/i-want-to-connect-to-api-kubernetes-with-ansible/34210/4 "2020-11-23T08:22:59Z")

</div>

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, Андрей Метелкин:

---

<div class="post-metadata">

**Author:** ![user77](https://avatars.discourse-cdn.com/v4/letter/u/a183cd/32.png) [@user77](https://forum.ansible.com/u/user77)\
**Post date:** [November 24, 2020, 12:15pm UTC](https://forum.ansible.com/t/i-want-to-connect-to-api-kubernetes-with-ansible/34210/5 "2020-11-24T12:15:22Z")

</div>

As I understand it, no one did it?

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

---

<div class="post-metadata">

**Author:** ![user77](https://avatars.discourse-cdn.com/v4/letter/u/a183cd/32.png) [@user77](https://forum.ansible.com/u/user77)\
**Post date:** [November 25, 2020, 11:57am UTC](https://forum.ansible.com/t/i-want-to-connect-to-api-kubernetes-with-ansible/34210/6 "2020-11-25T11:57:01Z")

</div>

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:](https://192.168.17.167:6443/)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, Андрей Метелкин:
