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