opencost-exporter.yaml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. ---
  2. # The namespace opencost will run in
  3. apiVersion: v1
  4. kind: Namespace
  5. metadata:
  6. name: opencost-exporter
  7. ---
  8. # Service account for permissions
  9. apiVersion: v1
  10. kind: ServiceAccount
  11. metadata:
  12. name: opencost
  13. ---
  14. # Cluster role giving opencost to get, list, watch required resources
  15. # No write permissions are required
  16. apiVersion: rbac.authorization.k8s.io/v1
  17. kind: ClusterRole
  18. metadata:
  19. name: opencost
  20. rules:
  21. - apiGroups:
  22. - ''
  23. resources:
  24. - configmaps
  25. - deployments
  26. - nodes
  27. - pods
  28. - services
  29. - resourcequotas
  30. - replicationcontrollers
  31. - limitranges
  32. - persistentvolumeclaims
  33. - persistentvolumes
  34. - namespaces
  35. - endpoints
  36. verbs:
  37. - get
  38. - list
  39. - watch
  40. - apiGroups:
  41. - extensions
  42. resources:
  43. - daemonsets
  44. - deployments
  45. - replicasets
  46. verbs:
  47. - get
  48. - list
  49. - watch
  50. - apiGroups:
  51. - apps
  52. resources:
  53. - statefulsets
  54. - deployments
  55. - daemonsets
  56. - replicasets
  57. verbs:
  58. - list
  59. - watch
  60. - apiGroups:
  61. - batch
  62. resources:
  63. - cronjobs
  64. - jobs
  65. verbs:
  66. - get
  67. - list
  68. - watch
  69. - apiGroups:
  70. - autoscaling
  71. resources:
  72. - horizontalpodautoscalers
  73. verbs:
  74. - get
  75. - list
  76. - watch
  77. - apiGroups:
  78. - policy
  79. resources:
  80. - poddisruptionbudgets
  81. verbs:
  82. - get
  83. - list
  84. - watch
  85. - apiGroups:
  86. - storage.k8s.io
  87. resources:
  88. - storageclasses
  89. verbs:
  90. - get
  91. - list
  92. - watch
  93. ---
  94. # Bind the role to the service account
  95. apiVersion: rbac.authorization.k8s.io/v1
  96. kind: ClusterRoleBinding
  97. metadata:
  98. name: opencost
  99. roleRef:
  100. apiGroup: rbac.authorization.k8s.io
  101. kind: ClusterRole
  102. name: opencost
  103. subjects:
  104. - kind: ServiceAccount
  105. name: opencost
  106. namespace: opencost-exporter
  107. ---
  108. # Create a deployment for a single cost model pod
  109. #
  110. # See environment variables if you would like to add a Prometheus for
  111. # cost model to read from for full functionality.
  112. apiVersion: apps/v1
  113. kind: Deployment
  114. metadata:
  115. name: opencost
  116. labels:
  117. app: opencost
  118. spec:
  119. replicas: 1
  120. selector:
  121. matchLabels:
  122. app: opencost
  123. strategy:
  124. rollingUpdate:
  125. maxSurge: 1
  126. maxUnavailable: 1
  127. type: RollingUpdate
  128. template:
  129. metadata:
  130. labels:
  131. app: opencost
  132. spec:
  133. restartPolicy: Always
  134. serviceAccountName: opencost
  135. containers:
  136. - image: quay.io/kubecost1/kubecost-cost-model:latest
  137. name: opencost
  138. resources:
  139. requests:
  140. cpu: "10m"
  141. memory: "55M"
  142. limits:
  143. cpu: "999m"
  144. memory: "1G"
  145. env:
  146. - name: PROMETHEUS_SERVER_ENDPOINT
  147. value: "http://prometheus-server.prometheus-system.svc" # The endpoint should have the form http://<service-name>.<namespace-name>.svc
  148. - name: CLOUD_PROVIDER_API_KEY
  149. value: "AIzaSyD29bGxmHAVEOBYtgd8sYM2gM2ekfxQX4U" # The GCP Pricing API requires a key. This is supplied just for evaluation.
  150. - name: CLUSTER_ID
  151. value: "cluster-one" # Default cluster ID to use if cluster_id is not set in Prometheus metrics.
  152. - name: EXPORT_CSV_FILE
  153. value: "s3://path/to/csv"
  154. - name: AWS_ACCESS_KEY_ID
  155. value: "XXXXXXXXXXXXXXX" ## AWS Access KeyID
  156. - name: AWS_SECRET_ACCESS_KEY
  157. value: "XXXXXXXXXXXXXXX" ## AWS Secret Access Key
  158. - name: AWS_REGION
  159. value: "us-west-2" ## AWS Region where bucket is hosted
  160. imagePullPolicy: Always
  161. volumeMounts:
  162. - name: tmp-volume
  163. mountPath: /tmp
  164. volumes:
  165. - name: tmp-volume
  166. emptyDir: {}
  167. ---
  168. # Expose the cost model with a service
  169. #
  170. # Without a Prometheus endpoint configured in the deployment,
  171. # only opencost/metrics will have useful data as it is intended
  172. # to be used as just an exporter.
  173. kind: Service
  174. apiVersion: v1
  175. metadata:
  176. name: opencost
  177. spec:
  178. selector:
  179. app: opencost
  180. type: ClusterIP
  181. ports:
  182. - name: opencost
  183. port: 9003
  184. targetPort: 9003
  185. ---