| Giorgi Lekveishvili | 285ab62 | 2023-11-22 13:50:45 +0400 | [diff] [blame^] | 1 | # Running Gerrit on Kubernetes using Minikube |
| 2 | |
| 3 | To test Gerrit on Kubernetes locally, a one-node cluster can be set up using |
| 4 | Minikube. Minikube provides basic Kubernetes functionality and allows to quickly |
| 5 | deploy and evaluate a Kubernetes deployment. |
| 6 | This tutorial will guide through setting up Minikube to deploy the gerrit and |
| 7 | gerrit-replica helm charts to it. Note, that due to limited compute |
| 8 | resources on a single local machine and the restricted functionality of Minikube, |
| 9 | the full functionality of the charts might not be usable. |
| 10 | |
| 11 | ## Installing Kubectl and Minikube |
| 12 | |
| 13 | To use Minikube, a hypervisor is needed. A good non-commercial solution is HyperKit. |
| 14 | The Minikube project provides binaries to install the driver: |
| 15 | |
| 16 | ```sh |
| 17 | curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-hyperkit \ |
| 18 | && sudo install -o root -g wheel -m 4755 docker-machine-driver-hyperkit /usr/local/bin/ |
| 19 | ``` |
| 20 | |
| 21 | To manage Kubernetes clusters, the Kubectl CLI tool will be needed. A detailed |
| 22 | guide how to do that for all supported OSs can be found |
| 23 | [here](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-with-homebrew-on-macos). |
| 24 | On OSX hombrew can be used for installation: |
| 25 | |
| 26 | ```sh |
| 27 | brew install kubernetes-cli |
| 28 | ``` |
| 29 | |
| 30 | Finally, Minikube can be installed. Download the latest binary |
| 31 | [here](https://github.com/kubernetes/minikube/releases). To install it on OSX, run: |
| 32 | |
| 33 | ```sh |
| 34 | VERSION=1.1.0 |
| 35 | curl -Lo minikube https://storage.googleapis.com/minikube/releases/v$VERSION/minikube-darwin-amd64 && \ |
| 36 | chmod +x minikube && \ |
| 37 | sudo cp minikube /usr/local/bin/ && \ |
| 38 | rm minikube |
| 39 | ``` |
| 40 | |
| 41 | ## Starting a Minikube cluster |
| 42 | |
| 43 | For a more detailed overview over the features of Minikube refer to the |
| 44 | [official documentation](https://kubernetes.io/docs/setup/minikube/). If a |
| 45 | hypervisor driver other than virtual box (e.g. hyperkit) is used, set the |
| 46 | `--vm-driver` option accordingly: |
| 47 | |
| 48 | ```sh |
| 49 | minikube config set vm-driver hyperkit |
| 50 | ``` |
| 51 | |
| 52 | The gerrit and gerrit-replica charts are configured to work with the default |
| 53 | resource limits configured for minikube (2 cpus and 2Gi RAM). If more resources |
| 54 | are desired (e.g. to speed up deployment startup or for more resource intensive |
| 55 | tests), configure the resource limits using: |
| 56 | |
| 57 | ```sh |
| 58 | minikube config set memory 4096 |
| 59 | minikube config set cpus 4 |
| 60 | ``` |
| 61 | |
| 62 | To install a full Gerrit and Gerrit replica setup with reasonable startup |
| 63 | times, Minikube will need about 9.5 GB of RAM and 3-4 CPUs! But the more the |
| 64 | better. |
| 65 | |
| 66 | To start a Minikube cluster simply run: |
| 67 | |
| 68 | ```sh |
| 69 | minikube start |
| 70 | ``` |
| 71 | |
| 72 | Starting up the cluster will take a while. The installation should automatically |
| 73 | configure kubectl to connect to the Minikube cluster. Run the following command |
| 74 | to test whether the cluster is up: |
| 75 | |
| 76 | ```sh |
| 77 | kubectl get nodes |
| 78 | |
| 79 | NAME STATUS ROLES AGE VERSION |
| 80 | minikube Ready master 1h v1.14.2 |
| 81 | ``` |
| 82 | |
| 83 | The helm-charts use ingresses, which can be used in Minikube by enabling the |
| 84 | ingress addon: |
| 85 | |
| 86 | ```sh |
| 87 | minikube addons enable ingress |
| 88 | ``` |
| 89 | |
| 90 | Since for testing there will probably no usable host names configured to point |
| 91 | to the minikube installation, the traffic to the hostnames configured in the |
| 92 | Ingress definition needs to be redirected to Minikube by editing the `/etc/hosts`- |
| 93 | file, adding a line containing the Minikube IP and a whitespace-delimited list |
| 94 | of all the hostnames: |
| 95 | |
| 96 | ```sh |
| 97 | echo "$(minikube ip) primary.gerrit backend.gerrit replica.gerrit" | sudo tee -a /etc/hosts |
| 98 | ``` |
| 99 | |
| 100 | The host names (e.g. `primary.gerrit`) are the defaults, when using the values.yaml |
| 101 | files provided as and example for minikube. Change them accordingly, if a different |
| 102 | one is chosen. |
| 103 | This will only redirect traffic from the computer running Minikube. |
| 104 | |
| 105 | To see whether all cluster components are ready, run: |
| 106 | |
| 107 | ```sh |
| 108 | kubectl get pods --all-namespaces |
| 109 | ``` |
| 110 | |
| 111 | The status of all components should be `Ready`. The kubernetes dashboard giving |
| 112 | an overview over all cluster components, can be opened by executing: |
| 113 | |
| 114 | ```sh |
| 115 | minikube dashboard |
| 116 | ``` |
| 117 | |
| 118 | ## Install helm |
| 119 | |
| 120 | Helm is needed to install and manage the helm charts. To install the helm client |
| 121 | on your local machine (running OSX), run: |
| 122 | |
| 123 | ```sh |
| 124 | brew install kubernetes-helm |
| 125 | ``` |
| 126 | |
| 127 | A guide for all suported OSs can be found [here](https://docs.helm.sh/using_helm/#installing-helm). |
| 128 | |
| 129 | ## Start an NFS-server |
| 130 | |
| 131 | The helm-charts need a volume with ReadWriteMany access mode to store |
| 132 | git-repositories. This guide will use the nfs-server-provisioner chart to provide |
| 133 | NFS-volumes directly in the cluster. A basic configuration file for the nfs-server- |
| 134 | provisioner-chart is provided in the supplements-directory. It can be installed |
| 135 | by running: |
| 136 | |
| 137 | ```sh |
| 138 | helm install nfs \ |
| 139 | stable/nfs-server-provisioner \ |
| 140 | -f ./supplements/nfs.minikube.values.yaml |
| 141 | ``` |
| 142 | |
| 143 | ## Installing the gerrit helm chart |
| 144 | |
| 145 | A configuration file to configure the gerrit chart is provided at |
| 146 | `./supplements/gerrit.minikube.values.yaml`. To install the gerrit |
| 147 | chart on Minikube, run: |
| 148 | |
| 149 | ```sh |
| 150 | helm install gerrit \ |
| 151 | ./helm-charts/gerrit \ |
| 152 | -f ./supplements/gerrit.minikube.values.yaml |
| 153 | ``` |
| 154 | |
| 155 | Startup may take some time, especially when allowing only a small amount of |
| 156 | resources to the containers. Check progress with `kubectl get pods -w` until |
| 157 | it says that the pod `gerrit-gerrit-stateful-set-0` is `Running`. |
| 158 | Then use `kubectl logs -f gerrit-gerrit-stateful-set-0` to follow |
| 159 | the startup process of Gerrit until a line like this shows that Gerrit is ready: |
| 160 | |
| 161 | ```sh |
| 162 | [2019-06-04 15:24:25,914] [main] INFO com.google.gerrit.pgm.Daemon : Gerrit Code Review 2.16.8-86-ga831ebe687 ready |
| 163 | ``` |
| 164 | |
| 165 | To open Gerrit's UI, run: |
| 166 | |
| 167 | ```sh |
| 168 | open http://primary.gerrit |
| 169 | ``` |
| 170 | |
| 171 | ## Installing the gerrit-replica helm chart |
| 172 | |
| 173 | A custom configuration file to configure the gerrit-replica chart is provided at |
| 174 | `./supplements/gerrit-replica.minikube.values.yaml`. Install it by running: |
| 175 | |
| 176 | ```sh |
| 177 | helm install gerrit-replica \ |
| 178 | ./helm-charts/gerrit-replica \ |
| 179 | -f ./supplements/gerrit-replica.minikube.values.yaml |
| 180 | ``` |
| 181 | |
| 182 | The replica will start up, which can be followed by running: |
| 183 | |
| 184 | ```sh |
| 185 | kubectl logs -f gerrit-replica-gerrit-replica-deployment-<id> |
| 186 | ``` |
| 187 | |
| 188 | Replication of repositories has to be started on the Gerrit, e.g. by making |
| 189 | a change in the respective repositories. Only then previous changes to the |
| 190 | repositories will be available on the replica. |
| 191 | |
| 192 | ## Cleanup |
| 193 | |
| 194 | Shut down minikube: |
| 195 | |
| 196 | ```sh |
| 197 | minikube stop |
| 198 | ``` |
| 199 | |
| 200 | Delete the minikube cluster: |
| 201 | |
| 202 | ```sh |
| 203 | minikube delete |
| 204 | ``` |
| 205 | |
| 206 | Remove the line added to `/etc/hosts`. If Minikube is restarted, the cluster will |
| 207 | get a new IP and the `/etc/hosts`-entry has to be adjusted. |