Skip to content

CLI

Azure Kubernetes Service (AKS) is a fully managed Kubernetes service provided by Microsoft Azure. We have developed an integration with AKS to ensure that users can provision AKS Clusters in any region using the RCTL CLI.


Imperative

Create Cluster

Use this command to create an AKS cluster object in the configured project on the controller. You can optionally also specify the cluster blueprint during this step.

To create an AKS cluster: cloud credential, resource group and Kubernetes version are mandatory

./rctl create cluster aks <demo-aks-cluster> --cloud-creds <user-credentials> --resource-group <demo-resoursegroup> --version <k8s-version>

Users can add more flags based on the cluster requirement. The below help flag allows the users to view and utilize the required flags that can be associated with a new cluster

./rctl create cluster aks --help

Below is an example to create an AKS cluster with cluster autoscaler enabled and a custom blueprint:

./rctl create cluster aks <demo-aks-cluster> --cloud-creds <user-credentials> --resource-group <demo-resoursegroup> --version <k8s-version> --count 1 --enable-auto-scaling --min-count 1 --max-count 3 --blueprint <blueprint-name>

List Clusters

To retrieve a list of clusters, use the below command

./rctl get cluster

Output

+---------------------+-----------+-----------+
| NAME                | TYPE      | OWNERSHIP |
+---------------------+-----------+-----------+
| swag-aws            | aws-ec2   | self      |
+---------------------+-----------+-----------+
| aks19               | azure-aks | self      |
+---------------------+-----------+-----------+
| aks1                | azure-aks | self      |
+---------------------+-----------+-----------+

To retrieve a single cluster, use the below command

./rctl get cluster <cluster-name>

Example:

./rctl get cluster aks1

Output

+------+----------------------------+-----------+-----------+-------------+-----------------------+
| NAME | CREATED AT                 | TYPE      | STATUS    | BLUEPRINT   | PROVISION STATUS      |
+------+----------------------------+-----------+-----------+-------------+-----------------------+
| aks1 | 2021-09-16T20:44:45.88153Z | azure-aks | NOT_READY | default-aks | INFRA_CREATION_FAILED |
+------+----------------------------+-----------+-----------+-------------+-----------------------+

Delete Cluster

Users can delete one or more clusters with a single command

./rctl delete cluster <cluster-name>

(or)

./rctl delete cluster <cluster1-name> <cluster2-name>

Create nodePool

To create a nodepool on AKS clusters, use the below command

./rctl create nodepool aks <node-pool-name> <cluster-name>

Users can add more flags based on the nodepool requirement. The below help flag allows the users to view and utilize the required flags that can be associated with a new nodepool

./rctl create nodepool aks --help

Below is an example to create a Nodepool on an AKS cluster with cluster autoscaler enabled:

./rctl create node-pool aks newpool ap-aks-2 --enable-auto-scaling --count 1 --max-pods-per-node 50 --node-labels pool=new

Update Nodepool

Use the below commands to update a nodePool

./rctl update node-pool aks <np-name> <cluster-name>
Users can add more flags based on the requirement to update different nodepool parameters. The below help flag allows the users to view the list of flags and utilize the required flags to update the nodepool

./rctl update node-pool aks --help
Currently, scaling (auto or manual) and mode change are supported for nodepools

Scaling command

Auto Scaling

./rctl update node-pool aks <np-name> <cluster-name> --scaling-type auto --min-count <n> --max-count <n>

Example:

./rctl update node-pool aks demo-np demo-cluster --scaling-type auto --min-count 1 --max-count 2

Manual Scaling

./rctl update node-pool aks <np-name> <cluster-name> --scaling-type manual --count <n>

Example:

./rctl update node-pool aks demo-np demo-cluster --scaling-type manual --count 3

Mode change command

./rctl update node-pool aks <np-name> <cluster-name> --mode

Delete Nodepool

Use the below command to delete a nodePool

./rctl delete node-pool <node-name> <cluster-name>

Cluster Upgrade

Use the below command to upgrade a cluster

./rctl upgrade cluster <cluster-name> --version <version>

Example:

./rctl upgrade cluster kal-aks-nov16 --version 1.20.9

Cluster Node Pool Upgrade

Users are allowed to upgrade the Cluster Node Pool with three modes

  1. Upgrade only node pools
./rctl upgrade cluster ClusterName --mode node-pools-only --node-pools <PoolName> --version <version>

(or)

./rctl upgrade node-pool <nodepool-name> <cluster-name> --version <version>
  1. Upgrade control plane only
./rctl upgrade cluster <cluster-name> --mode control-plane-only --version <version>
  1. Upgrade both node pools and control plane
./rctl upgrade cluster <cluster-name> --mode both --version <version>

Declarative

You can also create the cluster based on a version controlled cluster spec that you can store in a Git repository. This enables users to develop automation for reproducible infrastructure.

Create Cluster

./rctl create cluster aks -f cluster-spec.yaml

An illustrative example of the cluster spec YAML file for AKS is shown below

apiVersion: rafay.io/v1alpha1
kind: Cluster
metadata:
  name: demo-aks
  project: defaultproject
spec:
  type: aks
  blueprint: minimal
  cloudprovider: my-cloud-creds
  clusterConfig:
    apiVersion: rafay.io/v1alpha1
    kind: aksClusterConfig
    metadata:
      name: my-cluster
    spec:
      resourceGroupName: my-rg
      managedCluster:
        type: Microsoft.ContainerService/managedClusters
        apiVersion: "2021-05-01"
        location: eastus2
        identity:
          type: SystemAssigned
        properties:
          dnsPrefix: my-cluster-dns
          kubernetesVersion: 1.21.1
      nodePools:
      - type: Microsoft.ContainerService/managedClusters/agentPools
        apiVersion: "2021-05-01"
        location: eastus2
        name: agentpooly
        properties:
          count: 1
          maxPods: 30
          mode: System
          vmSize: Standard_B2s

Successfully provisioned AKS cluster


Create Nodepool

./rctl create nodepool aks -f node-spec.yaml

An illustrative example of the cluster spec YAML file for AKS is shown below

apiVersion: rafay.io/v1alpha1
kind: aksClusterConfig
metadata:
  name: my-cluster
spec:
  resourceGroupName: my-rg
  nodePools:
  - type: Microsoft.ContainerService/managedClusters/agentPools
    apiVersion: "2021-05-01"
    name: agentpooly
    properties:
      count: 1
      maxPods: 30
      mode: System
      vmSize: Standard_B2s
  - type: Microsoft.ContainerService/managedClusters/agentPools
    apiVersion: "2021-05-01"
    name: agentpoolz
    properties:
      count: 1
      vmSize: Standard_B2s

Download Cluster Config

Use the below command to download the AKS Cluster Config file

./rctl get cluster config ClusterName > ClusterConfigFileName.yaml

Example:

/rctl get cluster config demo-akscluster > demo-akscluster-config.yaml

Important

Download the cluster configuration only after the cluster is completely provisioned