2016-12-12 16:21:56 +00:00
# Kubernetes on Azure with Azure Resource Group Templates
Provision the base infrastructure for a Kubernetes cluster by using [Azure Resource Group Templates ](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates )
## Status
This will provision the base infrastructure (vnet, vms, nics, ips, ...) needed for Kubernetes in Azure into the specified
2017-06-16 17:25:46 +00:00
Resource Group. It will not install Kubernetes itself, this has to be done in a later step by yourself (using kubespray of course).
2016-12-12 16:21:56 +00:00
## Requirements
2018-06-07 04:47:15 +00:00
- [Install azure-cli ](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest )
- [Login with azure-cli ](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli?view=azure-cli-latest )
2016-12-12 16:21:56 +00:00
- Dedicated Resource Group created in the Azure Portal or through azure-cli
## Configuration through group_vars/all
2020-05-01 06:46:12 +00:00
You have to modify at least two variables in group_vars/all. The one is the **cluster_name** variable, it must be globally
unique due to some restrictions in Azure. The other one is the **ssh_public_keys** variable, it must be your ssh public
key to access your azure virtual machines. Most other variables should be self explanatory if you have some basic Kubernetes
2016-12-12 16:21:56 +00:00
experience.
## Bastion host
You can enable the use of a Bastion Host by changing **use_bastion** in group_vars/all to **true** . The generated
templates will then include an additional bastion VM which can then be used to connect to the masters and nodes. The option
2020-12-22 12:44:26 +00:00
also removes all public IPs from all other VMs.
2016-12-12 16:21:56 +00:00
## Generating and applying
To generate and apply the templates, call:
```shell
2020-12-22 12:44:26 +00:00
./apply-rg.sh < resource_group_name >
2016-12-12 16:21:56 +00:00
```
If you change something in the configuration (e.g. number of nodes) later, you can call this again and Azure will
take care about creating/modifying whatever is needed.
## Clearing a resource group
If you need to delete all resources from a resource group, simply call:
```shell
2020-12-22 12:44:26 +00:00
./clear-rg.sh < resource_group_name >
2016-12-12 16:21:56 +00:00
```
**WARNING** this really deletes everything from your resource group, including everything that was later created by you!
2022-05-20 06:39:12 +00:00
## Installing Ansible and the dependencies
Install Ansible according to [Ansible installation guide ](/docs/ansible.md#installing-ansible )
2017-06-16 17:25:46 +00:00
## Generating an inventory for kubespray
2016-12-12 16:21:56 +00:00
After you have applied the templates, you can generate an inventory with this call:
```shell
2020-12-22 12:44:26 +00:00
./generate-inventory.sh < resource_group_name >
2016-12-12 16:21:56 +00:00
```
2017-06-16 17:25:46 +00:00
It will create the file ./inventory which can then be used with kubespray, e.g.:
2016-12-12 16:21:56 +00:00
```shell
2020-12-22 12:44:26 +00:00
cd kubespray-root-dir
ansible-playbook -i contrib/azurerm/inventory -u devops --become -e "@inventory/sample/group_vars/all/all.yml" cluster.yml
2016-12-12 16:21:56 +00:00
```