Skip to content

Chargeback Groups

RCTL support helps to automate the lifecycle of operations associated with Chargeback Groups.

Resource Create Get Delete
Chargeback Group Yes Yes Yes

Chargeback Group

Create Chargeback Group

Use the below command to create a chargeback group of summary/detailed Report

./rctl create chargebackgroup -f <configfile_name>

An illustrative example of a detailed report config file is given below

apiVersion: system.k8smgmt.io/v3
kind: ChargebackGroup
metadata:
  name: rctld2
  description: ""
spec:
  inclusions:
  - project: p1
    cluster: ""
    namespace: ""
    label:
    - scb3
  exclusions:
  - project: p1
    cluster: ""
    namespace: ""
    label: []
  type: detailed

An illustrative example of a summary report config file is given below

apiVersion: system.k8smgmt.io/v3
kind: ChargebackGroup
metadata:
  name: rctld2
  description: ""
spec:
  inclusions:
  - project: p1
  aggregate:
    project: false
    cluster: false
    namespace: false
    label:
    - scb3
  type: summary

Generate Report

To generate a chargeback group report, use the below command

./rctl create chargebackgroupreport -f <configfile_name>

An illustrative example of a report generating config file is given below

apiVersion: system.k8smgmt.io/v3
kind: ChargebackGroupReport
metadata:
  name: rctld2
  description: ""
spec:
  groupName: rctld2
  startDate:
    seconds: 1669011971
  endDate:
    seconds: 1669616771

List Chargeback Groups

To view the list of all chargeback groups, use the below command

./rctl get chargebackgroup
+------------+-------------+-------------------+
| GROUP NAME | REPORT TYPE | REPORTS GENERATED |
+------------+-------------+-------------------+
| rctl1      | summary     | 0                 |
+------------+-------------+-------------------+
| rctl2      | summary     | 1                 |
+------------+-------------+-------------------+
| rctl3      | detailed    | 0                 |
+------------+-------------+-------------------+
| cb-group-1 | summary     | 0                 |
+------------+-------------+-------------------+
| cb-group-2 | summary     | 0                 |
+------------+-------------+-------------------+

To retrieve a specific chargeback group details, use the below command

./rctl get chargebackgroup <group-name>

Example Output

./rctl get chargebackgroup rctl2
+------------+-------------+-------------------+
| GROUP NAME | REPORT TYPE | REPORTS GENERATED |
+------------+-------------+-------------------+
| rctl2      | summary     | 1                 |
+------------+-------------+-------------------+

Or you can use below commands to get more information of the chargeback group in json or yaml format

./rctl get chargebackgroup <cbg-name> -o json

(or)

./rctl get chargebackgroup <cbg-name> -o yaml

Example Output

./rctl get chargebackgroup cb-group-1 -o yaml
apiVersion: system.k8smgmt.io/v3
kind: ChargebackGroup
metadata:
  name: cb-group-1
spec:
  aggregate: {}
  inclusions:
  - label:
    - ""
  type: summary
status:
  extra:
    data: {}

Chargeback Share Configuration

Users can enable/disable the Chargeback Share Type via the configuration file.

Below is an example of chargeback group share config file. Users can edit the shareEnabled parameter to true or false to share/unshare the chargebackgroup and change the required sharetype tenancy/allocation.

apiVersion: system.k8smgmt.io/v3
kind: ChargebackShare
metadata:
  name: chargebackshare
spec:
  shareUnallocatedCost: true
  shareCommonServicesCost: true
  shareControlPlaneCost: true
  shareType: allocation

Now run the below command to apply the required configuration

./rctl create chargebackshare -f <configfile_name>

Note

Chargeback share configuration will apply to "unallocated resources", "control plane", and "common services".


Apportioning costs for Common Services

The platform now supports identification of common services (e.g. security tools, monitoring tools) through configuration of namespace list/labels and adds the ability to share the cost of running these common services among tenants (teams/applications) sharing the cluster when generating chargeback/showback reports.

Below are some of the example config specs to configure policies for identifying common services.

For all clusters in all projects

apiVersion: system.k8smgmt.io/v3
kind: ChargebackCommonServicesPolicy
metadata:
    name: policy1
spec:
    policyProject: '*'
    selectionType: allClusters
    commonServicesNamespaces:
    - kube-system
    commonServicesNamespaceLabels:
    - key: 'common'
      value: 'service'

For all clusters in a specific project

apiVersion: system.k8smgmt.io/v3
kind: ChargebackCommonServicesPolicy
metadata:
    name: policy2
spec:
    policyProject: 'project-name'
    selectionType: allClusters
    commonServicesNamespaces:
    - kube-system
    commonServicesNamespaceLabels:
    - key: 'common'
      value: 'service'

For specific cluster(s) in a project

apiVersion: system.k8smgmt.io/v3
kind: ChargebackCommonServicesPolicy
metadata:
    name: policy3
spec:
    policyProject: 'project-name'
    selectionType: clusterNames
    clusters:
    - 'cluster1'
    - 'cluster2'
    commonServicesNamespaces:
    - kube-system
    commonServicesNamespaceLabels:
    - key: 'common'
      value: 'service'

For specific cluster label(s) in a project

apiVersion: system.k8smgmt.io/v3
kind: ChargebackCommonServicesPolicy
metadata:
    name: policy4
spec:
    policyProject: 'project-name'
    selectionType: clusterLabels
    clusterLabels:
    - key: "rafay.dev/clusterName"
      value: "sachin-24-aug"
    commonServicesNamespaces:
    - kube-system
    commonServicesNamespaceLabels:
    - key: 'common'
      value: 'service'

Delete Chargeback Group

Users can delete a chargeback group using the below command

./rctl delete chargebackgroup <chargebackgroup-name>

Important

You cannot delete a chargeback group report and chargeback share