opencost.yaml 4.0 KB

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