Skip to content

Commit 3b8908f

Browse files
committed
Formatting edits to Use an internal load balancer with AKS
1 parent 97d27ed commit 3b8908f

File tree

1 file changed

+136
-127
lines changed

1 file changed

+136
-127
lines changed

articles/aks/internal-lb.md

Lines changed: 136 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,48 @@ An internal load balancer does not have a public IP and makes a Kubernetes servi
2222
2323
## Before you begin
2424

25-
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].
26-
27-
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].
28-
29-
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.
30-
31-
For more information on permissions, see [Delegate AKS access to other Azure resources][aks-sp].
25+
* 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].
26+
* You 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].
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.
28+
* For more information on permissions, see [Delegate AKS access to other Azure resources][aks-sp].
3229

3330
## Create an internal load balancer
3431

35-
To create an internal load balancer, create a service manifest named `internal-lb.yaml` with the service type *LoadBalancer* and the *azure-load-balancer-internal* annotation as shown in the following example:
36-
37-
```yaml
38-
apiVersion: v1
39-
kind: Service
40-
metadata:
41-
name: internal-app
42-
annotations:
43-
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
44-
spec:
45-
type: LoadBalancer
46-
ports:
47-
- port: 80
48-
selector:
49-
app: internal-app
50-
```
32+
1. Create a service manifest named `internal-lb.yaml` with the service type `LoadBalancer` and the `azure-load-balancer-internal` annotation.
5133

52-
Deploy the internal load balancer using [`kubectl apply`][kubectl-apply] and specify the name of your YAML manifest.
34+
```yaml
35+
apiVersion: v1
36+
kind: Service
37+
metadata:
38+
name: internal-app
39+
annotations:
40+
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
41+
spec:
42+
type: LoadBalancer
43+
ports:
44+
- port: 80
45+
selector:
46+
app: internal-app
47+
```
5348
54-
```console
55-
kubectl apply -f internal-lb.yaml
56-
```
49+
2. Deploy the internal load balancer using the [`kubectl apply`][kubectl-apply] command. This command creates an Azure load balancer in the node resource group connected to the same virtual network as your AKS cluster.
5750

58-
This command creates an Azure load balancer in the node resource group that's connected to the same virtual network as your AKS cluster.
51+
```azurecli-interactive
52+
kubectl apply -f internal-lb.yaml
53+
```
5954

60-
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. This IP address is dynamically assigned from the same subnet as the AKS cluster.
55+
3. View the service details using the `kubectl get service` command.
6156

62-
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:
57+
```azurecli-interactive
58+
kubectl get service internal-app
59+
```
6360

64-
```
65-
kubectl get service internal-app
61+
The IP address of the internal load balancer is shown in the `EXTERNAL-IP` column, as shown in the following example output. 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. This IP address is dynamically assigned from the same subnet as the AKS cluster.
6662

67-
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
68-
internal-app LoadBalancer 10.0.248.59 10.240.0.7 80:30555/TCP 2m
69-
```
63+
```output
64+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
65+
internal-app LoadBalancer 10.0.248.59 10.240.0.7 80:30555/TCP 2m
66+
```
7067

7168
## Specify an IP address
7269

@@ -76,12 +73,14 @@ You can use the [`az network vnet subnet list`][az-network-vnet-subnet-list] Azu
7673

7774
For more information on subnets, see [Add a node pool with a unique subnet][unique-subnet].
7875

79-
If you want to use a specific IP address with the load balancer, there are two ways:
76+
If you want to use a specific IP address with the load balancer, you have two options: **set service annotations** or **add the *LoadBalancerIP* property to the load balancer YAML manifest**.
8077

8178
> [!IMPORTANT]
8279
> 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.
8380

84-
* **Set service annotations**: 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.
81+
### [Set service annotations](#tab/set-service-annotations)
82+
83+
1. Set service annotations using `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.
8584

8685
```yaml
8786
apiVersion: v1
@@ -99,7 +98,9 @@ If you want to use a specific IP address with the load balancer, there are two w
9998
app: internal-app
10099
```
101100

102-
* **Add the *LoadBalancerIP* property to the load balancer YAML manifest**: Add the *Service.Spec.LoadBalancerIP* property to the load balancer YAML manifest. This field is deprecating following [upstream Kubernetes](https://github.com/kubernetes/kubernetes/pull/107235), and it can't support dual-stack. Current usage remains the same and existing services are expected to work without modification.
101+
### [Add the *LoadBalancerIP* property to the load balancer YAML manifest](#tab/add-load-balancer-ip-property)
102+
103+
1. Add the *Service.Spec.LoadBalancerIP* property to the load balancer YAML manifest. This field is deprecating following [upstream Kubernetes](https://github.com/kubernetes/kubernetes/pull/107235), and it can't support dual-stack. Current usage remains the same and existing services are expected to work without modification.
103104

104105
```yaml
105106
apiVersion: v1
@@ -117,101 +118,110 @@ If you want to use a specific IP address with the load balancer, there are two w
117118
app: internal-app
118119
```
119120

120-
When you view the service details, the IP address in the *EXTERNAL-IP* column should reflect your specified IP address.
121+
---
121122

122-
```
123-
kubectl get service internal-app
123+
2. View the service details using the `kubectl get service` command.
124124

125-
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
126-
internal-app LoadBalancer 10.0.184.168 10.240.0.25 80:30225/TCP 4m
127-
```
125+
```azurecli-interactive
126+
kubectl get service internal-app
127+
```
128+
129+
The IP address in the `EXTERNAL-IP` column should reflect your specified IP address, as shown in the following example output:
130+
131+
```output
132+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
133+
internal-app LoadBalancer 10.0.184.168 10.240.0.25 80:30225/TCP 4m
134+
```
128135

129136
For more information on configuring your load balancer in a different subnet, see [Specify a different subnet][different-subnet]
130137

131138
## Connect Azure Private Link service to internal load balancer
132139

133140
### Before you begin
134141

135-
You must have the following resources:
136-
137-
* Kubernetes version 1.22.x or later.
138-
* 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].
142+
* You need Kubernetes version 1.22.x or later.
143+
* You need an existing resource group with a VNet and subnet. This resource group is where you [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].
139144

140145
### Create a Private Link service connection
141146

142-
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.
143-
144-
```yaml
145-
apiVersion: v1
146-
kind: Service
147-
metadata:
148-
name: internal-app
149-
annotations:
150-
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
151-
service.beta.kubernetes.io/azure-pls-create: "true"
152-
spec:
153-
type: LoadBalancer
154-
ports:
155-
- port: 80
156-
selector:
157-
app: internal-app
158-
```
159-
160-
Deploy the internal load balancer using [`kubectl apply`][kubectl-apply] and specify the name of your YAML manifest.
161-
162-
```console
163-
kubectl apply -f internal-lb-pls.yaml
164-
```
165-
166-
This command creates an Azure load balancer in the node resource group that's connected to the same virtual network as your AKS cluster.
147+
1. Create a service manifest named `internal-lb-pls.yaml` with the service type `LoadBalancer` and the `azure-load-balancer-internal` and `azure-pls-create` annotations. For more options, refer to the [Azure Private Link Service Integration](https://kubernetes-sigs.github.io/cloud-provider-azure/topics/pls-integration/) design document.
167148

168-
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.
149+
```yaml
150+
apiVersion: v1
151+
kind: Service
152+
metadata:
153+
name: internal-app
154+
annotations:
155+
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
156+
service.beta.kubernetes.io/azure-pls-create: "true"
157+
spec:
158+
type: LoadBalancer
159+
ports:
160+
- port: 80
161+
selector:
162+
app: internal-app
163+
```
169164

170-
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:
165+
2. Deploy the internal load balancer using the [`kubectl apply`][kubectl-apply] command. This command creates an Azure load balancer in the node resource group connected to the same virtual network as your AKS cluster and a Private Link Service object that connects to the frontend IP configuration of the load balancer associated with the Kubernetes service.
171166

172-
```
173-
kubectl get service internal-app
167+
```azurecli-interactive
168+
kubectl apply -f internal-lb-pls.yaml
169+
```
174170

175-
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
176-
internal-app LoadBalancer 10.125.17.53 10.125.0.66 80:30430/TCP 64m
177-
```
171+
3. View the service details using the `kubectl get service` command.
178172

179-
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:
173+
```azurecli-interactive
174+
kubectl get service internal-app
175+
```
180176

181-
```azurecli-interactive
182-
# Create a variable for the resource group
177+
The IP address of the internal load balancer is shown in the `EXTERNAL-IP` column, as shown in the following example output. 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.
183178

184-
AKS_MC_RG=$(az aks show -g myResourceGroup --name myAKSCluster --query nodeResourceGroup -o tsv)
179+
```output
180+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
181+
internal-app LoadBalancer 10.125.17.53 10.125.0.66 80:30430/TCP 64m
182+
```
185183

186-
# List the private link service
184+
4. View the details of the Private Link Service object using the [`az network private-link-service list`][az-network-private-link-service-list] command.
187185

188-
az network private-link-service list -g $AKS_MC_RG --query "[].{Name:name,Alias:alias}" -o table
186+
```azurecli-interactive
187+
# Create a variable for the node resource group
188+
189+
AKS_MC_RG=$(az aks show -g myResourceGroup --name myAKSCluster --query nodeResourceGroup -o tsv)
190+
191+
# View the details of the Private Link Service object
192+
193+
az network private-link-service list -g $AKS_MC_RG --query "[].{Name:name,Alias:alias}" -o table
194+
```
189195

190-
Name Alias
191-
-------- -------------------------------------------------------------------------
192-
pls-xyz pls-xyz.abc123-defg-4hij-56kl-789mnop.eastus2.azure.privatelinkservice
196+
Your output will look similar to the following example output:
193197

194-
```
198+
```output
199+
Name Alias
200+
-------- -------------------------------------------------------------------------
201+
pls-xyz pls-xyz.abc123-defg-4hij-56kl-789mnop.eastus2.azure.privatelinkservice
202+
```
195203

196204
### Create a Private Endpoint to the Private Link service
197205

198-
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.
199-
200-
```azurecli-interactive
201-
# Create a variable for the private link service
202-
203-
AKS_PLS_ID=$(az network private-link-service list -g $AKS_MC_RG --query "[].id" -o tsv)
204-
205-
# Create the private endpoint
206-
207-
$ az network private-endpoint create \
208-
-g myOtherResourceGroup \
209-
--name myAKSServicePE \
210-
--vnet-name myOtherVNET \
211-
--subnet pe-subnet \
212-
--private-connection-resource-id $AKS_PLS_ID \
213-
--connection-name connectToMyK8sService
214-
```
206+
A Private Endpoint allows you to privately connect to your Kubernetes service object via the Private Link Service you created.
207+
208+
* Create the private endpoint using the [`az network private-endpoint create`][az-network-private-endpoint-create] command.
209+
210+
```azurecli-interactive
211+
# Create a variable for the private link service
212+
213+
AKS_PLS_ID=$(az network private-link-service list -g $AKS_MC_RG --query "[].id" -o tsv)
214+
215+
# Create the private endpoint
216+
217+
$ az network private-endpoint create \
218+
-g myOtherResourceGroup \
219+
--name myAKSServicePE \
220+
--vnet-name myOtherVNET \
221+
--subnet pe-subnet \
222+
--private-connection-resource-id $AKS_PLS_ID \
223+
--connection-name connectToMyK8sService
224+
```
215225

216226
## Use private networks
217227

@@ -221,36 +231,35 @@ For more information, see [configure your own virtual network subnets with Kuben
221231

222232
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:
223233

224-
```
234+
```azurecli-interactive
225235
$ kubectl get service internal-app
226236
227237
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
228238
internal-app LoadBalancer 10.1.15.188 10.0.0.35 80:31669/TCP 1m
229239
```
230240

231241
> [!NOTE]
232-
>
233-
> You may need to assign a minimum of *Microsoft.Network/virtualNetworks/subnets/read* and *Microsoft.Network/virtualNetworks/subnets/join/action* permission to AKS MSI on the Azure Virtual Network resources. 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.
242+
> You may need to assign a minimum of *Microsoft.Network/virtualNetworks/subnets/read* and *Microsoft.Network/virtualNetworks/subnets/join/action* permission to AKS MSI on the Azure Virtual Network resources. 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.
234243

235244
### Specify a different subnet
236245

237-
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.
238-
239-
```yaml
240-
apiVersion: v1
241-
kind: Service
242-
metadata:
243-
name: internal-app
244-
annotations:
245-
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
246-
service.beta.kubernetes.io/azure-load-balancer-internal-subnet: "apps-subnet"
247-
spec:
248-
type: LoadBalancer
249-
ports:
250-
- port: 80
251-
selector:
252-
app: internal-app
253-
```
246+
* 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.
247+
248+
```yaml
249+
apiVersion: v1
250+
kind: Service
251+
metadata:
252+
name: internal-app
253+
annotations:
254+
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
255+
service.beta.kubernetes.io/azure-load-balancer-internal-subnet: "apps-subnet"
256+
spec:
257+
type: LoadBalancer
258+
ports:
259+
- port: 80
260+
selector:
261+
app: internal-app
262+
```
254263

255264
## Delete the load balancer
256265

0 commit comments

Comments
 (0)