Skip to content

Commit a902547

Browse files
authored
feat: automated creation of Azure NAT Gateway (#44)
Signed-off-by: Andrew Block <[email protected]>
1 parent c3560f0 commit a902547

File tree

3 files changed

+94
-8
lines changed

3 files changed

+94
-8
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ Future work includes:
2727
- If not using ARO you must either provide your own CA signed certs, or use let's encrypt.
2828
- Must be on 4.16.14 or later.
2929

30-
> [!IMPORTANT]
31-
> Users must provide a NAT Gateway attached to the worker node subnet when using Azure.
32-
3330
## Major versions
3431

3532
### `2.*`
@@ -90,11 +87,6 @@ This only has to be done once.
9087
> [!NOTE]
9188
> Once generated this script will not override secrets. Be careful when doing multiple tests.
9289
93-
#### Check your cluster on Azure has a NAT gateway attached
94-
OpenShift does not require a NAT gateway by default, however, peer-pods do require a NAT gateway attached to the worker node subnet.
95-
96-
> [!NOTE]
97-
>
9890
#### Configuring let's encrypt.
9991

10092
> [!IMPORTANT]
@@ -148,6 +140,7 @@ Red Hat a demo platform. This allows easy access for Red Hat associates and part
148140
2. Get access to an [Azure Subscription Based Blank Open Environment](https://catalog.demo.redhat.com/catalog?category=Open_Environments&search=azure&item=babylon-catalog-prod%2Fazure-gpte.open-environment-azure-subscription.prod).
149141
3. Import the required azure environmental variables (see coded block):
150142
```
143+
export GUID=
151144
export CLIENT_ID=
152145
export PASSWORD=
153146
export TENANT=

ansible/azure-nat-gateway.yaml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
3+
- name: Configure Azure NAT Gateway
4+
become: false
5+
connection: local
6+
hosts: localhost
7+
gather_facts: false
8+
vars:
9+
kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}"
10+
resource_prefix: "coco"
11+
tasks:
12+
- name: Get Azure credentials
13+
kubernetes.core.k8s_info:
14+
kind: Secret
15+
namespace: openshift-cloud-controller-manager
16+
name: azure-cloud-credentials
17+
register: azure_credentials
18+
retries: 20
19+
delay: 5
20+
21+
- name: Get Azure credentials
22+
kubernetes.core.k8s_info:
23+
kind: ConfigMap
24+
namespace: openshift-cloud-controller-manager
25+
name: cloud-conf
26+
register: azure_cloud_conf
27+
retries: 20
28+
delay: 5
29+
30+
- name: Set facts
31+
ansible.builtin.set_fact:
32+
azure_subscription_id: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['subscriptionId'] }}"
33+
azure_tenant_id: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['tenantId'] }}"
34+
azure_resource_group: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['vnetResourceGroup'] }}"
35+
azure_client_id: "{{ azure_credentials.resources[0]['data']['azure_client_id'] | b64decode }}"
36+
azure_client_secret: "{{ azure_credentials.resources[0]['data']['azure_client_secret'] | b64decode }}"
37+
azure_vnet: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['vnetName'] }}"
38+
azure_subnet: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['subnetName'] }}"
39+
coco_public_ip_name: "{{ resource_prefix }}-pip"
40+
coco_nat_gateway_name: "{{ resource_prefix }}-nat-gateway"
41+
no_log: true
42+
43+
- name: Create Public IP for NAT Gateway
44+
azure_rm_publicipaddress:
45+
subscription_id: "{{ azure_subscription_id }}"
46+
tenant: "{{ azure_tenant_id }}"
47+
client_id: "{{ azure_client_id }}"
48+
secret: "{{ azure_client_secret }}"
49+
resource_group: "{{ azure_resource_group }}"
50+
name: "{{ coco_public_ip_name }}"
51+
sku: "standard"
52+
allocation_method: "static"
53+
54+
- name: Retrieve Public IP for NAT Gateway
55+
azure_rm_publicipaddress_info:
56+
subscription_id: "{{ azure_subscription_id }}"
57+
tenant: "{{ azure_tenant_id }}"
58+
client_id: "{{ azure_client_id }}"
59+
secret: "{{ azure_client_secret }}"
60+
resource_group: "{{ azure_resource_group }}"
61+
name: "{{ coco_public_ip_name }}"
62+
register: coco_gw_public_ip
63+
64+
- name: Create NAT Gateway
65+
azure.azcollection.azure_rm_natgateway:
66+
subscription_id: "{{ azure_subscription_id }}"
67+
tenant: "{{ azure_tenant_id }}"
68+
client_id: "{{ azure_client_id }}"
69+
secret: "{{ azure_client_secret }}"
70+
resource_group: "{{ azure_resource_group }}"
71+
name: "{{ coco_nat_gateway_name }}"
72+
idle_timeout_in_minutes: 10
73+
sku:
74+
name: standard
75+
public_ip_addresses:
76+
- "{{ coco_gw_public_ip.publicipaddresses[0].id }}"
77+
register: coco_natgw
78+
79+
- name: Update the worker subnet to associate NAT gateway
80+
azure.azcollection.azure_rm_subnet:
81+
subscription_id: "{{ azure_subscription_id }}"
82+
tenant: "{{ azure_tenant_id }}"
83+
client_id: "{{ azure_client_id }}"
84+
secret: "{{ azure_client_secret }}"
85+
resource_group: "{{ azure_resource_group }}"
86+
name: "{{ azure_subnet }}"
87+
virtual_network_name: "{{ azure_vnet }}"
88+
nat_gateway: "{{ coco_nat_gateway_name }}"
89+
...

values-simple.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ clusterGroup:
126126
#image: quay.io/hybridcloudpatterns/ansible-edge-gitops-ee:latest
127127
verbosity: -vvv
128128
timeout: 3600
129+
- name: configure-azure-nat-gateway
130+
playbook: ansible/azure-nat-gateway.yaml
131+
verbosity: -vvv
132+
timeout: 3600
129133
managedClusterGroups:
130134
exampleRegion:
131135
name: group-one

0 commit comments

Comments
 (0)