# Auto Mode

## About Auto Mode

Amazon **EKS Auto Mode** automates Kubernetes cluster management by handling tasks such as node provisioning, scaling, and upgrades. It eliminates manual node group configuration, ensuring clusters are cost-efficient, secure, and optimized for performance.

For more details, visit [Amazon EKS Auto Mode](https://docs.aws.amazon.com/eks/latest/userguide/create-node-pool.html).

## Why EKS Auto Mode?

EKS Auto Mode simplifies operations by leveraging AWS best practices for resource utilization and security. It uses Karpenter for automatic node provisioning and scaling, while managing infrastructure tasks like node scaling and automatic upgrades every 21 days.

Auto Mode can be enabled on **Day 0** during new cluster creation, where it provisions and scales nodes automatically. For **Day 2**, existing clusters can be converted to Auto Mode, retaining previously configured node groups. Users can decide to keep or remove original node groups based on requirements.

For a deeper dive into how EKS Auto Mode works, read this [AWS blog](https://aws.amazon.com/blogs/containers/getting-started-with-amazon-eks-auto-mode/).

Did you know ?

EKS Auto Mode can be managed through various methods:

- [API](https://docs.rafay.co/automation/api/apis/)
- [UI](https://docs.rafay.co/clusters/eks/auto_mode/)
- [CLI](https://docs.rafay.co/clusters/eks/auto_mode/)
- [Terraform](https://registry.terraform.io/providers/RafaySystems/rafay/latest/docs/resources/eks_cluster)
- [GitOps](https://docs.rafay.co/gitops/stages/system_sync/)

## Pre-requisite

The following permissions are required for enabling the EKS Auto Mode, divided into `ClusterRole` and `NodeRole` permissions.

#### ClusterRole Permissions:

- `AmazonEKSComputePolicy`
- `AmazonEKSBlockStoragePolicy`
- `AmazonEKSLoadBalancingPolicy`
- `AmazonEKSNetworkingPolicy`
- `AmazonEKSClusterPolicy`

#### NodeRole Permissions:

- `AmazonEKSWorkerNodeMinimalPolicy`
- `AmazonEC2ContainerRegistryPullOnly`

For more details on IAM role requirements refer to the AWS documentation:

- [EKS Auto Mode cluster IAM role](https://docs.aws.amazon.com/eks/latest/userguide/auto-cluster-iam-role.html)
- [EKS Auto Mode node IAM role](https://docs.aws.amazon.com/eks/latest/userguide/auto-create-node-role.html)

## Day-0 Support

On **Day 0**, EKS Auto Mode can be enabled during cluster creation, allowing automatic node provisioning and scaling with minimal configuration. This simplifies cluster setup, ensuring optimal resource management aligned with AWS best practices.

### Enable Auto Node via UI

- During cluster creation, after selecting the General settings, enable **Use EKS Auto Mode** under Cluster settings
- Select the **Node Pool** type from the drop-down: either `general-purpose` or `system` or `both`
- Provide the **Node Role ARN**. If no Node Role ARN is provided, default policies will be automatically applied to the nodes

### Enable Auto Node via RCTL

To enable auto node via RCTL, add the `autoModeConfig` parameters to the EKS Cluster Config Spec as given in the below example

```
autoModeConfig:
  enabled: true
  nodeRoleARN: arn:aws:iam::200143372387:role/rafay-demouser1-auto-01-cluster-AutoModeNodeRole-65AagDXNwCps
  nodePools:
  - general-purpose
  - system
```

At least one default system node pool is required for Rafay cluster blueprints so the Rafay operator (and its pods) can be deployed and scheduled during cluster provisioning.

### System Node Pool Taints

The built-in default **system node pool** has a taint with the following configuration:

- **Key**: `CriticalAddonsOnly`
- **Effect**: `NoSchedule`

Many EKS addons automatically tolerate this taint. However if you intend to schedule your application workloads or custom blueprint pods on the system node pool, you must ensure they have matching tolerations.

For Rafay blueprint components, you can use the [**System Components Placement**](https://docs.rafay.co/clusters/eks/provisioning/#system-components-placement) setting in the cluster configuration to automatically apply the required tolerations and ensure placement on the system node pool.

For more information, refer to the [AWS documentation](https://docs.aws.amazon.com/eks/latest/userguide/set-builtin-node-pools.html).

## Day-2 Support

Users have the ability to enable EKS Auto Mode post-cluster creation if it was not initially enabled. As part of Day 2 support, users can convert an existing cluster to use the EKS Auto Mode configuration. Once Auto Mode is enabled, users can modify cluster settings, update scaling configurations, and manage node upgrades. It is also possible to disable Auto Mode and revert to manual node management when needed.

To enable auto mode,

- Select the desired cluster from the Clusters page
- Click on the settings gear icon and select **Enable/Disable Auto Mode**

- Enable **Use EKS Auto Mode** and choose the **Node Pool(s)**: either `system`, `general-purpose`, or both
- Optionally, enter the **Node Role ARN** and click **Save**

A message appears stating "EKS Auto Mode updated successfully."

## EKS Auto on Existing Clusters

Before enabling EKS Auto Mode on an existing cluster, ensure you're running Karpenter v1.1 or later to avoid API conflicts. For detailed prerequisites and migration steps, see the [AWS documentation](https://docs.aws.amazon.com/eks/latest/userguide/migrate-auto.html).
