Skip to content

Commit 9f46655

Browse files
Merge pull request #277073 from tamram/tamram24-0603
update example to include user-assigned MI
2 parents 88eee9a + d3de126 commit 9f46655

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

articles/aks/static-ip.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: allensu
77
ms.subservice: aks-networking
88
ms.custom: devx-track-azurecli
99
ms.topic: how-to
10-
ms.date: 09/22/2023
10+
ms.date: 06/03/2024
1111
#Customer intent: As a cluster operator or developer, I want to create and manage static IP address resources in Azure that I can use beyond the lifecycle of an individual Kubernetes service deployed in an AKS cluster.
1212
---
1313

@@ -65,11 +65,53 @@ This article shows you how to create a static public IP address and assign it to
6565
6666
## Create a service using the static IP address
6767
68-
1. Ensure the cluster identity used by the AKS cluster has delegated permissions to the public IP's resource group using the [`az role assignment create`][az-role-assignment-create] command.
68+
1. First, determine which type of managed identity your AKS cluster is using, system-assigned or user-assigned. If you're not certain, call the [az aks show][az-aks-show] command and query for the identity's *type* property.
69+
70+
```azurecli
71+
az aks show \
72+
--name myAKSCluster \
73+
--resource-group myResourceGroup \
74+
--query identity.type \
75+
--output tsv
76+
```
77+
78+
If the cluster is using a managed identity, the value of the *type* property will be either **SystemAssigned** or **UserAssigned**.
79+
80+
If the cluster is using a service principal, the value of the *type* property will be null. Consider upgrading your cluster to use a managed identity.
81+
82+
1. If your AKS cluster uses a system-assigned managed identity, then query for the managed identity's principal ID as follows:
83+
84+
```azurecli-interactive
85+
# Get the principal ID for a system-assigned managed identity.
86+
CLIENT_ID=$(az aks show \
87+
--name myAKSCluster \
88+
--resource-group myNetworkResourceGroup \
89+
--query identity.principalId \
90+
--output tsv)
91+
```
92+
93+
If your AKS cluster uses a user-assigned managed identity, then the principal ID will be null. Query for the user-assigned managed identity's client ID instead:
94+
95+
```azurecli-interactive
96+
# Get the client ID for a user-assigned managed identity.
97+
CLIENT_ID=$(az aks show \
98+
--name myAKSCluster \
99+
--resource-group myNetworkResourceGroup \
100+
--query identity.userAssignedIdentities.*.clientId \
101+
--output tsv
102+
```
103+
104+
1. Assign delegated permissions for the managed identity used by the AKS cluster for the public IP's resource group by calling the [`az role assignment create`][az-role-assignment-create] command.
69105
70106
```azurecli-interactive
71-
CLIENT_ID=$(az aks show --name myAKSCluster --resource-group myNetworkResourceGroup --query identity.principalId -o tsv)
72-
RG_SCOPE=$(az group show --name <node resource group> --query id -o tsv)
107+
# Get the resource ID for the node resource group.
108+
RG_SCOPE=$(az group show \
109+
--name <node resource group> \
110+
--query id \
111+
--output tsv)
112+
113+
# Assign the Network Contributor role to the managed identity,
114+
# scoped to the node resource group.
73115
az role assignment create \
74116
--assignee ${CLIENT_ID} \
75117
--role "Network Contributor" \
@@ -79,7 +121,7 @@ This article shows you how to create a static public IP address and assign it to
79121
> [!IMPORTANT]
80122
> If you customized your outbound IP, make sure your cluster identity has permissions to both the outbound public IP and the inbound public IP.
81123
82-
2. Create a file named `load-balancer-service.yaml` and copy in the contents of the following YAML file, providing your own public IP address created in the previous step and the node resource group name.
124+
1. Create a file named `load-balancer-service.yaml` and copy in the contents of the following YAML file, providing your own public IP address created in the previous step and the node resource group name.
83125
84126
> [!IMPORTANT]
85127
> Adding the `loadBalancerIP` property to the load balancer YAML manifest is deprecating following [upstream Kubernetes](https://github.com/kubernetes/kubernetes/pull/107235). While current usage remains the same and existing services are expected to work without modification, we **highly recommend setting service annotations** instead. To set service annotations, you can either use `service.beta.kubernetes.io/azure-pip-name` for public IP name, or use `service.beta.kubernetes.io/azure-load-balancer-ipv4` for an IPv4 address and `service.beta.kubernetes.io/azure-load-balancer-ipv6` for an IPv6 address, as shown in the example YAML.
@@ -103,7 +145,7 @@ This article shows you how to create a static public IP address and assign it to
103145
> [!NOTE]
104146
> Adding the `service.beta.kubernetes.io/azure-pip-name` annotation ensures the most efficient LoadBalancer creation and is highly recommended to avoid potential throttling.
105147
106-
3. Set a public-facing DNS label to the service using the `service.beta.kubernetes.io/azure-dns-label-name` service annotation. This publishes a fully qualified domain name (FQDN) for your service using Azure's public DNS servers and top-level domain. The annotation value must be unique within the Azure location, so we recommend you use a sufficiently qualified label. Azure automatically appends a default suffix in the location you selected, such as `<location>.cloudapp.azure.com`, to the name you provide, creating the FQDN.
148+
1. Set a public-facing DNS label to the service using the `service.beta.kubernetes.io/azure-dns-label-name` service annotation. This publishes a fully qualified domain name (FQDN) for your service using Azure's public DNS servers and top-level domain. The annotation value must be unique within the Azure location, so we recommend you use a sufficiently qualified label. Azure automatically appends a default suffix in the location you selected, such as `<location>.cloudapp.azure.com`, to the name you provide, creating the FQDN.
107149
108150
> [!NOTE]
109151
> If you want to publish the service on your own domain, see [Azure DNS][azure-dns-zone] and the [external-dns][external-dns] project.
@@ -125,13 +167,13 @@ This article shows you how to create a static public IP address and assign it to
125167
app: azure-load-balancer
126168
```
127169
128-
4. Create the service and deployment using the `kubectl apply` command.
170+
1. Create the service and deployment using the `kubectl apply` command.
129171
130172
```console
131173
kubectl apply -f load-balancer-service.yaml
132174
```
133175
134-
5. To see the DNS label for your load balancer, use the `kubectl describe service` command.
176+
1. To see the DNS label for your load balancer, use the `kubectl describe service` command.
135177
136178
```console
137179
kubectl describe service azure-load-balancer

0 commit comments

Comments
 (0)