|
1 | 1 | ---
|
2 |
| -title: Configure kube-proxy (iptables/IPVS) (preview) |
| 2 | +title: Configure kube-proxy (iptables/IPVS) (Preview) |
3 | 3 | titleSuffix: Azure Kubernetes Service
|
4 | 4 | description: Learn how to configure kube-proxy to utilize different load balancing configurations with Azure Kubernetes Service (AKS).
|
5 | 5 | ms.subservice: aks-networking
|
6 | 6 | ms.custom: devx-track-azurecli, devx-track-linux
|
7 | 7 | ms.topic: how-to
|
8 |
| -ms.date: 10/25/2022 |
| 8 | +ms.date: 09/25/2023 |
9 | 9 | ms.author: allensu
|
10 | 10 | author: asudbring
|
11 | 11 | #Customer intent: As a cluster operator, I want to utilize a different kube-proxy configuration.
|
12 | 12 | ---
|
13 | 13 |
|
14 |
| -# Configure `kube-proxy` in Azure Kubernetes Service (AKS) (preview) |
| 14 | +# Configure `kube-proxy` in Azure Kubernetes Service (AKS) (Preview) |
15 | 15 |
|
16 |
| -`kube-proxy` is a component of Kubernetes that handles routing traffic for services within the cluster. There are two backends available for Layer 3/4 load balancing in upstream `kube-proxy` - iptables and IPVS. |
| 16 | +`kube-proxy` is a component of Kubernetes that handles routing traffic for services within the cluster. There are two backends available for Layer 3/4 load balancing in upstream `kube-proxy`: iptables and IPVS. |
17 | 17 |
|
18 |
| -- iptables is the default backend utilized in the majority of Kubernetes clusters. It is simple and well supported, but is not as efficient or intelligent as IPVS. |
19 |
| -- IPVS utilizes the Linux Virtual Server, a layer 3/4 load balancer built into the Linux kernel. IPVS provides a number of advantages over the default iptables configuration, including state awareness, connection tracking, and more intelligent load balancing. |
| 18 | +- **iptables** is the default backend utilized in the majority of Kubernetes clusters. It's simple and well-supported, but not as efficient or intelligent as IPVS. |
| 19 | +- **IPVS** uses the Linux Virtual Server, a layer 3/4 load balancer built into the Linux kernel. IPVS provides a number of advantages over the default iptables configuration, including state awareness, connection tracking, and more intelligent load balancing. IPVS *doesn't support Azure Network Policy*. |
20 | 20 |
|
21 |
| -The AKS managed `kube-proxy` DaemonSet can also be disabled entirely if that is desired to support [bring-your-own CNI][aks-byo-cni]. |
| 21 | +For more information, see the [Kubernetes documentation on kube-proxy](https://kubernetes.io/docs/reference/command-line-tools-reference/kube-proxy/). |
22 | 22 |
|
23 |
| -## Prerequisites |
24 |
| - |
25 |
| -* Azure CLI with aks-preview extension 0.5.105 or later. |
26 |
| -* If using ARM or the REST API, the AKS API version must be 2022-08-02-preview or later. |
27 |
| - |
28 |
| -## Install the aks-preview Azure CLI extension |
| 23 | +> [!NOTE] |
| 24 | +> If you want, you can disable the AKS-managed `kube-proxy` DaemonSet to support [bring-your-own CNI][aks-byo-cni]. |
29 | 25 |
|
30 | 26 | [!INCLUDE [preview features callout](includes/preview/preview-callout.md)]
|
31 | 27 |
|
32 |
| -To install the aks-preview extension, run the following command: |
33 |
| - |
34 |
| -```azurecli-interactive |
35 |
| -az extension add --name aks-preview |
36 |
| -``` |
| 28 | +## Before you begin |
37 | 29 |
|
38 |
| -Run the following command to update to the latest version of the extension released: |
| 30 | +- If using the Azure CLI, you need the `aks-preview` extension. See [Install the `aks-preview` Azure CLI extension](#install-the-aks-preview-azure-cli-extension). |
| 31 | +- If using ARM or the REST API, the AKS API version must be *2022-08-02-preview or later*. |
| 32 | +- You need to register the `KubeProxyConfigurationPreview` feature flag. See [Register the `KubeProxyConfigurationPreview` feature flag](#register-the-kubeproxyconfigurationpreview-feature-flag). |
39 | 33 |
|
40 |
| -```azurecli-interactive |
41 |
| -az extension update --name aks-preview |
42 |
| -``` |
| 34 | +### Install the `aks-preview` Azure CLI extension |
43 | 35 |
|
44 |
| -## Register the 'KubeProxyConfigurationPreview' feature flag |
| 36 | +1. Install the `aks-preview` extension using the [`az extension add`][az-extension-add] command. |
45 | 37 |
|
46 |
| -Register the `KubeProxyConfigurationPreview` feature flag by using the [az feature register][az-feature-register] command, as shown in the following example: |
| 38 | + ```azurecli-interactive |
| 39 | + az extension add --name aks-preview |
| 40 | + ``` |
47 | 41 |
|
48 |
| -```azurecli-interactive |
49 |
| -az feature register --namespace "Microsoft.ContainerService" --name "KubeProxyConfigurationPreview" |
50 |
| -``` |
| 42 | +2. Update to the latest version of the extension using the [`az extension update`][az-extension-update] command. |
51 | 43 |
|
52 |
| -It takes a few minutes for the status to show *Registered*. Verify the registration status by using the [az feature show][az-feature-show] command: |
| 44 | + ```azurecli-interactive |
| 45 | + az extension update --name aks-preview |
| 46 | + ``` |
53 | 47 |
|
54 |
| -```azurecli-interactive |
55 |
| -az feature show --namespace "Microsoft.ContainerService" --name "KubeProxyConfigurationPreview" |
56 |
| -``` |
| 48 | +### Register the `KubeProxyConfigurationPreview` feature flag |
57 | 49 |
|
58 |
| -When the status reflects *Registered*, refresh the registration of the *Microsoft.ContainerService* resource provider by using the [az provider register][az-provider-register] command: |
| 50 | +1. Register the `KubeProxyConfigurationPreview` feature flag using the [`az feature register`][az-feature-register] command. |
59 | 51 |
|
60 |
| -```azurecli-interactive |
61 |
| -az provider register --namespace Microsoft.ContainerService |
62 |
| -``` |
| 52 | + ```azurecli-interactive |
| 53 | + az feature register --namespace "Microsoft.ContainerService" --name "KubeProxyConfigurationPreview" |
| 54 | + ``` |
63 | 55 |
|
64 |
| -## Configurable options |
| 56 | + It takes a few minutes for the status to show *Registered*. |
65 | 57 |
|
66 |
| -The full `kube-proxy` configuration structure can be found in the [AKS Cluster Schema][aks-schema-kubeproxyconfig]. |
| 58 | +2. Verify the registration status using the [`az feature show`][az-feature-show] command. |
67 | 59 |
|
68 |
| -- `enabled` - whether or not to deploy the `kube-proxy` DaemonSet. Defaults to true. |
69 |
| -- `mode` - can be set to `IPTABLES` or `IPVS`. Defaults to `IPTABLES`. |
70 |
| -- `ipvsConfig` - if `mode` is `IPVS`, this object contains IPVS-specific configuration properties. |
71 |
| - - `scheduler` - which connection scheduler to utilize. Supported values: |
72 |
| - - `LeastConnection` - sends connections to the backend pod with the fewest connections |
73 |
| - - `RoundRobin` - distributes connections evenly between backend pods |
74 |
| - - `tcpFinTimeoutSeconds` - the value used for timeout after a FIN has been received in a TCP session |
75 |
| - - `tcpTimeoutSeconds` - the value used for timeout length for idle TCP sessions |
76 |
| - - `udpTimeoutSeconds` - the value used for timeout length for idle UDP sessions |
| 60 | + ```azurecli-interactive |
| 61 | + az feature show --namespace "Microsoft.ContainerService" --name "KubeProxyConfigurationPreview" |
| 62 | + ``` |
77 | 63 |
|
78 |
| -> [!NOTE] |
79 |
| -> IPVS load balancing operates in each node independently and is still only aware of connections flowing through the local node. This means that while `LeastConnection` results in more even load under higher number of connections, when low numbers of connections (# connects < 2 * node count) occur traffic may still be relatively unbalanced. |
80 |
| -
|
81 |
| -## Utilize `kube-proxy` configuration in a new or existing AKS cluster using Azure CLI |
| 64 | +3. When the status reflects *Registered*, refresh the registration of the *Microsoft.ContainerService* resource provider using the [`az provider register`][az-provider-register] command. |
82 | 65 |
|
83 |
| -`kube-proxy` configuration is a cluster-wide setting. No action is needed to update your services. |
84 |
| - |
85 |
| ->[!WARNING] |
86 |
| -> Changing the kube-proxy configuration may cause a slight interruption in cluster service traffic flow. |
| 66 | + ```azurecli-interactive |
| 67 | + az provider register --namespace Microsoft.ContainerService |
| 68 | + ``` |
87 | 69 |
|
88 |
| -To begin, create a JSON configuration file with the desired settings: |
| 70 | +## `kube-proxy` configuration options |
89 | 71 |
|
90 |
| -### Create a configuration file |
| 72 | +You can view the full `kube-proxy` configuration structure in the [AKS Cluster Schema][aks-schema-kubeproxyconfig]. |
91 | 73 |
|
92 |
| -```json |
93 |
| -{ |
94 |
| - "enabled": true, |
95 |
| - "mode": "IPVS", |
96 |
| - "ipvsConfig": { |
97 |
| - "scheduler": "LeastConnection", |
98 |
| - "TCPTimeoutSeconds": 900, |
99 |
| - "TCPFINTimeoutSeconds": 120, |
100 |
| - "UDPTimeoutSeconds": 300 |
101 |
| - } |
102 |
| -} |
103 |
| -``` |
| 74 | +- **`enabled`**: Determines deployment of the `kube-proxy` DaemonSet. Defaults to `true`. |
| 75 | +- **`mode`**: You can set to either `IPTABLES` or `IPVS`. Defaults to `IPTABLES`. |
| 76 | +- **`ipvsConfig`**: If `mode` is `IPVS`, this object contains IPVS-specific configuration properties. |
| 77 | + - **`scheduler`**: Determines which connection scheduler to use. Supported values include: |
| 78 | + - **`LeastConnection`**: Sends connections to the backend pod with the fewest connections. |
| 79 | + - **`RoundRobin`**: Evenly distributes connections between backend pods. |
| 80 | + - **`tcpFinTimeoutSeconds`**: Sets the timeout length value after a TCP session receives a FIN. |
| 81 | + - **`tcpTimeoutSeconds`**: Sets the timeout length value for idle TCP sessions. |
| 82 | + - **`udpTimeoutSeconds`**: Sets the timeout length value for idle UDP sessions. |
104 | 83 |
|
105 |
| -### Deploy a new cluster |
106 |
| - |
107 |
| -Deploy your cluster using `az aks create` and pass in the configuration file: |
108 |
| - |
109 |
| -```bash |
110 |
| -az aks create -g <resourceGroup> -n <clusterName> --kube-proxy-config kube-proxy.json |
111 |
| -``` |
112 |
| - |
113 |
| -### Update an existing cluster |
114 |
| - |
115 |
| -Configure your cluster using `az aks update` and pass in the configuration file: |
| 84 | +> [!NOTE] |
| 85 | +> IPVS load balancing operates in each node independently and is only aware of connections flowing through the local node. This means that while `LeastConnection` results in a more even load under a higher number of connections, when a low amount of connections (# connects < 2 * node count) occur, traffic may be relatively unbalanced |
116 | 86 |
|
117 |
| -```bash |
118 |
| -az aks update -g <resourceGroup> -n <clusterName> --kube-proxy-config kube-proxy.json |
119 |
| -``` |
| 87 | +## Use `kube-proxy` in a new or existing AKS cluster |
120 | 88 |
|
121 |
| -### Limitations |
| 89 | +`kube-proxy` configuration is a cluster-wide setting. You don't need to update your services. |
122 | 90 |
|
123 |
| -When using kube-proxy IPVS, the following restrictions apply: |
| 91 | +> [!WARNING] |
| 92 | +> Changing the kube-proxy configuration may cause a slight interruption in cluster service traffic flow. |
124 | 93 |
|
125 |
| -- Azure Network Policy is not supported. |
| 94 | +1. Create a configuration file with the desired `kube-proxy` configuration. For example, the following configuration enables IPVS with the `LeastConnection` scheduler and sets the TCP timeout to 900 seconds. |
| 95 | +
|
| 96 | + ```json |
| 97 | + { |
| 98 | + "enabled": true, |
| 99 | + "mode": "IPVS", |
| 100 | + "ipvsConfig": { |
| 101 | + "scheduler": "LeastConnection", |
| 102 | + "TCPTimeoutSeconds": 900, |
| 103 | + "TCPFINTimeoutSeconds": 120, |
| 104 | + "UDPTimeoutSeconds": 300 |
| 105 | + } |
| 106 | + } |
| 107 | + ``` |
| 108 | +
|
| 109 | +2. Create a new cluster or update an existing cluster with the configuration file using the [`az aks create`][az-aks-create] or [`az aks update`][az-aks-update] command with the `--kube-proxy-config` parameter set to the configuration file. |
| 110 | +
|
| 111 | + ```azurecli-interactive |
| 112 | + # Create a new cluster |
| 113 | + az aks create -g <resourceGroup> -n <clusterName> --kube-proxy-config kube-proxy.json |
| 114 | + |
| 115 | + # Update an existing cluster |
| 116 | + az aks update -g <resourceGroup> -n <clusterName> --kube-proxy-config kube-proxy.json |
| 117 | + ``` |
126 | 118 |
|
127 | 119 | ## Next steps
|
128 | 120 |
|
129 |
| -Learn more about utilizing the Standard Load Balancer for inbound traffic at the [AKS Standard Load Balancer documentation](load-balancer-standard.md). |
130 |
| - |
131 |
| -Learn more about using Internal Load Balancer for Inbound traffic at the [AKS Internal Load Balancer documentation](internal-lb.md). |
| 121 | +This article covered how to configure `kube-proxy` in Azure Kubernetes Service (AKS). To learn more about load balancing in AKS, see the following articles: |
132 | 122 |
|
133 |
| -Learn more about Kubernetes services at the [Kubernetes services documentation][kubernetes-services]. |
| 123 | +- [Use a standard public load balancer in AKS](load-balancer-standard.md) |
| 124 | +- [Use an internal load balancer in AKS](internal-lb.md) |
134 | 125 |
|
135 | 126 | <!-- LINKS - External -->
|
136 |
| -[kubernetes-services]: https://kubernetes.io/docs/concepts/services-networking/service/ |
137 | 127 | [aks-schema-kubeproxyconfig]: /azure/templates/microsoft.containerservice/managedclusters?pivots=deployment-language-bicep#containerservicenetworkprofilekubeproxyconfig
|
138 | 128 |
|
139 | 129 | <!-- LINKS - Internal -->
|
140 | 130 | [aks-byo-cni]: use-byo-cni.md
|
141 | 131 | [az-provider-register]: /cli/azure/provider#az-provider-register
|
142 | 132 | [az-feature-register]: /cli/azure/feature#az-feature-register
|
143 | 133 | [az-feature-show]: /cli/azure/feature#az-feature-show
|
| 134 | +[az-extension-add]: /cli/azure/extension#az-extension-add |
| 135 | +[az-extension-update]: /cli/azure/extension#az-extension-update |
| 136 | +[az-aks-create]: /cli/azure/aks#az-aks-create |
| 137 | +[az-aks-update]: /cli/azure/aks#az-aks-update |
0 commit comments