dashboard.tf 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. variable "k8s_dashboard_ver" {
  2. description = "Version of Kubernetes dashboard to deploy"
  3. type = string
  4. default = "1.10.1"
  5. }
  6. variable "minimal_role_name" {
  7. description = "Name of limited permissions role"
  8. type = string
  9. default = "kubernetes-dashboard-minimal"
  10. }
  11. variable "name" {
  12. description = "Name of deployed service"
  13. type = string
  14. default = "kubernetes-dashboard"
  15. }
  16. variable "app_name" {
  17. description = "Value of k8s-app label"
  18. type = string
  19. default = "kubernetes-dashboard"
  20. }
  21. variable "namespace" {
  22. description = "Target namespace to deploy"
  23. type = string
  24. default = "kube-system"
  25. }
  26. variable "revision_history_limit" {
  27. description = "Revision history limit"
  28. type = string
  29. default = "10"
  30. }
  31. variable "replicas" {
  32. description = "Number of replicas"
  33. type = string
  34. default = "1"
  35. }
  36. resource "kubernetes_secret" "dashboard" {
  37. metadata {
  38. name = "kubernetes-dashboard-certs"
  39. namespace = var.namespace
  40. labels = {
  41. k8s-app = var.app_name
  42. }
  43. }
  44. type = "Opaque"
  45. }
  46. resource "kubernetes_role" "dashboard-minimal" {
  47. metadata {
  48. name = var.minimal_role_name
  49. namespace = var.namespace
  50. }
  51. rule {
  52. api_groups = [""]
  53. resources = ["secrets"]
  54. verbs = ["create"]
  55. }
  56. rule {
  57. api_groups = [""]
  58. resources = ["configmaps"]
  59. verbs = ["create"]
  60. }
  61. rule {
  62. api_groups = [""]
  63. resource_names = ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"]
  64. resources = ["secrets"]
  65. verbs = ["get", "update", "delete"]
  66. }
  67. rule {
  68. api_groups = [""]
  69. resources = ["configmaps"]
  70. resource_names = ["kubernetes-dashboard-settings"]
  71. verbs = ["get", "update"]
  72. }
  73. rule {
  74. api_groups = [""]
  75. resources = ["services"]
  76. resource_names = ["heapster"]
  77. verbs = ["proxy"]
  78. }
  79. rule {
  80. api_groups = [""]
  81. resources = ["services/proxy"]
  82. resource_names = ["heapster", "http:heapster:", "https:heapster:"]
  83. verbs = ["get"]
  84. }
  85. }
  86. resource "kubernetes_cluster_role_binding" "dashboard" {
  87. metadata {
  88. name = var.name
  89. labels = {
  90. k8s-app = var.app_name
  91. }
  92. }
  93. role_ref {
  94. api_group = "rbac.authorization.k8s.io"
  95. kind = "ClusterRole"
  96. name = "cluster-admin"
  97. }
  98. subject {
  99. kind = "ServiceAccount"
  100. name = var.name
  101. namespace = var.namespace
  102. api_group = ""
  103. }
  104. }
  105. resource "kubernetes_service_account" "dashboard" {
  106. metadata {
  107. name = var.name
  108. namespace = var.namespace
  109. labels = {
  110. k8s-app = var.app_name
  111. }
  112. }
  113. }
  114. resource "kubernetes_role_binding" "dashboard" {
  115. metadata {
  116. name = var.minimal_role_name
  117. namespace = var.namespace
  118. }
  119. role_ref {
  120. api_group = "rbac.authorization.k8s.io"
  121. kind = "Role"
  122. name = var.minimal_role_name
  123. }
  124. subject {
  125. kind = "ServiceAccount"
  126. name = var.name
  127. namespace = var.namespace
  128. api_group = ""
  129. }
  130. }
  131. resource "kubernetes_deployment" "dashboard" {
  132. metadata {
  133. name = var.name
  134. namespace = var.namespace
  135. labels = {
  136. k8s-app = var.app_name
  137. }
  138. }
  139. spec {
  140. replicas = var.replicas
  141. revision_history_limit = var.revision_history_limit
  142. selector {
  143. match_labels = {
  144. k8s-app = var.app_name
  145. }
  146. }
  147. template {
  148. metadata {
  149. labels = {
  150. k8s-app = var.app_name
  151. }
  152. }
  153. spec {
  154. service_account_name = "kubernetes-dashboard"
  155. volume {
  156. name = "kubernetes-dashboard-certs"
  157. secret {
  158. secret_name = "kubernetes-dashboard-certs"
  159. }
  160. }
  161. volume {
  162. name = kubernetes_service_account.dashboard.default_secret_name
  163. secret {
  164. secret_name = kubernetes_service_account.dashboard.default_secret_name
  165. }
  166. }
  167. volume {
  168. name = "tmp-volume"
  169. empty_dir {}
  170. }
  171. container {
  172. name = "kubernetes-dashboard"
  173. args = ["--auto-generate-certificates", "--enable-skip-login"]
  174. image = "k8s.gcr.io/kubernetes-dashboard-amd64:v${var.k8s_dashboard_ver}"
  175. port {
  176. container_port = 8443
  177. protocol = "TCP"
  178. }
  179. resources {
  180. limits {
  181. cpu = "0.5"
  182. memory = "512Mi"
  183. }
  184. requests {
  185. cpu = "250m"
  186. memory = "50Mi"
  187. }
  188. }
  189. volume_mount {
  190. name = "kubernetes-dashboard-certs"
  191. mount_path = "/certs"
  192. }
  193. volume_mount {
  194. name = "tmp-volume"
  195. mount_path = "/tmp"
  196. }
  197. volume_mount {
  198. name = kubernetes_service_account.dashboard.default_secret_name
  199. read_only = true
  200. mount_path = "/var/run/secrets/kubernetes.io/serviceaccount"
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. resource "kubernetes_service" "dashboard" {
  208. metadata {
  209. name = var.name
  210. namespace = var.namespace
  211. labels = {
  212. k8s-app = var.app_name
  213. }
  214. }
  215. spec {
  216. selector = {
  217. k8s-app = "kubernetes-dashboard"
  218. }
  219. port {
  220. port = 443
  221. target_port = 8443
  222. }
  223. }
  224. }