Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Create Azure k3s Cluster with CAPI #145

Open
chaitu7989 opened this issue Nov 20, 2024 · 0 comments
Open

Unable to Create Azure k3s Cluster with CAPI #145

chaitu7989 opened this issue Nov 20, 2024 · 0 comments

Comments

@chaitu7989
Copy link

chaitu7989 commented Nov 20, 2024

Hi Team,
I’m facing an issue while attempting to create a k3s cluster on Azure using Cluster API (CAPI). The resources (like VMs) are not being created in Azure, but the resource group and other associated resources are visible in the Azure portal. Below are the details:
Cluster API and Machine Deployment Status
bash

▶ kubectl get cluster-api
NAME                                     CLUSTERCLASS   PHASE         AGE    VERSION
cluster.cluster.x-k8s.io/clusterapik3s                  Provisioned   111m   

NAME                                                    CLUSTER         REPLICAS   READY   UPDATED   UNAVAILABLE   PHASE   AGE    VERSION
machinedeployment.cluster.x-k8s.io/clusterapik3s-md-0   clusterapik3s                                                      111m   v1.30.2+k3s2

NAME                                                                   AGE
awsclustercontrolleridentity.infrastructure.cluster.x-k8s.io/default   7d6h

NAME                                                                    TYPE               AGE
azureclusteridentity.infrastructure.cluster.x-k8s.io/cluster-identity   ServicePrincipal   111m

NAME                                                         CLUSTER         READY   REASON   AGE
azurecluster.infrastructure.cluster.x-k8s.io/clusterapik3s   clusterapik3s   True             111m

NAME                                                                               AGE
azuremachinetemplate.infrastructure.cluster.x-k8s.io/clusterapik3s-control-plane   111m
azuremachinetemplate.infrastructure.cluster.x-k8s.io/clusterapik3s-md-0            111m
Cluster Description Output
bash


▶ clusterctl describe cluster clusterapik3s
NAME                                                              READY  SEVERITY  REASON  SINCE  MESSAGE 
Cluster/clusterapik3s                                             True                     109m            
├─ClusterInfrastructure - AzureCluster/clusterapik3s              True                     109m            
└─ControlPlane - KThreesControlPlane/clusterapik3s-control-plane                            

Generated YAML File
Below is the Template YAML file used for creating the Azure k3s cluster:

apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
  name: ${CLUSTER_NAME}
  namespace: default
spec:
  clusterNetwork:
    pods:
      cidrBlocks:
      - 10.42.0.0/16
    services:
      cidrBlocks:
      - 10.43.0.0/16
  controlPlaneRef:
    apiVersion: controlplane.cluster.x-k8s.io/v1beta2
    kind: KThreesControlPlane
    name: ${CLUSTER_NAME}-control-plane
  infrastructureRef:
    apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
    kind: AzureCluster
    name: ${CLUSTER_NAME}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AzureCluster
metadata:
  name: ${CLUSTER_NAME}
  namespace: default
spec:
  identityRef:
    apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
    kind: AzureClusterIdentity
    name: ${CLUSTER_IDENTITY_NAME}
  location: ${AZURE_LOCATION}
  networkSpec:
    subnets:
    - name: control-plane-subnet
      role: control-plane
    - name: node-subnet
      role: node
  resourceGroup: ${AZURE_RESOURCE_GROUP:=${CLUSTER_NAME}}
  subscriptionID: ${AZURE_SUBSCRIPTION_ID}
---
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: KThreesControlPlane
metadata:
  name: ${CLUSTER_NAME}-control-plane
  namespace: default
spec:
  kthreesConfigSpec:
    serverConfig:
      kubeControllerManagerArgs:
      # allocate-node-cidrs needs to be true to use flannel as CNI
      - allocate-node-cidrs=true
      - cluster-name=${CLUSTER_NAME}
      disableCloudController: true
      cloudProviderName: external
    files:
    - contentFrom:
        secret:
          key: control-plane-azure.json
          name: ${CLUSTER_NAME}-control-plane-azure-json
      owner: root:root
      path: /etc/kubernetes/azure.json
      permissions: "0644"
    agentConfig:
      nodeName: '{{ ds.meta_data["local_hostname"] }}'
    postK3sCommands: []
    preK3sCommands: []
  machineTemplate:
    infrastructureRef:
      apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
      kind: AzureMachineTemplate
      name: ${CLUSTER_NAME}-control-plane
  replicas: ${CONTROL_PLANE_MACHINE_COUNT:=1}
  version: ${KUBERNETES_VERSION:=v1.30.2+k3s2}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AzureMachineTemplate
metadata:
  name: ${CLUSTER_NAME}-control-plane
  namespace: default
spec:
  template:
    spec:
      osDisk:
        diskSizeGB: 128
        osType: Linux
      sshPublicKey: ${AZURE_SSH_PUBLIC_KEY_B64:=""}
      vmSize: ${AZURE_CONTROL_PLANE_MACHINE_TYPE:="Standard_D2s_v3"}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
  name: ${CLUSTER_NAME}-md-0
  namespace: default
spec:
  clusterName: ${CLUSTER_NAME}
  replicas: ${WORKER_MACHINE_COUNT:=2}
  selector:
    matchLabels: null
  template:
    spec:
      bootstrap:
        configRef:
          apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
          kind: KThreesConfigTemplate
          name: ${CLUSTER_NAME}-md-0
      clusterName: ${CLUSTER_NAME}
      infrastructureRef:
        apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
        kind: AzureMachineTemplate
        name: ${CLUSTER_NAME}-md-0
      version: ${KUBERNETES_VERSION:=v1.30.2+k3s2}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AzureMachineTemplate
metadata:
  name: ${CLUSTER_NAME}-md-0
  namespace: default
spec:
  template:
    spec:
      osDisk:
        diskSizeGB: 128
        osType: Linux
      sshPublicKey: ${AZURE_SSH_PUBLIC_KEY_B64:=""}
      vmSize: ${AZURE_NODE_MACHINE_TYPE:="Standard_D2s_v3"}
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: KThreesConfigTemplate
metadata:
  name: ${CLUSTER_NAME}-md-0
  namespace: default
spec:
  template:
    spec:
      files:
      - contentFrom:
          secret:
            key: worker-node-azure.json
            name: ${CLUSTER_NAME}-md-0-azure-json
        owner: root:root
        path: /etc/kubernetes/azure.json
        permissions: "0644"
      agentConfig:
        nodeName: '{{ ds.meta_data["local_hostname"] }}'
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AzureClusterIdentity
metadata:
  name: "${CLUSTER_IDENTITY_NAME}"
  labels:
    clusterctl.cluster.x-k8s.io/move-hierarchy: "true"
spec:
  type: ServicePrincipal
  allowedNamespaces: {}
  tenantID: "${AZURE_TENANT_ID}"
  clientID: "${AZURE_CLIENT_ID}"
  clientSecret: {"name":"${AZURE_CLUSTER_IDENTITY_SECRET_NAME}","namespace":"${AZURE_CLUSTER_IDENTITY_SECRET_NAMESPACE}"}
# (Full YAML omitted for brevity; provided in the full file)

Issue
The cluster creation process indicates the cluster is provisioned, and resources like AzureClusterIdentity, AzureCluster, and AzureMachineTemplates are created successfully.
Despite this, control plane VMs are not being created in Azure, and I’m seeing the following error in the CACP3 Logs:
1.731990851709848e+09 INFO controllers.KThreesControlPlane Cluster Controller has not yet set OwnerRef {"namespace": "azure-cluster-k3s", "kthreesControlPlane": "clusterapik3s-control-plane"}
1.7319908517153668e+09 INFO controllers.KThreesControlPlane Cluster Controller has not yet set OwnerRef {"namespace": "azure-cluster-k3s", "kthreesControlPlane": "clusterapik3s-control-plane"}
Commands Used to Check Status
bash

▶ kubectl get cluster-api
▶ clusterctl describe cluster clusterapik3s
Kubectl logs of capi-bootstrap-system
Kubectl logs of capi-k3s-control-plane-system
Kubectl logs pf capz-system
Request for Help
Could someone assist me in understanding why the VMs (control plane and worker nodes) are not being created?
I suspect there might be an issue with the ownerReferences or a misconfiguration in the YAML file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant