123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- variable "k8s_dashboard_ver" {
- description = "Version of Kubernetes dashboard to deploy"
- type = string
- default = "1.10.1"
- }
- variable "minimal_role_name" {
- description = "Name of limited permissions role"
- type = string
- default = "kubernetes-dashboard-minimal"
- }
- variable "name" {
- description = "Name of deployed service"
- type = string
- default = "kubernetes-dashboard"
- }
- variable "app_name" {
- description = "Value of k8s-app label"
- type = string
- default = "kubernetes-dashboard"
- }
- variable "namespace" {
- description = "Target namespace to deploy"
- type = string
- default = "kube-system"
- }
- variable "revision_history_limit" {
- description = "Revision history limit"
- type = string
- default = "10"
- }
- variable "replicas" {
- description = "Number of replicas"
- type = string
- default = "1"
- }
- resource "kubernetes_secret" "dashboard" {
- metadata {
- name = "kubernetes-dashboard-certs"
- namespace = var.namespace
- labels = {
- k8s-app = var.app_name
- }
- }
- type = "Opaque"
- }
- resource "kubernetes_role" "dashboard-minimal" {
- metadata {
- name = var.minimal_role_name
- namespace = var.namespace
- }
- rule {
- api_groups = [""]
- resources = ["secrets"]
- verbs = ["create"]
- }
- rule {
- api_groups = [""]
- resources = ["configmaps"]
- verbs = ["create"]
- }
- rule {
- api_groups = [""]
- resource_names = ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"]
- resources = ["secrets"]
- verbs = ["get", "update", "delete"]
- }
- rule {
- api_groups = [""]
- resources = ["configmaps"]
- resource_names = ["kubernetes-dashboard-settings"]
- verbs = ["get", "update"]
- }
- rule {
- api_groups = [""]
- resources = ["services"]
- resource_names = ["heapster"]
- verbs = ["proxy"]
- }
- rule {
- api_groups = [""]
- resources = ["services/proxy"]
- resource_names = ["heapster", "http:heapster:", "https:heapster:"]
- verbs = ["get"]
- }
- }
- resource "kubernetes_cluster_role_binding" "dashboard" {
- metadata {
- name = var.name
- labels = {
- k8s-app = var.app_name
- }
- }
- role_ref {
- api_group = "rbac.authorization.k8s.io"
- kind = "ClusterRole"
- name = "cluster-admin"
- }
- subject {
- kind = "ServiceAccount"
- name = var.name
- namespace = var.namespace
- api_group = ""
- }
- }
- resource "kubernetes_service_account" "dashboard" {
- metadata {
- name = var.name
- namespace = var.namespace
- labels = {
- k8s-app = var.app_name
- }
- }
- }
- resource "kubernetes_role_binding" "dashboard" {
- metadata {
- name = var.minimal_role_name
- namespace = var.namespace
- }
- role_ref {
- api_group = "rbac.authorization.k8s.io"
- kind = "Role"
- name = var.minimal_role_name
- }
- subject {
- kind = "ServiceAccount"
- name = var.name
- namespace = var.namespace
- api_group = ""
- }
- }
- resource "kubernetes_deployment" "dashboard" {
- metadata {
- name = var.name
- namespace = var.namespace
- labels = {
- k8s-app = var.app_name
- }
- }
- spec {
- replicas = var.replicas
- revision_history_limit = var.revision_history_limit
- selector {
- match_labels = {
- k8s-app = var.app_name
- }
- }
- template {
- metadata {
- labels = {
- k8s-app = var.app_name
- }
- }
- spec {
- service_account_name = "kubernetes-dashboard"
- volume {
- name = "kubernetes-dashboard-certs"
- secret {
- secret_name = "kubernetes-dashboard-certs"
- }
- }
- volume {
- name = kubernetes_service_account.dashboard.default_secret_name
- secret {
- secret_name = kubernetes_service_account.dashboard.default_secret_name
- }
- }
- volume {
- name = "tmp-volume"
- empty_dir {}
- }
- container {
- name = "kubernetes-dashboard"
- args = ["--auto-generate-certificates", "--enable-skip-login"]
- image = "k8s.gcr.io/kubernetes-dashboard-amd64:v${var.k8s_dashboard_ver}"
- port {
- container_port = 8443
- protocol = "TCP"
- }
- resources {
- limits {
- cpu = "0.5"
- memory = "512Mi"
- }
- requests {
- cpu = "250m"
- memory = "50Mi"
- }
- }
- volume_mount {
- name = "kubernetes-dashboard-certs"
- mount_path = "/certs"
- }
- volume_mount {
- name = "tmp-volume"
- mount_path = "/tmp"
- }
- volume_mount {
- name = kubernetes_service_account.dashboard.default_secret_name
- read_only = true
- mount_path = "/var/run/secrets/kubernetes.io/serviceaccount"
- }
- }
- }
- }
- }
- }
- resource "kubernetes_service" "dashboard" {
- metadata {
- name = var.name
- namespace = var.namespace
- labels = {
- k8s-app = var.app_name
- }
- }
- spec {
- selector = {
- k8s-app = "kubernetes-dashboard"
- }
- port {
- port = 443
- target_port = 8443
- }
- }
- }
|