Skip to content

Commit 3d382cf

Browse files
committed
Troubleshooting GitIssues
1 parent e162f73 commit 3d382cf

File tree

1 file changed

+68
-77
lines changed

1 file changed

+68
-77
lines changed

articles/aks/static-ip.md

Lines changed: 68 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,101 @@
11
---
2-
title: Use static IP with load balancer
2+
title: Use a static IP with a load balancer in Azure Kubernetes Service (AKS)
33
titleSuffix: Azure Kubernetes Service
44
description: Learn how to create and use a static IP address with the Azure Kubernetes Service (AKS) load balancer.
55
author: asudbring
66
ms.author: allensu
77
ms.service: azure-kubernetes-service
88
ms.subservice: aks-networking
99
ms.topic: how-to
10-
ms.date: 11/14/2020
11-
10+
ms.date: 02/24/2023
1211

1312
#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.
1413
---
1514

1615
# Use a static public IP address and DNS label with the Azure Kubernetes Service (AKS) load balancer
1716

18-
By default, the public IP address assigned to a load balancer resource created by an AKS cluster is only valid for the lifespan of that resource. If you delete the Kubernetes service, the associated load balancer and IP address are also deleted. If you want to assign a specific IP address or retain an IP address for redeployed Kubernetes services, you can create and use a static public IP address.
17+
When you create a load balancer resource in an Azure Kubernetes Service (AKS) cluster, the public IP address assigned to it is only valid for the lifespan of that resource. If you delete the Kubernetes service, the associated load balancer and IP address are also deleted. If you want to assign a specific IP address or retain an IP address for redeployed Kubernetes services, you can create and use a static public IP address.
1918

2019
This article shows you how to create a static public IP address and assign it to your Kubernetes service.
2120

2221
## Before you begin
2322

24-
This article assumes that you have an existing AKS cluster. If you need an AKS cluster, see the AKS quickstart [using the Azure CLI][aks-quickstart-cli], [using Azure PowerShell][aks-quickstart-powershell], or [using the Azure portal][aks-quickstart-portal].
25-
26-
You also need the Azure CLI version 2.0.59 or later installed and configured. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][install-azure-cli].
27-
28-
This article covers using a *Standard* SKU IP with a *Standard* SKU load balancer. For more information, see [IP address types and allocation methods in Azure][ip-sku].
23+
* This article assumes that you have an existing AKS cluster. If you need an AKS cluster, see the AKS quickstart [using the Azure CLI][aks-quickstart-cli], [using Azure PowerShell][aks-quickstart-powershell], or [using the Azure portal][aks-quickstart-portal].
24+
* You need the Azure CLI version 2.0.59 or later installed and configured. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][install-azure-cli].
25+
* This article covers using a *Standard* SKU IP with a *Standard* SKU load balancer. For more information, see [IP address types and allocation methods in Azure][ip-sku].
2926

3027
## Create a static IP address
3128

32-
Create a static public IP address with the [az network public ip create][az-network-public-ip-create] command. The following creates a static IP resource named *myAKSPublicIP* in the *myResourceGroup* resource group:
33-
34-
```azurecli-interactive
35-
az network public-ip create \
36-
--resource-group myResourceGroup \
37-
--name myAKSPublicIP \
38-
--sku Standard \
39-
--allocation-method static
40-
```
41-
42-
> [!NOTE]
43-
> If you are using a *Basic* SKU load balancer in your AKS cluster, use *Basic* for the *sku* parameter when defining a public IP. Only *Basic* SKU IPs work with the *Basic* SKU load balancer and only *Standard* SKU IPs work with *Standard* SKU load balancers.
44-
45-
The IP address is displayed, as shown in the following condensed example output:
46-
47-
```json
48-
{
49-
"publicIp": {
50-
...
51-
"ipAddress": "40.121.183.52",
52-
...
53-
}
54-
}
55-
```
56-
57-
You can later get the public IP address using the [az network public-ip list][az-network-public-ip-list] command. Specify the name of the node resource group and public IP address you created, and query for the *ipAddress* as shown in the following example:
58-
59-
```azurecli-interactive
60-
$ az network public-ip show --resource-group myResourceGroup --name myAKSPublicIP --query ipAddress --output tsv
29+
1. Use the `az aks show`[az-aks-show] command to get the node resource group name of your AKS cluster, which follows this format: `MC_<resource group name>_<AKS cluster name>_<region>`.
6130

62-
40.121.183.52
63-
```
31+
```azurecli-interactive
32+
az aks show \
33+
--resource-group myResourceGroup \
34+
--name myAKSCluster
35+
--query nodeResourceGroup
36+
--output tsv
37+
```
6438
65-
## Create a service using the static IP address
39+
2. Use the [`az network public ip create`][az-network-public-ip-create] command to create a static public IP address. The following example creates a static IP resource named *myAKSPublicIP* in the *MC_myResourceGroup_myAKSCluster_eastus* node resource group.
6640
67-
Before creating a service, ensure the cluster identity used by the AKS cluster has delegated permissions to the other resource group. For example:
41+
```azurecli-interactive
42+
az network public-ip create \
43+
--resource-group MC_myResourceGroup_myAKSCluster_eastus \
44+
--name myAKSPublicIP \
45+
--sku Standard \
46+
--allocation-method static
47+
```
6848
69-
```azurecli-interactive
70-
az role assignment create \
71-
--assignee <Client ID> \
72-
--role "Network Contributor" \
73-
--scope /subscriptions/<subscription id>/resourceGroups/<resource group name>
74-
```
49+
> [!NOTE]
50+
> If you're using a *Basic* SKU load balancer in your AKS cluster, use *Basic* for the `--sku` parameter when defining a public IP. Only *Basic* SKU IPs work with the *Basic* SKU load balancer and only *Standard* SKU IPs work with *Standard* SKU load balancers.
7551
76-
> [!IMPORTANT]
77-
> If you customized your outbound IP make sure your cluster identity has permissions to both the outbound public IP and this inbound public IP.
52+
3. After you create the static public IP address, use the [`az network public-ip list`][az-network-public-ip-list] command to get the IP address. Specify the name of the node resource group and public IP address you created, and query for the *ipAddress*.
7853
79-
To create a *LoadBalancer* service with the static public IP address, add the `loadBalancerIP` property and the value of the static public IP address to the YAML manifest. Create a file named `load-balancer-service.yaml` and copy in the following YAML. Provide your own public IP address created in the previous step. The following example also sets the annotation to the resource group named *myResourceGroup*. Provide your own resource group name.
54+
```azurecli-interactive
55+
az network public-ip show --resource-group MC_myResourceGroup_myAKSCluster_eastus --name myAKSPublicIP --query ipAddress --output tsv
56+
```
8057
81-
```yaml
82-
apiVersion: v1
83-
kind: Service
84-
metadata:
85-
annotations:
86-
service.beta.kubernetes.io/azure-load-balancer-resource-group: myResourceGroup
87-
name: azure-load-balancer
88-
spec:
89-
loadBalancerIP: 40.121.183.52
90-
type: LoadBalancer
91-
ports:
92-
- port: 80
93-
selector:
94-
app: azure-load-balancer
95-
```
58+
## Create a service using the static IP address
9659
97-
Create the service and deployment with the `kubectl apply` command.
60+
1. Before creating a service, use the [`az role assignment create`][az-role-assignment-create] command to ensure the cluster identity used by the AKS cluster has delegated permissions to the node resource group.
61+
62+
```azurecli-interactive
63+
az role assignment create \
64+
--assignee <Client ID> \
65+
--role "Network Contributor" \
66+
--scope /subscriptions/<subscription id>/resourceGroups/<MC_myResourceGroup_myAKSCluster_eastus>
67+
```
68+
69+
> [!IMPORTANT]
70+
> If you customized your outbound IP, make sure your cluster identity has permissions to both the outbound public IP and the inbound public IP.
71+
72+
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.
73+
74+
```yaml
75+
apiVersion: v1
76+
kind: Service
77+
metadata:
78+
annotations:
79+
service.beta.kubernetes.io/azure-load-balancer-resource-group: MC_myResourceGroup_myAKSCluster_eastus
80+
name: azure-load-balancer
81+
spec:
82+
loadBalancerIP: 40.121.183.52
83+
type: LoadBalancer
84+
ports:
85+
- port: 80
86+
selector:
87+
app: azure-load-balancer
88+
```
89+
90+
3. Use the `kubectl apply` command to create the service and deployment.
9891
9992
```console
10093
kubectl apply -f load-balancer-service.yaml
10194
```
10295

10396
## Apply a DNS label to the service
10497

105-
If your service is using a dynamic or static public IP address, you can use the service annotation `service.beta.kubernetes.io/azure-dns-label-name` to set a public-facing DNS label. This publishes a fully qualified domain name for your service using Azure's public DNS servers and top-level domain. The annotation value must be unique within the Azure location, so it's recommended to use a sufficiently qualified label.
106-
107-
Azure will then automatically append a default suffix, such as `<location>.cloudapp.azure.com` (where location is the region you selected), to the name you provide, to create the fully qualified DNS name. For example:
98+
If your service uses a dynamic or static public IP address, you can use the `service.beta.kubernetes.io/azure-dns-label-name` service annotation to set a public-facing DNS label. 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 it's recommended to 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.
10899

109100
```yaml
110101
apiVersion: v1
@@ -121,20 +112,20 @@ spec:
121112
app: azure-load-balancer
122113
```
123114
124-
> [!NOTE]
115+
> [!NOTE]
125116
> To publish the service on your own domain, see [Azure DNS][azure-dns-zone] and the [external-dns][external-dns] project.
126117
127118
## Troubleshoot
128119
129-
If the static IP address defined in the *loadBalancerIP* property of the Kubernetes service manifest does not exist, or has not been created in the node resource group and no additional delegations configured, the load balancer service creation fails. To troubleshoot, review the service creation events with the [kubectl describe][kubectl-describe] command. Provide the name of the service as specified in the YAML manifest, as shown in the following example:
120+
If the static IP address defined in the *loadBalancerIP* property of the Kubernetes service manifest doesn't exist or hasn't been created in the node resource group and there are no additional delegations configured, the load balancer service creation fails. To troubleshoot, review the service creation events using the [`kubectl describe`][kubectl-describe] command. Provide the name of the service specified in the YAML manifest, as shown in the following example:
130121

131122
```console
132123
kubectl describe service azure-load-balancer
133124
```
134125

135-
Information about the Kubernetes service resource is displayed. The *Events* at the end of the following example output indicate that the *user supplied IP Address was not found*. In these scenarios, verify that you have created the static public IP address in the node resource group and that the IP address specified in the Kubernetes service manifest is correct.
126+
The output will show you information about the Kubernetes service resource. The following example output shows a `Warning` in the `Events`: "`user supplied IP address was not found`." In this scenario, make sure you've created the static public IP address in the node resource group and that the IP address specified in the Kubernetes service manifest is correct.
136127

137-
```
128+
```console
138129
Name: azure-load-balancer
139130
Namespace: default
140131
Labels: <none>
@@ -158,22 +149,22 @@ Events:
158149

159150
## Next steps
160151

161-
For additional control over the network traffic to your applications, you may want to instead [create an ingress controller][aks-ingress-basic]. You can also [create an ingress controller with a static public IP address][aks-static-ingress].
152+
For additional control over the network traffic to your applications, you may want to [create an ingress controller][aks-ingress-basic]. You can also [create an ingress controller with a static public IP address][aks-static-ingress].
162153

163154
<!-- LINKS - External -->
164155
[kubectl-describe]: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#describe
165156
[azure-dns-zone]: https://azure.microsoft.com/services/dns/
166157
[external-dns]: https://github.com/kubernetes-sigs/external-dns
167158

168159
<!-- LINKS - Internal -->
169-
[aks-faq-resource-group]: faq.md#why-are-two-resource-groups-created-with-aks
170160
[az-network-public-ip-create]: /cli/azure/network/public-ip#az_network_public_ip_create
171161
[az-network-public-ip-list]: /cli/azure/network/public-ip#az_network_public_ip_list
172-
[az-aks-show]: /cli/azure/aks#az_aks_show
173162
[aks-ingress-basic]: ingress-basic.md
174163
[aks-static-ingress]: ingress-static-ip.md
175164
[aks-quickstart-cli]: ./learn/quick-kubernetes-deploy-cli.md
176165
[aks-quickstart-portal]: ./learn/quick-kubernetes-deploy-portal.md
177166
[aks-quickstart-powershell]: ./learn/quick-kubernetes-deploy-powershell.md
178167
[install-azure-cli]: /cli/azure/install-azure-cli
179168
[ip-sku]: ../virtual-network/ip-services/public-ip-addresses.md#sku
169+
[az-role-assignment-create]: /cli/azure/role/assignment#az-role-assignment-create
170+
[az-aks-show]: /cli/azure/aks#az-aks-show

0 commit comments

Comments
 (0)