You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/aks/internal-lb.md
+60-36Lines changed: 60 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,26 +4,27 @@ titleSuffix: Azure Kubernetes Service
4
4
description: Learn how to create and use an internal load balancer to expose your services with Azure Kubernetes Service (AKS).
5
5
services: container-service
6
6
ms.topic: article
7
-
ms.date: 03/04/2019
7
+
ms.date: 12/12/2022
8
8
9
9
10
10
#Customer intent: As a cluster operator or developer, I want to learn how to create a service in AKS that uses an internal Azure load balancer for enhanced security and without an external endpoint.
11
11
---
12
12
13
13
# Use an internal load balancer with Azure Kubernetes Service (AKS)
14
14
15
-
To restrict access to your applications in Azure Kubernetes Service (AKS), you can create and use an internal load balancer. An internal load balancer makes a Kubernetes service accessible only to applications running in the same virtual network as the Kubernetes cluster. This article shows you how to create and use an internal load balancer with Azure Kubernetes Service (AKS).
15
+
You can create and use an internal load balancer to restrict access to your applications in Azure Kubernetes Service (AKS).
16
+
An internal load balancer makes a Kubernetes service accessible only to applications running in the same virtual network as the Kubernetes cluster. This article shows you how to create and use an internal load balancer with AKS.
16
17
17
18
> [!NOTE]
18
-
> Azure Load Balancer is available in two SKUs - *Basic* and *Standard*. By default, the Standard SKU is used when you create an AKS cluster. When creating a Service with type as LoadBalancer, you will get the same LB type as when you provision the cluster. For more information, see [Azure load balancer SKU comparison][azure-lb-comparison].
19
+
> Azure Load Balancer is available in two SKUs: *Basic* and *Standard*. The *Standard* SKU is used by default when you create an AKS cluster. When you create a *LoadBalancer* service type, you'll get the same load balancer type as when you provisioned the cluster. For more information, see [Azure Load Balancer SKU comparison][azure-lb-comparison].
19
20
20
21
## Before you begin
21
22
22
-
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].
23
+
This article assumes that you have an existing AKS cluster. If you need an AKS cluster, you can create one[using Azure CLI][aks-quickstart-cli], [Azure PowerShell][aks-quickstart-powershell], or [the Azure portal][aks-quickstart-portal].
23
24
24
-
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].
25
+
You also need the Azure CLI version 2.0.59 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][install-azure-cli].
25
26
26
-
The AKS cluster identity needs permission to manage network resources if you use an existing subnet or resource group. For information, see [Use kubenet networking with your own IP address ranges in Azure Kubernetes Service (AKS)][use-kubenet] or [Configure Azure CNI networking in Azure Kubernetes Service (AKS)][advanced-networking]. If you are configuring your load balancer to use an [IP address in a different subnet][different-subnet], ensure the AKS cluster identity also has read access to that subnet.
27
+
If you want to use an existing subnet or resource group, the AKS cluster identity needs permission to manage network resources. For information, see [Use kubenet networking with your own IP address ranges in AKS][use-kubenet] or [Configure Azure CNI networking in AKS][advanced-networking]. If you're configuring your load balancer to use an [IP address in a different subnet][different-subnet], ensure the AKS cluster identity also has read access to that subnet.
27
28
28
29
For more information on permissions, see [Delegate AKS access to other Azure resources][aks-sp].
29
30
@@ -46,26 +47,30 @@ spec:
46
47
app: internal-app
47
48
```
48
49
49
-
Deploy the internal load balancer using the [kubectl apply][kubectl-apply] and specify the name of your YAML manifest:
50
+
Deploy the internal load balancer using [`kubectl apply`][kubectl-apply] and specify the name of your YAML manifest.
50
51
51
52
```console
52
53
kubectl apply -f internal-lb.yaml
53
54
```
54
55
55
-
An Azure load balancer is created in the node resource group and connected to the same virtual network as the AKS cluster.
56
+
This command creates an Azure load balancer in the node resource group that's connected to the same virtual network as your AKS cluster.
56
57
57
-
When you view the service details, the IP address of the internal load balancer is shown in the *EXTERNAL-IP* column. In this context, *External* is in relation to the external interface of the load balancer, not that it receives a public, external IP address. It may take a minute or two for the IP address to change from *\<pending\>* to an actual internal IP address, as shown in the following example:
58
+
When you view the service details, the IP address of the internal load balancer is shown in the *EXTERNAL-IP* column. In this context, *External* refers to the external interface of the load balancer. It doesn't mean that it receives a public, external IP address.
59
+
60
+
It may take a minute or two for the IP address to change from *\<pending\>* to an actual internal IP address, as shown in the following example:
If you would like to use a specific IP address with the internal load balancer, add the *loadBalancerIP* property to the load balancer YAML manifest. In this scenario, the specified IP address must reside in the same subnet as the AKS cluster but can't already be assigned to a resource. For example, an IP address in the range designated for the Kubernetes subnet within the AKS cluster shouldn't be used.
71
+
If you want to use a specific IP address with the internal load balancer, add the *loadBalancerIP* property to the load balancer YAML manifest. In this scenario, the specified IP address must reside in the same subnet as the AKS cluster, but it can't already be assigned to a resource. For example, you shouldn't use an IP address in the range designated for the Kubernetes subnet within the AKS cluster.
72
+
73
+
For more information on subnets, see [Add a node pool with a unique subnet][unique-subnet].
69
74
70
75
```yaml
71
76
apiVersion: v1
@@ -83,10 +88,10 @@ spec:
83
88
app: internal-app
84
89
```
85
90
86
-
When deployed and you view the service details, the IP address in the *EXTERNAL-IP* column reflects your specified IP address:
91
+
When you view the service details, the IP address in the *EXTERNAL-IP* column should reflect your specified IP address.
@@ -98,14 +103,15 @@ For more information on configuring your load balancer in a different subnet, se
98
103
99
104
### Before you begin
100
105
101
-
You must have the following resource installed:
106
+
You must have the following resources:
102
107
103
-
* The Azure CLI
104
-
* Kubernetes version 1.22.x or above
108
+
* Azure CLI version 2.0.59 or later.
109
+
* Kubernetes version 1.22.x or later.
110
+
* An existing resource group with a VNet and subnet. This resource group is where you'll [create the private endpoint](#create-a-private-endpoint-to-the-private-link-service). If you don't have these resources, see [Create a virtual network and subnet][aks-vnet-subnet].
105
111
106
112
### Create a Private Link service connection
107
113
108
-
To attach an Azure Private Link service to an internal load balancer, create a service manifest named `internal-lb-pls.yaml` with the service type *LoadBalancer* and the *azure-load-balancer-internal* and *azure-pls-create* annotation as shown in the example below. For more options, refer to the [Azure Private Link Service Integration](https://kubernetes-sigs.github.io/cloud-provider-azure/topics/pls-integration/) design document
114
+
To attach an Azure Private Link service to an internal load balancer, create a service manifest named `internal-lb-pls.yaml` with the service type *LoadBalancer* and the *azure-load-balancer-internal* and *azure-pls-create* annotation as shown in the following example. For more options, refer to the [Azure Private Link Service Integration](https://kubernetes-sigs.github.io/cloud-provider-azure/topics/pls-integration/) design document.
109
115
110
116
```yaml
111
117
apiVersion: v1
@@ -123,27 +129,35 @@ spec:
123
129
app: internal-app
124
130
```
125
131
126
-
Deploy the internal load balancer using the [kubectl apply][kubectl-apply] and specify the name of your YAML manifest:
132
+
Deploy the internal load balancer using [`kubectl apply`][kubectl-apply] and specify the name of your YAML manifest.
127
133
128
134
```console
129
135
kubectl apply -f internal-lb-pls.yaml
130
136
```
131
137
132
-
An Azure load balancer is created in the node resource group and connected to the same virtual network as the AKS cluster.
138
+
This command creates an Azure load balancer in the node resource group that's connected to the same virtual network as your AKS cluster.
133
139
134
-
When you view the service details, the IP address of the internal load balancer is shown in the *EXTERNAL-IP* column. In this context, *External* is in relation to the external interface of the load balancer, not that it receives a public, external IP address. It may take a minute or two for the IP address to change from *\<pending\>* to an actual internal IP address, as shown in the following example:
140
+
When you view the service details, the IP address of the internal load balancer is shown in the *EXTERNAL-IP* column. In this context, *External* refers to the external interface of the load balancer. It doesn't mean that it receives a public, external IP address.
141
+
142
+
It may take a minute or two for the IP address to change from *\<pending\>* to an actual internal IP address, as shown in the following example:
Additionally, a Private Link Service object will also be created that connects to the Frontend IP configuration of the Load Balancer associated with the Kubernetes service. Details of the Private Link Service object can be retrieved as shown in the following example:
144
-
```
145
-
$ AKS_MC_RG=$(az aks show -g myResourceGroup --name myAKSCluster --query nodeResourceGroup -o tsv)
146
-
$ az network private-link-service list -g ${AKS_MC_RG} --query "[].{Name:name,Alias:alias}" -o table
151
+
A Private Link Service object is also created. This Private Link Service object connects to the frontend IP configuration of the load balancer associated with the Kubernetes service. You can get the details of the Private Link Service object with the following sample command:
152
+
153
+
```azurecli-interactive
154
+
# Create a variable for the resource group
155
+
156
+
AKS_MC_RG=$(az aks show -g myResourceGroup --name myAKSCluster --query nodeResourceGroup -o tsv)
157
+
158
+
# List the private link service
159
+
160
+
az network private-link-service list -g $AKS_MC_RG --query "[].{Name:name,Alias:alias}" -o table
### Create a Private Endpoint to the Private Link service
155
169
156
-
A Private Endpoint allows you to privately connect to your Kubernetes service object via the Private Link Service created above. To do so, follow the example shown below:
170
+
A Private Endpoint allows you to privately connect to your Kubernetes service object via the Private Link Service you created. To do so, follow the sample commands.
171
+
172
+
```azurecli-interactive
173
+
# Create a variable for the private link service
174
+
175
+
AKS_PLS_ID=$(az network private-link-service list -g $AKS_MC_RG --query "[].id" -o tsv)
When you create your AKS cluster, you can specify advanced networking settings. This approach lets you deploy the cluster into an existing Azure virtual network and subnets. One scenario is to deploy your AKS cluster into a private network connected to your on-premises environment and run services only accessible internally. For more information, see configure your own virtual network subnets with [Kubenet][use-kubenet] or [Azure CNI][advanced-networking].
190
+
When you create your AKS cluster, you can specify advanced networking settings. These settings allow you to deploy the cluster into an existing Azure virtual network and subnets. For example, you can deploy your AKS cluster into a private network connected to your on-premises environment and run services that are only accessible internally.
191
+
192
+
For more information, see [configure your own virtual network subnets with Kubenet][use-kubenet] or [with Azure CNI][advanced-networking].
172
193
173
-
No changes to the previous steps are needed to deploy an internal load balancer in an AKS cluster that uses a private network. The load balancer is created in the same resource group as your AKS cluster but connected to your private virtual network and subnet, as shown in the following example:
194
+
You don't need to make any changes to the previous steps to deploy an internal load balancer that uses a private network in an AKS cluster. The load balancer is created in the same resource group as your AKS cluster, but it's instead connected to your private virtual network and subnet, as shown in the following example:
> You may need to grant the cluster identity for your AKS cluster the *Network Contributor* role to the resource group where your Azure virtual network resources are deployed. View the cluster identity with [az aks show][az-aks-show], such as `az aks show --resource-group myResourceGroup --name myAKSCluster --query "identity"`. To create a role assignment, use the [az role assignment create][az-role-assignment-create] command.
204
+
>
205
+
> You may need to give the *Network Contributor* role to the resource group in which your Azure virtual network resources are deployed. You can view the cluster identity with [az aks show][az-aks-show], such as `az aks show --resource-group myResourceGroup --name myAKSCluster --query "identity"`. To create a role assignment, use the [az role assignment create][az-role-assignment-create] command.
184
206
185
207
## Specify a different subnet
186
208
187
-
To specify a subnet for your load balancer, add the *azure-load-balancer-internal-subnet* annotation to your service. The subnet specified must be in the same virtual network as your AKS cluster. When deployed, the load balancer *EXTERNAL-IP* address is part of the specified subnet.
209
+
Add the *azure-load-balancer-internal-subnet* annotation to your service to specify a subnet for your load balancer. The subnet specified must be in the same virtual network as your AKS cluster. When deployed, the load balancer *EXTERNAL-IP* address is part of the specified subnet.
188
210
189
211
```yaml
190
212
apiVersion: v1
@@ -204,13 +226,13 @@ spec:
204
226
205
227
## Delete the load balancer
206
228
207
-
When all services that use the internal load balancer are deleted, the load balancer itself is also deleted.
229
+
The load balancer will be deleted when all of its services are deleted.
208
230
209
-
You can also directly delete a service as with any Kubernetes resource, such as `kubectl delete service internal-app`, which also then deletes the underlying Azure load balancer.
231
+
As with any Kubernetes resource, you can directly delete a service, such as `kubectl delete service internal-app`, which also deletes the underlying Azure load balancer.
210
232
211
233
## Next steps
212
234
213
-
Learn more about Kubernetes services at the [Kubernetes services documentation][kubernetes-services].
235
+
Learn more about Kubernetes services in the [Kubernetes services documentation][kubernetes-services].
0 commit comments