Create a Kubernetes Connector for AutoStopping Rules
Connectors allow Harness to connect to your deployment environments, such as Kubernetes Clusters, AWS, Google Cloud Platform, Azure, etc. To create an AutoStopping Rule for your Kubernetes clusters, you first need to connect Harness to your cluster.
This topic describes how to connect your Kubernetes cluster to Harness for creating AutoStopping Rules.
In this topic:
- Before You Begin
- Review: Kubernetes Coverage
- Review: Kuberenetes Cluster Connector Options
- Connect Your Kubernetes Cluster Connector to CCM for AutoStopping Rules
- Step 1: Overview
- Step 2: Select Features
- Step 3: Create a Secret
- Step 4: Provide Permissions
- Next Step
Before You Begin
Make sure you have the following set up before you create a Kubernetes connector for AutoStopping Rules:
- Ensure that you have access to your Kubernetes cluster.
- Ensure that you've added a cloud provider connector depending on the type of Kubernetes cluster for which you want to create an AutoStopping Rules:
- Ensure that you have added a Kubernetes Cluster in Cloud Providers Connector. See Add a Kubernetes Cluster Connector.
Set up your Kubernetes Cluster
You'll need a target Kubernetes cluster for the Harness Delegate and deployment. Ensure your cluster meets the following requirements:
- Number of nodes: 2.
- vCPUs, Memory, Disk Size: 4vCPUs, 16GB memory, 100GB disk.
- Networking: outbound HTTPS for the Harness connection to app.harness.io, github.com, and hub.docker.com. Allow TCP port 22 for SSH.
- A Kubernetes service account with permission to create entities in the target namespace is required. The set of permissions should include
deletepermissions. In general, the cluster-admin permission or namespace admin permission is enough.
For more information, see User-Facing Roles from Kubernetes.
Your Kubernetes cluster must have unallocated resources required to run the Harness Delegate workload:
Important: these sizing requirements are for the Delegate only. Your cluster will require more memory for Kubernetes, the operating system, and other services. Ensure that the cluster has enough memory, storage, and CPU for all of its resource consumers.
- Laptop - 1.6GB memory, 0.5CPU
- Small - 3.3GB memory, 1CPU
- Medium - 6.6GB memory, 2CPU
- Large - 13.2GB memory, 4CPU
- Make sure you are a member of the Harness Administrator Group in the Harness FirstGen version. This is required to create an API key.
- Metrics Server: Metrics Server must be running on the Kubernetes cluster where your Harness Kubernetes Delegate is installed. Before enabling CCM for Kubernetes, you must ensure the utilization data for pods and nodes is available.Metrics Server is installed by default on GKE and AKS clusters, however, you need to install it on the AWS EKS cluster.Metrics Server is a cluster-wide aggregator of resource usage data. It collects resource metrics from kubelets and exposes them in the Kubernetes API server through Metrics API. CCM polls the utilization data every minute on the Delegate. The metrics are aggregated for 20 minutes and then CCM keeps one data point per 20 minutes. For more information, see Installing the Kubernetes Metrics Server from AWS.
To install a metrics server on your EKS clusters, run the following command:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.5.0/components.yaml
Review: Kubernetes Coverage
The following section lists the support for Kubernetes clusters for AutoStopping Rules:
- EKS (AWS)
- GKE (GCP)
- AKS (Azure)
Review: Kuberenetes Cluster Connector Setup Options
There are two ways to add a Kubernetes cluster connector:
- When Setting Up the Connectors: You can create Connectors from the Account Resources option in the Account Setup. See Connect Your Kuberenetes Cluster to CCM.
- When Creating an AutoStopping Rule: You can also add a Connector inline when creating an AutoStopping Rule. If you've added a Kubernetes Connector already as described in the Connect Your Kuberenetes Cluster to CCM, you can simply select your Kubernetes Connector for which you want to create AutoStopping Rules. This topic explains how to add a Kuberenetes cluster inline when creating an AutoStopping Rule.
Connect Your Kubernetes Cluster Connector to CCM for AutoStopping Rules
Perform the following steps to connect your Kubernetes cluster connector inline when creating AutoStopping Rules:
- In Cloud Costs, in AutoStopping Rules, click New AutoStopping Rule.
- In AutoStopping Rules, select the cloud account. It is the cloud account in which your workloads are running that you want to manage using AutoStopping Rules.
You can select any of the following cloud account types:
- Click Connect to your Cloud Account drop-down list. The name of the drop-down list depends on the cloud account type selection. For example, if you select AWS, then the label reads as Connect to your AWS account.
- In Create or Select an Existing Connector page, select your Conenctor from the list.
If you have not created a cloud provider connector already, click New Connector. Refer to the following topics to add your cloud account Connector (depending on the type of cloud account you have selected):
- Once you've created your cloud account type Connector, select the Connector, and click Apply Selected.
- In Let's get you started page, click Next.
- In Configurations, in Define your AutoStopping rule, in Name your Rule, enter a name for your rule. This is the name of your AutoStopping rule.
- In Idle time, enter the idle time in minutes. This is the time that the AutoStopping rule will wait before stopping the idle instances.
- In Resources to be managed by the AutoStopping rules step, select Kubernetes Cluster and then click Add a cluster.
- Click Create a new connector.
Step 1: Overview
- In Kubernetes Connector, in Overview, enter the Name for your connector. The name will appear in AutoStopping Dashboard to identify this cluster.
- In Reference an existing connector, select your Kubernetes cluster connector from the drop-down list. See Add a Kubernetes Cluster Connector.
- Click Save and Continue.
Step 2: Select Features
- In Choose Requirements, select the Cloud Cost Management features that you would like to enable for your Kubernetes clusters. Based on your selection Harness requires specific permissions.To create AutoStopping Rules for your Kubernetes connector, ensure that you have selected Cost Visibility and AutoStopping both.You need to provide different permissions depending on the features that you enable for your Kubernetes clusters. CCM offers the following features:
Cost Visibility (Required)
This feature is available by default and provides the following capabilities:
- Insights into cluster costs by pods, namespace, workloads, etc.
- Idle and unallocated cluster costs
- Workload recommendations
- Root cost analysis using cost perspectives
- Cost anomaly detection
- Governance using budgets and forecasts
- Alert users using Email and Slack notification
Kubernetes optimization using AutoStopping rules (Required for AutoStopping Rules)
This feature allows you to enable Intelligent Cloud AutoStopping for Kubernetes. For more information, see Create AutoStopping Rules for AWS.
- Works for custom resources, EKS, AKS, GKE, etc.
- Orchestrate VMs based on idleness
- Provides granular savings visibility
- Click Continue.
Step 3: Create a Secret
The secret creation settings appear only if you have selected Kubernetes Optimization by AutoStopping feature in the Feature Selection step. In this step, you are providing permissions for intelligent cloud AutoStopping rules. For more information, see Create AutoStopping Rules for Kubernetes.
- In Secret creation, click create an API key here and create an API key. See Create an API Key.You must be logged into the Harness FirstGen version as a member of the Administrators User Group to create an API key. For details about Harness' role-based access control, see Managing Users and Groups (RBAC).
- Run the following commands in your Kubernetes cluster:
- Create a namespace.
kubectl create namespace harness-autostopping
- In the following YAML, add the API token that you created (in step 1) and run the command in your K8s cluster.
token: <paste token here>
- Run the following command:
kubectl apply -f secret.yaml
- Create a namespace.
- Click Continue.
Step 4: Provide Permissions
- In Provide Permissions, click Download YAML.
- Copy the downloaded YAML to a machine where you have
kubectlinstalled and have access to your Kubernetes cluster.
- Run the following command to apply the Harness Delegate to your Kubernetes Cluster.
kubectl apply -f ccm-kubernetes.yaml
- Click Done and Continue.
- In Verify connection, once the Test Connection succeeds, click Finish.
The Connector is now listed in Connectors.