Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Set extension for custom DNS (#3264)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminebizid authored and jackfrancis committed Jun 15, 2018
1 parent 9455a82 commit e0cb223
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 8 deletions.
38 changes: 30 additions & 8 deletions examples/vnet/kubernetesvnet-customnodesdns.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,37 @@
"masterProfile": {
"count": 1,
"dnsPrefix": "test",
"vmSize": "Standard_D2_v2",
"vmSize": "Standard_D2_v3",
"vnetSubnetId": "/subscriptions/SUB_ID/resourceGroups/RG_NAME/providers/Microsoft.Network/virtualNetworks/VNET_NAME/subnets/SUBNET_NAME",
"firstConsecutiveStaticIP": "10.239.255.239"
"firstConsecutiveStaticIP": "10.239.255.239",
"vnetCidr": "10.22.221.0/24",
"preProvisionExtension": {
"name": "register-dns",
"singleOrAll": "All"
}
},
"agentPoolProfiles": [
{
"name": "agentpri",
"name": "staging",
"count": 2,
"vmSize": "Standard_D2_v2",
"vmSize": "Standard_D2_v3",
"vnetSubnetId": "/subscriptions/SUB_ID/resourceGroups/RG_NAME/providers/Microsoft.Network/virtualNetworks/VNET_NAME/subnets/SUBNET_NAME",
"availabilityProfile": "AvailabilitySet"
"availabilityProfile": "VirtualMachineScaleSets",
"preProvisionExtension": {
"name": "register-dns",
"singleOrAll": "All"
}
},
{
"name": "agentpri2",
"name": "production",
"count": 2,
"vmSize": "Standard_D2_v2",
"vmSize": "Standard_D2_v3",
"vnetSubnetId": "/subscriptions/SUB_ID/resourceGroups/RG_NAME/providers/Microsoft.Network/virtualNetworks/VNET_NAME/subnets/SUBNET_NAME",
"availabilityProfile": "AvailabilitySet"
"availabilityProfile": "VirtualMachineScaleSets",
"preProvisionExtension": {
"name": "register-dns",
"singleOrAll": "All"
}
}
],
"linuxProfile": {
Expand All @@ -43,6 +56,15 @@
]
}
},
"extensionProfiles": [
{
"name": "register-dns",
"version": "v1",
"extensionParameters": "mydomain.com",
"rootURL": "https://raw.githubusercontent.com/Azure/acs-engine/master/extensions/dnsupdate/",
"script": "register-dns.sh"
}
],
"servicePrincipalProfile": {
"clientId": "",
"secret": ""
Expand Down
39 changes: 39 additions & 0 deletions extensions/dnsupdate/v1/register-dns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
# Add support for registering host on dns server. Must allow non-secure updates

set -e

DOMAINNAME=$1

echo $(date) " - Starting Script"

cat > /etc/network/if-up.d/register-dns <<EOFDHCP
#!/bin/sh
# only execute on the primary nic
if [ "\${IFACE}" = "eth0" ]
then
ip=\$(ip address show eth0 | awk '/inet / {print \$2}' | cut -d/ -f1)
host=\$(hostname -s)
nsupdatecmds=/var/tmp/nsupdatecmds
echo "update delete \${host}.${DOMAINNAME} a" > \$nsupdatecmds
echo "update add \${host}.${DOMAINNAME} 3600 a \${ip}" >> \$nsupdatecmds
echo "send" >> \$nsupdatecmds
nsupdate \$nsupdatecmds
fi
EOFDHCP

chmod 755 /etc/network/if-up.d/register-dns

if ! grep -Fq "${DOMAINNAME}" /etc/dhcp/dhclient.conf
then
echo $(date) " - Adding domain to dhclient.conf"

echo "supersede domain-name \"${DOMAINNAME}\";" >> /etc/dhcp/dhclient.conf
echo "prepend domain-search \"${DOMAINNAME}\";" >> /etc/dhcp/dhclient.conf
fi

# service networking restart
echo $(date) " - Restarting network"
sudo ifdown eth0 && sudo ifup eth0

0 comments on commit e0cb223

Please sign in to comment.