Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

14.0.0b3
+++++++
* Support `az aks loadbalancer show/list/add/update/delete/rebalance` commands.

14.0.0b2
+++++++
Expand Down
4 changes: 4 additions & 0 deletions src/aks-preview/azext_aks_preview/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ def get_providers_client_factory(cli_ctx, subscription_id=None):

def get_keyvault_client(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_KEYVAULT, subscription_id=subscription_id).vaults


def cf_load_balancers(cli_ctx, *_):
return get_container_service_client(cli_ctx).load_balancers
128 changes: 128 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -3300,3 +3300,131 @@
type: string
short-summary: Additional endpoint(s) to perform the connectivity check, separated by comma.
"""

helps['aks loadbalancer'] = """
type: group
short-summary: Commands to manage load balancer configurations in a managed Kubernetes cluster.
long-summary: These commands enable the feature of multiple standard load balancers for Azure Kubernetes Service clusters.
"""

helps['aks loadbalancer add'] = """
type: command
short-summary: Add a load balancer configuration to a managed Kubernetes cluster.
parameters:
- name: --name -n
type: string
short-summary: Name of the load balancer configuration.
long-summary: Load balancer name used for identification. There must be a configuration named "kubernetes" in the cluster.
- name: --primary-agent-pool-name -p
type: string
short-summary: Name of the primary agent pool for this load balancer.
long-summary: Required field. A string value that must specify the ID of an existing agent pool. All nodes in the given pool will always be added to this load balancer.
- name: --allow-service-placement -a
type: bool
short-summary: Whether to automatically place services on the load balancer.
long-summary: If not supplied, the default value is true. If set to false manually, both the external and internal load balancer will not be selected for services unless they explicitly target it.
- name: --service-label-selector -l
type: string
short-summary: Label selector for services that can be placed on this load balancer.
long-summary: Only services that match this selector can be placed on this load balancer. Format as comma-separated key=value pairs or expressions like "key In value1,value2".
- name: --service-namespace-selector -s
type: string
short-summary: Namespace label selector for services that can be placed on this load balancer.
long-summary: Services created in namespaces that match the selector can be placed on this load balancer. Format as comma-separated key=value pairs.
- name: --node-selector -d
type: string
short-summary: Node label selector for nodes that can be members of this load balancer.
long-summary: Nodes that match this selector will be possible members of this load balancer. Format as comma-separated key=value pairs.
- name: --aks-custom-headers
type: string
short-summary: Send custom headers to the AKS API.
long-summary: When specified, format should be Key1=Value1,Key2=Value2.
examples:
- name: Add a load balancer configuration with a specific primary agent pool
text: az aks loadbalancer add -g MyResourceGroup -n secondary --cluster-name MyManagedCluster --primary-agent-pool-name nodepool1
- name: Add a load balancer configuration with service label selector
text: az aks loadbalancer add -g MyResourceGroup -n app-lb --cluster-name MyManagedCluster --primary-agent-pool-name nodepool2 --service-label-selector app=frontend
- name: Add a load balancer configuration that doesn't automatically place services
text: az aks loadbalancer add -g MyResourceGroup -n restricted-lb --cluster-name MyManagedCluster --primary-agent-pool-name nodepool3 --allow-service-placement false
- name: Add a load balancer configuration with custom AKS API headers
text: az aks loadbalancer add -g MyResourceGroup -n api-lb --cluster-name MyManagedCluster --primary-agent-pool-name nodepool1 --aks-custom-headers CustomHeader=Value
"""

helps['aks loadbalancer update'] = """
type: command
short-summary: Update a load balancer configuration in a managed Kubernetes cluster.
parameters:
- name: --name -n
type: string
short-summary: Name of the load balancer configuration to update.
- name: --primary-agent-pool-name -p
type: string
short-summary: Name of the primary agent pool for this load balancer.
long-summary: A string value that must specify the ID of an existing agent pool. All nodes in the given pool will always be added to this load balancer.
- name: --allow-service-placement -a
type: bool
short-summary: Whether to automatically place services on the load balancer.
long-summary: If set to false, both the external and internal load balancer will not be selected for services unless they explicitly target it.
- name: --service-label-selector -l
type: string
short-summary: Label selector for services that can be placed on this load balancer.
long-summary: Only services that match this selector can be placed on this load balancer. Format as comma-separated key=value pairs or expressions like "key In value1,value2".
- name: --service-namespace-selector -s
type: string
short-summary: Namespace label selector for services that can be placed on this load balancer.
long-summary: Services created in namespaces that match the selector can be placed on this load balancer. Format as comma-separated key=value pairs.
- name: --node-selector -d
type: string
short-summary: Node label selector for nodes that can be members of this load balancer.
long-summary: Nodes that match this selector will be possible members of this load balancer. Format as comma-separated key=value pairs.
- name: --aks-custom-headers
type: string
short-summary: Send custom headers to the AKS API.
long-summary: When specified, format should be Key1=Value1,Key2=Value2.
examples:
- name: Update a load balancer configuration's primary agent pool
text: az aks loadbalancer update -g MyResourceGroup -n secondary --cluster-name MyManagedCluster --primary-agent-pool-name nodepool2
- name: Update a load balancer configuration to disable automatic service placement
text: az aks loadbalancer update -g MyResourceGroup -n app-lb --cluster-name MyManagedCluster --allow-service-placement false
- name: Update a load balancer configuration with new service selector
text: az aks loadbalancer update -g MyResourceGroup -n app-lb --cluster-name MyManagedCluster --service-label-selector tier=frontend,environment=production
- name: Update a load balancer configuration with custom AKS API headers
text: az aks loadbalancer update -g MyResourceGroup -n api-lb --cluster-name MyManagedCluster --aks-custom-headers CustomHeader=Value
"""

helps['aks loadbalancer delete'] = """
type: command
short-summary: Delete a load balancer configuration from a managed Kubernetes cluster.
parameters:
- name: --name -n
type: string
short-summary: Name of the load balancer configuration to delete.
long-summary: The "kubernetes" load balancer cannot be deleted as it's required for cluster operation.
examples:
- name: Delete a load balancer configuration
text: az aks loadbalancer delete -g MyResourceGroup -n secondary --cluster-name MyManagedCluster
"""

helps['aks loadbalancer list'] = """
type: command
short-summary: List all load balancer configurations in a managed Kubernetes cluster.
examples:
- name: List all load balancer configurations
text: az aks loadbalancer list -g MyResourceGroup --cluster-name MyManagedCluster
- name: List all load balancer configurations in table format
text: az aks loadbalancer list -g MyResourceGroup --cluster-name MyManagedCluster -o table
"""

helps['aks loadbalancer show'] = """
type: command
short-summary: Show details of a specific load balancer configuration in a managed Kubernetes cluster.
parameters:
- name: --name -n
type: string
short-summary: Name of the load balancer configuration to show.
examples:
- name: Show details of a specific load balancer configuration
text: az aks loadbalancer show -g MyResourceGroup -n secondary --cluster-name MyManagedCluster
- name: Show details of a load balancer configuration in table format
text: az aks loadbalancer show -g MyResourceGroup -n kubernetes --cluster-name MyManagedCluster -o table
"""
143 changes: 143 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,149 @@ def load_arguments(self, _):
help='Space-separated additional endpoint(s) to perform the connectivity check.',
validator=validate_custom_endpoints)

# AKS loadbalancer command parameter configuration
with self.argument_context("aks loadbalancer add") as c:
c.argument(
"name",
options_list=["--name", "-n"],
help="Name of the load balancer configuration. Required.",
)
c.argument(
"primary_agent_pool_name",
options_list=["--primary-agent-pool-name", "-p"],
help=(
"Name of the primary agent pool for this load balancer. "
"All nodes in this pool will be added to the load balancer. Required."
),
)
c.argument(
"allow_service_placement",
options_list=["--allow-service-placement", "-a"],
arg_type=get_three_state_flag(),
help="Whether to automatically place services on the load balancer. Default is true.",
)
c.argument(
"aks_custom_headers",
help="Send custom headers. When specified, format should be Key1=Value1,Key2=Value2.",
)
c.argument(
"service_label_selector",
options_list=["--service-label-selector", "-l"],
help=(
"Only services that match this selector can be placed on this load balancer. "
"Format: key1=value1,key2=value2 for simple selectors, "
"or key1 In val1 val2,key2 Exists for advanced expressions."
),
)
c.argument(
"service_namespace_selector",
options_list=["--service-namespace-selector", "-s"],
help=(
"Services created in namespaces that match the selector can be placed on this load balancer. "
"Format: key1=value1,key2=value2 for simple selectors, "
"or key1 In val1 val2,key2 Exists for advanced expressions."
),
)
c.argument(
"node_selector",
options_list=["--node-selector", "-d"],
help=(
"Nodes that match this selector will be possible members of this load balancer. "
"Format: key1=value1,key2=value2 for simple selectors, "
"or key1 In val1 val2,key2 Exists for advanced expressions."
),
)

with self.argument_context("aks loadbalancer rebalance-nodes") as c:
c.argument(
"resource_group_name",
options_list=["--resource-group", "-g"],
help="Name of resource group.",
id_part="resource_group",
configured_default="aks",
)
c.argument(
"cluster_name",
options_list=["--name", "-n"],
help="Name of the managed cluster.",
)
c.argument(
"load_balancer_names",
options_list=["--load-balancer-names", "--lb-names"],
nargs="+",
help=(
"Space-separated list of load balancer names to rebalance. "
"If not specified, all load balancers will be rebalanced."
),
)
c.argument(
"no_wait", help="Do not wait for the long-running operation to finish."
)

with self.argument_context("aks loadbalancer update") as c:
c.argument(
"name",
options_list=["--name", "-n"],
help="Name of the public load balancer. Required.",
)
c.argument(
"primary_agent_pool_name",
options_list=["--primary-agent-pool-name", "-p"],
help=(
"Name of the primary agent pool for this load balancer. "
"All nodes in this pool will be added to the load balancer."
),
)
c.argument(
"allow_service_placement",
options_list=["--allow-service-placement", "-a"],
arg_type=get_three_state_flag(),
help="Whether to automatically place services on the load balancer. Default is true.",
)
c.argument(
"aks_custom_headers",
help="Send custom headers. When specified, format should be Key1=Value1,Key2=Value2.",
)
c.argument(
"service_label_selector",
options_list=["--service-label-selector", "-l"],
help=(
"Only services that match this selector can be placed on this load balancer. "
"Format: key1=value1,key2=value2 for simple selectors, "
"or key1 In val1 val2,key2 Exists for advanced expressions."
),
)
c.argument(
"service_namespace_selector",
options_list=["--service-namespace-selector", "-s"],
help=(
"Services created in namespaces that match the selector can be placed on this load balancer. "
"Format: key1=value1,key2=value2 for simple selectors, "
"or key1 In val1 val2,key2 Exists for advanced expressions."
),
)
c.argument(
"node_selector",
options_list=["--node-selector", "-d"],
help=(
"Nodes that match this selector will be possible members of this load balancer. "
"Format: key1=value1,key2=value2 for simple selectors, "
"or key1 In val1 val2,key2 Exists for advanced expressions."
),
)

# Define parameters for show and delete commands
for scope in [
"aks loadbalancer show",
"aks loadbalancer delete",
]:
with self.argument_context(scope) as c:
c.argument(
"name",
options_list=["--name", "-n"],
help="Name of the load balancer configuration. Required.",
)


def _get_default_install_location(exe_name):
system = platform.system()
Expand Down
13 changes: 13 additions & 0 deletions src/aks-preview/azext_aks_preview/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
cf_trustedaccess_role_binding,
cf_machines,
cf_operations,
cf_load_balancers,
)
from azext_aks_preview._format import (
aks_addon_list_available_table_format,
Expand Down Expand Up @@ -196,6 +197,18 @@ def load_command_table(self, _):
g.custom_command("update", "aks_maintenanceconfiguration_update")
g.custom_command("delete", "aks_maintenanceconfiguration_delete")

# AKS loadbalancer commands
with self.command_group(
"aks loadbalancer",
client_factory=cf_load_balancers,
) as g:
g.custom_command("list", "aks_loadbalancer_list")
g.custom_show_command("show", "aks_loadbalancer_show")
g.custom_command("add", "aks_loadbalancer_add")
g.custom_command("update", "aks_loadbalancer_update")
g.custom_command("delete", "aks_loadbalancer_delete")
g.custom_command("rebalance-nodes", "aks_loadbalancer_rebalance_nodes")

# AKS addon commands
with self.command_group(
"aks addon", managed_clusters_sdk, client_factory=cf_managed_clusters
Expand Down
Loading
Loading