Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible module to create & manage namespace in AKS #1232

Closed
sudheerkaramchand opened this issue Aug 1, 2023 · 7 comments · Fixed by #1497
Closed

Ansible module to create & manage namespace in AKS #1232

sudheerkaramchand opened this issue Aug 1, 2023 · 7 comments · Fixed by #1497
Labels
enhancement New feature or request has_pr PR fixes have been made medium_priority Medium priority

Comments

@sudheerkaramchand
Copy link

Currently I'm working on managing existing AKS cluster created through ansible playbook and now would like to create and manage the AKS cluster using playbooks. For eg creating pods, list pods, create namespace etc.

In ansible azure_rm_aks module there is no supported parameters given to create a pipeline to list pods or create namespace.

https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_aks_module.html

Kindly suggest how I overcome this issue.
`---

  • hosts: localhost
    connection: local
    gather_facts: yes

    tasks:

    • name: Get facts for one Azure Kubernetes Service
      azure.azcollection.azure_rm_aks_info:
      name: myAKSCluster
      resource_group: myResourceGroup
      `
@sudheerkaramchand
Copy link
Author

sudheerkaramchand commented Aug 1, 2023

@yuwzho @Fred-sun

@Fred-sun
Copy link
Collaborator

Fred-sun commented Aug 2, 2023

@sudheerkaramchand Could you explain your requirements in detail? This will help to resolve any issues you may encounter, and listing all clusters under resource groups or subscription_id is already supported in PR #1229. Thank you very much!

@Fred-sun Fred-sun added medium_priority Medium priority work in In trying to solve, or in working with contributors labels Aug 2, 2023
@sudheerkaramchand
Copy link
Author

@Fred-sun Thank you for your response.
I'm working on Ansible currently and created a AKS cluster in Azure using Ansible playbook which is deployed successfully. Now the actual requirement is to manage the AKS cluster in Azure from local machine through playbooks. I'm able to connect to the AKS cluster from local machine and able to list pods and create namespace using the kubectl commands.

Now I want to do the same thing using Ansible playbooks to create namespace and list pods (this is part of testing) and noticed there is no supporting module for AKS where I can list pods or create namespace but can find the same in open source k8s module (link below)
https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html

To run a playbook to list pods and create namespace, which module I can use here as Azure_rm_aks does not have kind and namespace parameter given in Ansible documentation (link below)
https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_aks_module.html

@bigfleet
Copy link

bigfleet commented Aug 3, 2023

Once you've created the cluster with the azure_rm_aks module, you begin to use the k8s modules with it. When I do this, I store the kubeconfig result from the azure_rm_aks module and pass that into the k8s module. Part of the promise of kubernetes is that after you have a cluster, they are all meant to run the same. You can start to use the kubernetes.core ones after that, as long as you manage which cluster you're interacting with successfully.

@sudheerkaramchand
Copy link
Author

@bigfleet Thank you for your response. Could you please elaborate or provide any example on how I can store the kubeconfig result and passing to k8s module.

@bigfleet
Copy link

- name: Store kube/config in tempfile
  ansible.builtin.tempfile:
    state: file
  register: aks_kubeconfig_tmpfile

- name: "Create an {{ k8sconfig.cluster_name }} AKS instance"
  azure.azcollection.azure_rm_aks: "{{ _aks_module_params }}"
  register: azure_aks_cluster

- name: Place kubeconfig onto filesystem temporarily
  copy: 
    content: "{{ azure_aks_cluster.kube_config }}"
    dest: "{{ aks_kubeconfig_tmpfile.path }}"
    mode: '0600'
  when: azure_aks_cluster.skip_reason is not defined

- set_fact:
    kubeconfig: "{{ aks_kubeconfig_tmpfile.path }}"

- name: Get Cluster information
  kubernetes.core.k8s_info:
    kind: namespace
    kubeconfig: "{{ kubeconfig }}"
  register: azure_aks_namespace_status
  retries: 6
  delay: 10
  until: azure_aks_namespace_status is not failed

@Fred-sun
Copy link
Collaborator

@bigfleet @sudheerkaramchand Added in #1497

@Fred-sun Fred-sun added enhancement New feature or request has_pr PR fixes have been made and removed work in In trying to solve, or in working with contributors labels Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request has_pr PR fixes have been made medium_priority Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants