Links

Installing Kubecost on Alibaba

Installing Kubecost via Helm

Kubecost installation is the same as other cloud providers with Helm v3.1+:
helm install kubecost/cost-analyzer -n kubecost -f values.yaml
Your values.yaml files must contain the below parameters:
prometheus:
server:
global:
external_labels:
cluster_id: aliyun-ali-test-1 # Each cluster should have a unique ID
kubecostProductConfigs:
clusterName: "aliyun-ali-test-" # used for display in Kubecost UI
serviceKeySecretName: "alibaba-service-key"
The alibaba-service-key can be created using the following command:
kubectl create secret generic alibaba-service-key -n kubecost –from-file=./example_path
Your path needs a file having Alibaba Cloud secrets. Alibaba secrets can be passed in a JSON file with the file in the format:
{
"alibaba_access_key_id": “XXX”
"alibaba_secret_access_key": “XXX"
}
These two can be generated in the Alibaba Cloud portal. Hover over your user account icon, then select AccessKey Management. A new window opens. Select Create AccessKey to generate a unique access token that will be used for all activities related to Kubecost.

Troubleshooting

Cannot install Kubecost without a default StorageClass

While getting all the available Storage Classes that the Alibaba K8s cluster comes with, there may not be a default storage class. Kubecost installation may fail as the cost-model pod and Prometheus server pod would be in a status pending state.
To fix this issue, make any of the Storage Classes in the Alibaba K8s cluster as Default using the below command:
kubectl patch storageclass alicloud-disk-available -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
Following this, installation should proceed as normal.