Skip to content

Commit a0731a5

Browse files
authored
Merge pull request #18262 from hakman/azure-cloud-routes
azure: enable CCM cloud routes for kubenet and kindnet
2 parents 5d48728 + c5b953b commit a0731a5

8 files changed

Lines changed: 36 additions & 4 deletions

File tree

nodeup/pkg/model/cloudconfig.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type azureCloudConfig struct {
5050
Location string `json:"location,omitempty"`
5151
VnetName string `json:"vnetName,omitempty"`
5252
SubnetName string `json:"subnetName,omitempty"`
53+
RouteTableName string `json:"routeTableName,omitempty"`
5354
SecurityGroupName string `json:"securityGroupName,omitempty"`
5455
UseInstanceMetadata bool `json:"useInstanceMetadata,omitempty"`
5556
DisableAvailabilitySetNodes bool `json:"disableAvailabilitySetNodes,omitempty"`
@@ -133,6 +134,7 @@ func (b *CloudConfigBuilder) build(c *fi.NodeupModelBuilderContext, inTree bool)
133134
Location: b.NodeupConfig.AzureLocation,
134135
VnetName: vnetName,
135136
SubnetName: b.NodeupConfig.AzureSubnetName,
137+
RouteTableName: b.NodeupConfig.AzureRouteTableName,
136138
SecurityGroupName: b.NodeupConfig.AzureSecurityGroupName,
137139
UseInstanceMetadata: true,
138140
DisableAvailabilitySetNodes: true,

nodeup/pkg/model/cloudconfig_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func TestBuildAzure(t *testing.T) {
105105
ResourceGroup: resourceGroupName,
106106
VnetName: vnetName,
107107
SubnetName: "test-subnet",
108+
RouteTableName: cluster.Name,
108109
SecurityGroupName: vnetName,
109110
UseInstanceMetadata: true,
110111
UseManagedIdentityExtension: true,

pkg/model/azuremodel/network.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,22 @@ func (b *NetworkModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
180180
DestinationApplicationSecurityGroupNames: []*string{fi.PtrTo(b.NameForApplicationSecurityGroupNodes())},
181181
DestinationPortRange: fi.PtrTo("*"),
182182
})
183+
// Kindnet preserves pod-CIDR source IPs to host services; Azure NSG ASG
184+
// matching needs an explicit allow since pod IPs aren't NIC-assigned.
185+
// Scoped to nodes to keep DenyAllToControlPlane and the etcd denies effective.
186+
if b.Cluster.Spec.Networking.Kindnet != nil && b.Cluster.Spec.Networking.PodCIDR != "" {
187+
nsgTask.SecurityRules = append(nsgTask.SecurityRules, &azuretasks.NetworkSecurityRule{
188+
Name: fi.PtrTo("AllowPodCIDRToNodes"),
189+
Priority: fi.PtrTo[int32](1006),
190+
Access: network.SecurityRuleAccessAllow,
191+
Direction: network.SecurityRuleDirectionInbound,
192+
Protocol: network.SecurityRuleProtocolAsterisk,
193+
SourceAddressPrefix: fi.PtrTo(b.Cluster.Spec.Networking.PodCIDR),
194+
SourcePortRange: fi.PtrTo("*"),
195+
DestinationApplicationSecurityGroupNames: []*string{fi.PtrTo(b.NameForApplicationSecurityGroupNodes())},
196+
DestinationPortRange: fi.PtrTo("*"),
197+
})
198+
}
183199
etcdPeerMax := wellknownports.EtcdEventsPeerPort
184200
for _, c := range b.Cluster.Spec.EtcdClusters {
185201
if c.Name == "leases" {

pkg/model/components/azurecloudcontrollermanager.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,16 @@ func (b *AzureCloudControllerManagerOptionsBuilder) BuildOptions(cluster *kops.C
5555
eccm.LogLevel = 2
5656
}
5757

58+
// Kubenet and kindnet rely on cloud routes to deliver pod-to-pod traffic across nodes:
59+
// the Azure VNet is L3 and drops packets whose destination IP is not a known VNet IP
60+
// (pod CIDRs are not), so the Azure CCM must populate UDRs in the route table that
61+
// kOps associates with the node subnet. EnableIPForwarding is already set on every NIC.
62+
networking := cluster.Spec.Networking
63+
if networking.Kubenet != nil || networking.Kindnet != nil {
64+
eccm.ConfigureCloudRoutes = fi.PtrTo(true)
65+
} else {
66+
eccm.ConfigureCloudRoutes = fi.PtrTo(false)
67+
}
68+
5869
return nil
5970
}

tests/integration/update_cluster/gossip-azure/data/azurerm_storage_blob_cluster-completed.spec_source

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ spec:
1919
manageStorageClasses: true
2020
cloudControllerManager:
2121
azureNodeManagerImage: mcr.microsoft.com/oss/kubernetes/azure-cloud-node-manager:v1.34.3
22+
configureCloudRoutes: false
2223
image: mcr.microsoft.com/oss/kubernetes/azure-cloud-controller-manager:v1.34.3
2324
leaderElection:
2425
leaderElect: true

tests/integration/update_cluster/minimal_azure/data/azurerm_storage_blob_cluster-completed.spec_source

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ spec:
2020
manageStorageClasses: true
2121
cloudControllerManager:
2222
azureNodeManagerImage: mcr.microsoft.com/oss/kubernetes/azure-cloud-node-manager:v1.34.3
23+
configureCloudRoutes: false
2324
image: mcr.microsoft.com/oss/kubernetes/azure-cloud-controller-manager:v1.34.3
2425
leaderElection:
2526
leaderElect: true

upup/models/cloudup/resources/addons/azure-cloud-controller.addons.k8s.io/helm-values.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ infra:
1010
cloudControllerManager:
1111
# Overridden by kustomize patch.
1212
imageTag: "v0.0.0"
13-
# No CNI on Azure uses node CIDR allocation.
13+
# KCM allocates pod CIDRs; CCM only writes UDRs into the route table.
1414
allocateNodeCidrs: "false"
15-
# No CNI on Azure uses CCM-managed routes.
16-
configureCloudRoutes: "false"
15+
# Enabled for kubenet/kindnet, which require UDRs to forward pod-CIDR traffic across nodes.
16+
configureCloudRoutes: "{{ WithDefaultBool .ExternalCloudControllerManager.ConfigureCloudRoutes false }}"
1717
clusterCIDR: "{{ .Networking.PodCIDR }}"
1818
leaderElect: "{{ .ExternalCloudControllerManager.LeaderElection.LeaderElect }}"
1919
logVerbosity: "{{ .ExternalCloudControllerManager.LogLevel }}"

upup/models/cloudup/resources/addons/azure-cloud-controller.addons.k8s.io/k8s-1.31.yaml.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ spec:
213213
- --cloud-provider=azure
214214
- --cluster-cidr={{ .Networking.PodCIDR }}
215215
- --cluster-name={{ ClusterName }}
216-
- --configure-cloud-routes=false
216+
- --configure-cloud-routes={{ WithDefaultBool .ExternalCloudControllerManager.ConfigureCloudRoutes false }}
217217
- --controllers=*,-cloud-node
218218
- --leader-elect={{ .ExternalCloudControllerManager.LeaderElection.LeaderElect
219219
}}

0 commit comments

Comments
 (0)