Delivering modern cloud-native applications with open source technologies on Azure Kubernetes Service
This section helps you install Kubecost on the cluster you’ve successfully created in Section 1. Optionally, you’ll also expose your Kubecost UI via a Load Balancer.
kubectl
These instructions are also available in kubecost.com/install.
Open the terminal, and create a kubecost
namespace in your cluster.
$ kubectl create namespace kubecost
Add the official Kubecost helm repository.
$ helm repo add kubecost https://kubecost.github.io/cost-analyzer/
Run the install command. A standard Kubecost installation will also install the Prometheus and Grafana dependencies within the kubecost
namespace.
If you created the Azure Cost Export as directed in Module 0, follow A. With Azure Cost Export
, otherwise, follow B. Without Azure Cost Export
A. With Azure Cost Export
Replace {subscription-id}
, {storage-account-name}
, {storage-container-name}
, and {storage-access-key}
with the appropriate values
$ helm install kubecost kubecost/cost-analyzer --namespace kubecost --set kubecostProductConfigs.azureSubscriptionID={subscription-id} --set kubecostProductConfigs.azureStorageAccount={storage-account-name} --set kubecostProductConfigs.azureStorageAccessKey={storage-access-key} --set kubecostProductConfigs.azureStorageContainer={storage-container-name} --set kubecostProductConfigs.azureStorageCreateSecret=true
B. Without Azure Cost Export
$ helm install kubecost kubecost/cost-analyzer --namespace kubecost
This step will take a couple of minutes to complete. Once it’s done, verify that all the containers have been created and are running without issues:
$ kubectl get pods -n kubecost
You can expose the Kubecost UI dashboards locally using Port Forwarding.
Run the port-forward
command.
$ kubectl port-forward --namespace kubecost deployment/kubecost-cost-analyzer 9090
In your browser, open localhost:9090
to see the data. It should look like this:
One of the available options to open your Kubecost deployment to the world is by exposing port 9090 via Azure’s Load Balancer.
Create a file called kubecost-cost-analyzer.yml
with the following contents. This file is also available within this section’s files.
apiVersion: v1
kind: Service
metadata:
name: public-svc
spec:
type: LoadBalancer
ports:
- port: 9090
selector:
app: cost-analyzer
The app
should be the service name of the Kubecost app minus the kubecost-
prefic. You can view your services by running kubectl get services -n kubecost
.
Apply to cluster.
$ kubectl apply -f kubecost-cost-analyzer.yml -n kubecost
Verify that the public-svc
service has been created as a Load Balancer, exposing port 9090.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubecost-cost-analyzer ClusterIP 10.0.208.169 <none> 9001/TCP,9003/TCP,9090/TCP 1h
kubecost-grafana ClusterIP 10.0.181.47 <none> 80/TCP 1h
kubecost-kube-state-metrics ClusterIP 10.0.2.211 <none> 8080/TCP 1h
kubecost-prometheus-node-exporter ClusterIP None <none> 9100/TCP 1h
kubecost-prometheus-server ClusterIP 10.0.228.40 <none> 80/TCP 1h
public-svc LoadBalancer 10.0.104.222 20.85.139.189 9090:32660/TCP 1h
View Kubecost data by visiting the public-svc
address: http://<EXTERNAL-IP>:9090
Party time! 💃💃💃