main.tf 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. resource "kubernetes_deployment" "browsh-ssh-server" {
  2. metadata {
  3. name = "browsh-ssh-server"
  4. }
  5. spec {
  6. replicas = 2
  7. selector {
  8. match_labels = {
  9. app = "browsh-ssh-server"
  10. }
  11. }
  12. template {
  13. metadata {
  14. labels = {
  15. app = "browsh-ssh-server"
  16. }
  17. }
  18. spec {
  19. container {
  20. image = "browsh/baas:v1.6.4"
  21. image_pull_policy = "Always"
  22. name = "app"
  23. port {
  24. container_port = 2222
  25. }
  26. volume_mount {
  27. name = "rw-config-ssh-key"
  28. mount_path = "/etc/browsh"
  29. }
  30. volume_mount {
  31. name = "rw-config-ssh-server-config"
  32. mount_path = "/app/.config/browsh/"
  33. }
  34. resources {
  35. requests {
  36. memory = "500Mi"
  37. cpu = "250m"
  38. }
  39. limits {
  40. memory = "2Gi"
  41. cpu = "2000m"
  42. }
  43. }
  44. }
  45. init_container {
  46. name = "fix-perms"
  47. image = "busybox"
  48. command = [
  49. "sh",
  50. "-c",
  51. "cp /etc/browsh-ro-ssh-key/id_rsa /etc/browsh && /bin/chmod 600 /etc/browsh/id_rsa && /bin/chown 1000 /etc/browsh/id_rsa && mkdir -p /app/.config/browsh/ && cp /etc/browsh-ro-config/config.toml /app/.config/browsh/ && /bin/chmod -R 777 /app/.config/browsh/"
  52. ]
  53. volume_mount {
  54. # The read-only mount of the k8s SSH secrets
  55. name = "browsh-ssh-rsa-key"
  56. mount_path = "/etc/browsh-ro-ssh-key"
  57. }
  58. volume_mount {
  59. # The read-only mount of the k8s config map for the Browsh config.toml
  60. name = "browsh-config"
  61. mount_path = "/etc/browsh-ro-config"
  62. }
  63. volume_mount {
  64. # The read-write helper mount to copy the SSH keys
  65. name = "rw-config-ssh-key"
  66. mount_path = "/etc/browsh"
  67. }
  68. volume_mount {
  69. # The read-write helper mount to copy the Browsh config.toml
  70. name = "rw-config-ssh-server-config"
  71. mount_path = "/app/.config/browsh/"
  72. }
  73. security_context {
  74. run_as_user = 0
  75. }
  76. }
  77. volume {
  78. name = "browsh-config"
  79. config_map {
  80. name = "browsh-ssh-server-config"
  81. }
  82. }
  83. volume {
  84. name = "rw-config-ssh-server-config"
  85. empty_dir {}
  86. }
  87. volume {
  88. name = "browsh-ssh-rsa-key"
  89. secret {
  90. secret_name = "browsh-ssh-rsa-key"
  91. items {
  92. key = "id_rsa_private_key"
  93. path = "id_rsa"
  94. }
  95. }
  96. }
  97. volume {
  98. name = "rw-config-ssh-key"
  99. empty_dir {}
  100. }
  101. }
  102. }
  103. }
  104. }
  105. resource "kubernetes_config_map" "browsh-ssh-server-config" {
  106. metadata {
  107. name = "browsh-ssh-server-config"
  108. }
  109. data = {
  110. "config.toml" = file("./ssh-server/config.toml")
  111. }
  112. }
  113. resource "kubernetes_horizontal_pod_autoscaler" "ssh-server-scaler" {
  114. metadata {
  115. name = "ssh-server-scaler"
  116. }
  117. spec {
  118. min_replicas = 1
  119. max_replicas = 10
  120. target_cpu_utilization_percentage = "80"
  121. scale_target_ref {
  122. kind = "Deployment"
  123. name = "browsh-ssh-server"
  124. }
  125. }
  126. }
  127. resource "kubernetes_secret" "browsh-ssh-rsa-key" {
  128. metadata {
  129. name = "browsh-ssh-rsa-key"
  130. }
  131. data = {
  132. id_rsa_private_key = file("etc/browsh_id_rsa")
  133. }
  134. }
  135. resource "kubernetes_service" "browsh-ssh-server" {
  136. metadata {
  137. name = "browsh-ssh-server"
  138. }
  139. spec {
  140. selector = {
  141. app = "browsh-ssh-server"
  142. }
  143. port {
  144. port = 22
  145. target_port = 2222
  146. }
  147. }
  148. }
  149. # TCP-specific load balancing rules
  150. resource "kubernetes_config_map" "nginx-ingress-tcp-config" {
  151. metadata {
  152. name = "nginx-ingress-tcp-conf"
  153. namespace = "ingress-nginx"
  154. labels = {
  155. "app.kubernetes.io/name" = "ingress-nginx"
  156. "app.kubernetes.io/part-of" = "ingress-nginx"
  157. }
  158. }
  159. data = {
  160. "22" = "default/browsh-ssh-server:22"
  161. }
  162. }