index.adoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. = Solution: Kubernetes Control Panel (Hosted)
  2. This solution gives you quick and easy buttons to run kubectl commands, when OliveTin is running on top of Kubernetes (this means OliveTin is "hosted" by Kubernetes). This can be very easy for quick debugging purposes when you cannot type (eg from a mobile phone), or to give junior sysadmins access to do basic predefined tasks.
  3. This use case is enabled by simply providing the OliveTin pod access to talk to the kubernetes API, and using `kubectl` which is preinstalled with modern versions of OliveTin.
  4. image::solutions/k8s-control-panel-hosted/preview.png[]
  5. == Requirements & Assumptions
  6. === Time & skills
  7. * This should take approximately **10 minutes** to configure if you are comfortable in using Kubernetes - using helm, kubectl, and editing basic YAML.
  8. === Environment
  9. * A Kubernetes cluster that is up and running.
  10. * Kubernetes permissions to create a helm deployment, a `ClusterRole` and `ClusterRoleBinding`.
  11. * A configured Ingress Controller, exposing the for web interface
  12. === System
  13. * Approximately 128m RAM, 1vCPU to run the OliveTin pod.
  14. == Install OliveTin on top of Kubernetes
  15. * xref:install/helm.adoc[Install OliveTin on Kubernetes with Helm] (recommended)
  16. * xref:install/k8s.adoc[Install OliveTin on Kubernetes with Manifests]
  17. == Grant permissions to API
  18. OliveTin needs a `ClusterRole` that allow it to access resources on your Kubernetes cluster. This is because by default, pods can communicate to the API using the credentials mounted in the pod by the default `ServiceAccount`, but they don't have any permissions. This `ClusterRole` is being created to give permissions to the `ServiceAccount`. Create the `ClusterRole` like follows;
  19. [tabs]
  20. ====
  21. kubectl cli::
  22. +
  23. --
  24. [source,shell]
  25. ----
  26. user@host: kubectl create clusterrole --resource=pods --verb=get,list,watch olivetin-k8s-permissions
  27. ----
  28. --
  29. manifest::
  30. +
  31. --
  32. [source,yaml]
  33. ----
  34. kind: ClusterRole
  35. apiVersion: rbac.authorization.k8s.io/v1
  36. metadata:
  37. name: olivetin-k8s-permissions
  38. rules:
  39. - apiGroups: [""]
  40. resources: ["pods"]
  41. verbs: ["get", "list", "watch"]
  42. ----
  43. --
  44. ====
  45. Now that the `ClusterRole` has been created, we need to associate it to a `ServiceAccount` with a `ClusterRoleBinding`.
  46. Create a cluster role binding;
  47. [tabs]
  48. ====
  49. kubectl cli::
  50. +
  51. --
  52. [source,shell]
  53. ----
  54. user@host: kubectl create clusterrolebinding --clusterrole=olivetin-k8s-permissions --serviceaccount myolivetinnamespace:default --namespace myolivetinnamespace olivetin-crb
  55. ----
  56. --
  57. ====
  58. == Build a simple kubernetes control planel
  59. Add `kubectl` job to OliveTin config with `kubectl edit cm/olivetin-config -n olivetin`;
  60. [source,yaml]
  61. ----
  62. apiVersion: v1
  63. data:
  64. config.yaml: |
  65. defaultOnClick: execution-dialog-output-only
  66. actions:
  67. - title: get pods
  68. icon: <iconify-icon icon="pajamas:pod"></iconify-icon>
  69. shell: kubectl get pods
  70. - title: restart postgres deployment
  71. icon: <iconify-icon icon="pajamas:clear-all"></iconify-icon>
  72. shell: kubectl rollout restart deployment postgres
  73. - title: evacuate node
  74. icon: <iconify-icon icon="pajamas:rocket-launch"></iconify-icon>
  75. shell: kubectl drain {{ NodeName }} --ignore-daemonsets --delete-emptydir-data
  76. arguments:
  77. - name: NodeName
  78. choices:
  79. - value: node1
  80. - value: node2
  81. - value: node3
  82. kind: ConfigMap
  83. metadata:
  84. annotations:
  85. meta.helm.sh/release-name: olivetin
  86. meta.helm.sh/release-namespace: default
  87. labels:
  88. app.kubernetes.io/managed-by: Helm
  89. name: olivetin-config
  90. namespace: default
  91. ----
  92. Don't forget to restart the OliveTin deployment as good measure, because Kubernetes can be slow to update configmaps.