使用 ansible 管理 Azure Kubernetes Service (AKS) instance 小記
OS: openSUSE Leap 15
ansible: 2.7.10
之前的 Azure AKS instance 都是使用 az aks create 指令建立的
但是久了有的時候真的會一時忘記 az aks 指令要下哪些 …..
所以今天就參考官方網站用 ansible 寫了 playbook 來建立以及移除 AKS instance
建立 AKS instance:
我的 playbook 如下, 檔案名稱 azure_create_aks_instance.yml
---
# Azure AKS 相關測試
# edit by sakana 2019/5/9
- name: use when conditionals and setup module
hosts: localhost
connection: local
#
vars_prompt:
- name: "client_id"
prompt: "Enter client_id"
private: no
- name: "client_secret"
prompt: "Enter client_secret"
private: no
- name: "resource_group"
prompt: "Enter resource group name"
private: no
default: sakanaK8s
- name: "aks_instance_name"
prompt: "Enter aks instance name"
private: no
default: test01
- name: "aks_location"
prompt: "Enter aks location"
private: no
default: eastus
- name: "dns_prefix"
prompt: "Enter aks dns_prefix"
private: no
default: sakanamax
- name: "admin_username"
prompt: "Enter admin user's name"
private: no
default: sakana
- name: "aks_ssh_key"
prompt: "Enter aks ssh public key"
private: no
- name: "aks_pool_name"
prompt: "Enter aks pool name"
private: no
default: testsakana
- name: "aks_count"
prompt: "Enter how many node do you want to create?"
private: no
default: 1
- name: "vm_size"
prompt: "Enter vm size for each node"
private: no
default: Standard_B2s
tasks:
- name: Create AKS instance
azure_rm_aks:
name: "{{ aks_instance_name }}"
resource_group: "{{ resource_group }}"
dns_prefix: "{{ dns_prefix }}"
linux_profile:
admin_username: "{{ admin_username }}"
ssh_key: "{{ aks_ssh_key }}"
service_principal:
client_id: "{{ client_id }}"
client_secret: "{{ client_secret }}"
agent_pool_profiles:
- name: "{{ aks_pool_name }}"
count: "{{ aks_count }}"
vm_size: "{{ vm_size }}"
建立方式
- 必須先有 client_id 以及 client_secret
- 有 ssh public key
使用 ansible-playbook 指令建立
> ansible-playbook azure_create_aks_instance.yml
依照詢問輸入相關資料就可以方便建立
建立完成之後我還是用 az ask 指令取得認證資訊 ( 從 web console 複製 )
> az aks get-credentials --resource-group sakanaK8s --name test01
接下來實驗
移除 AKS instance:
我的 playbook 如下, 檔案名稱 azure_remove_aks_instance.yml
---
# Azure AKS 相關測試
# edit by sakana 2019/5/9
- name: use when conditionals and setup module
hosts: localhost
connection: local
#
vars_prompt:
- name: "aks_instance_name"
prompt: "Enter aks instance name you want to REMOVE"
private: no
default: test01
- name: "resource_group"
prompt: "Enter resource group name"
private: no
default: sakanaK8s
tasks:
- name: Remove AKS instance
azure_rm_aks:
name: "{{ aks_instance_name }}"
resource_group: "{{ resource_group }}"
state: absent
移除的時候一樣用 ansible-playbook 指令
> ansible-playbook azure_remove_aks_instance.yml
這樣以後建立 AKS instance 就相對方便了
~ enjoy it
:)
Reference:
沒有留言:
張貼留言