1. Answers
  2. Enabling DNS Resolution for Azure Kubernetes Service (AKS) via A Records

How do I enable DNS resolution for Azure Kubernetes Service (AKS) via A records?

To enable DNS resolution for an Azure Kubernetes Service (AKS) cluster, we will set up an Azure DNS zone and create A records that point to our AKS cluster’s services. This configuration ensures that the services within the cluster can be resolved via human-readable domain names.

This example involves:

  1. Creating an Azure Kubernetes Service (AKS) cluster.
  2. Setting up an Azure DNS zone.
  3. Creating A records in the DNS zone to point to our AKS cluster services.
import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
import * as std from "@pulumi/std";

// Resource group for the AKS cluster and DNS zone
const example = new azure.core.ResourceGroup("example", {
    name: "example-resources",
    location: "East US",
});
// Azure Kubernetes Service cluster
const exampleKubernetesCluster = new azure.containerservice.KubernetesCluster("example", {
    name: "exampleaks",
    location: example.location,
    resourceGroupName: example.name,
    dnsPrefix: "exampleaks",
    defaultNodePool: {
        name: "default",
        nodeCount: 1,
        vmSize: "Standard_DS2_v2",
    },
    identity: {
        type: "SystemAssigned",
    },
    networkProfile: {
        networkPlugin: "azure",
        dnsServiceIp: "10.0.0.10",
        serviceCidr: "10.0.0.0/16",
        dockerBridgeCidr: "172.17.0.1/16",
    },
    tags: {
        environment: "testing",
    },
});
// Azure DNS zone
const exampleZone = new azure.dns.Zone("example", {
    name: "example.com",
    resourceGroupName: example.name,
});
// A Record for the AKS service
const exampleARecord = new azure.dns.ARecord("example", {
    name: "myaks",
    zoneName: exampleZone.name,
    resourceGroupName: example.name,
    ttl: 300,
    records: [exampleKubernetesCluster.kubeletIdentity.apply(kubeletIdentity => kubeletIdentity.clientId)],
});
export const dnsZoneName = exampleZone.name;
export const kubernetesClusterName = exampleKubernetesCluster.name;
export const aRecordFqdn = std.joinOutput({
    separator: ".",
    input: [
        exampleARecord.name,
        exampleARecord.zoneName,
    ],
}).apply(invoke => invoke.result);

In this configuration:

  • The azurerm_kubernetes_cluster resource sets up an AKS cluster.
  • The azurerm_dns_zone resource creates a DNS zone named “example.com”.
  • The azurerm_dns_a_record resource creates an A record “myaks.example.com” pointing to the AKS cluster’s services.

We use the Azure provider to specify configurations and fetch necessary parameters from the created resources.

In summary, we successfully set up DNS resolution for our AKS services by creating an Azure DNS zone and A records pointing to the desired services within the AKS cluster.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up