opencost.yaml 4.3 KB

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