Blame mbbox/README.md

Michal Konečný 1a4352
# MBBox deployment guide
Michal Konečný 1a4352
4275c9
## Introduction
Michal Konečný 1a4352
Michal Konečný 1a4352
This guide will describe the deployment of [MBBox](https://github.com/fedora-infra/mbbox) operator in OpenShift 4 cluster and it's prerequisites.
Michal Konečný 1a4352
4275c9
MBBox upstream documentation can be found at: https://mbbox-operator.readthedocs.io/en/latest/.
Michal Konečný 1a4352
4275c9
The MBBox operator has kubernetes custom resources to deploy the following components:
4275c9
4275c9
* koji-hub (includes koji-web)
4275c9
* koji-builder
4275c9
* kojira
4275c9
* MBS Backend
4275c9
* MBS Frontend
4275c9
4275c9
## Dependencies
4275c9
4275c9
MBBox depends on two components/services to be already deployed/available:
4275c9
4275c9
* PostgreSQL (>= 10.4)
4275c9
* Fedora Messaging
4275c9
4275c9
The operator does not deploy the above components but needs two secrets, one for each component, in the same namespace custom resources (koji, koji-builder, etc) are being created.
4275c9
4275c9
### PostgreSQL
4275c9
4275c9
Secret format (all `data` values need to be base64 encoded):
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: postgres
4275c9
  labels:
4275c9
    app: postgres
4275c9
data:
4275c9
  POSTGRES_HOST: cG9zdGdyZXNxbA== # postgresql
4275c9
  POSTGRES_DB: bWJveGRi # mboxdb
4275c9
  POSTGRES_USER: a29qaQ== # koji
4275c9
  POSTGRES_PASSWORD: bWJveA== # mbox
4275c9
```
4275c9
4275c9
Creating the secret from the command line:
4275c9
4275c9
```
4275c9
oc create secret generic postgres \
4275c9
--from-literal=POSTGRES_HOST=postgresql \
4275c9
--from-literal=POSTGRES_DB=mboxdb \
4275c9
--from-literal=POSTGRES_USER=koji \
4275c9
--from-literal=POSTGRES_PASSWORD=mbox
4275c9
```
4275c9
4275c9
### Fedora Messaging
4275c9
4275c9
Secret format (all `data` values need to be base64 encoded):
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: koji-hub-msg
4275c9
data:
4275c9
  koji.ca: |-
4275c9
    Y2hhbmdlbWU=
4275c9
  koji.crt: |-
4275c9
    Y2hhbmdlbWU=
4275c9
  koji.key: |-
4275c9
    Y2hhbmdlbWU=
4275c9
```
4275c9
4275c9
The secret can also be created from the command line:
4275c9
4275c9
```
4275c9
oc create secret generic koji-hub-msg \
4275c9
--from-file=koji.ca=/path/to/ca.pem \
4275c9
--from-file=koji.crt=/path/to/cert.pem \
4275c9
--from-file=koji.key=/path/to/key.pem
4275c9
```
4275c9
4275c9
All certificates must be in PEM format.
4275c9
4275c9
### Storage
4275c9
4275c9
**NOTE:** this section describes how to deal with Openshift Persistent Volumes if the cluster being used is not using any storage provisioning operator which may require extra PV setup from the cluster admin.
Michal Konečný 1a4352
Michal Konečný 1a4352
The MBBox needs several Persistent Volumes created in prior to deployment:
Michal Konečný 1a4352
Michal Konečný 1a4352
* mbox-registry (Recommended: 100 Gi) - Used as image registry
4275c9
* httpd (Minimum: 1Gi) - Used by koji-hub httpd server
4275c9
* koji (Minimum: 50Gi) - Used for shared koji space
4275c9
* postgres (Minimum: 5Gi) - Used by postgreSQL database
4275c9
4275c9
#### Persistent Volumes
4275c9
4275c9
##### ClaimRef
4275c9
4275c9
ClaimRef should be set in created Persistent Volumes (PVs) if no storage class is set in the cluster scope:
4275c9
4275c9
```yaml
4275c9
kind: PersistentVolume
4275c9
apiVersion: v1
4275c9
metadata:
4275c9
  annotations:
4275c9
    pv.kubernetes.io/bound-by-controller: 'yes'
4275c9
  selfLink: /api/v1/persistentvolumes/stg-postgres
4275c9
  resourceVersion: '39237794'
4275c9
  name: stg-postgres
4275c9
  uid: d0e3960e-af9e-45af-8f87-ac03def7b8a5
4275c9
  creationTimestamp: '2020-11-23T01:01:35Z'
4275c9
...
4275c9
spec:
4275c9
  capacity:
4275c9
    storage: 5Gi
4275c9
  claimRef:
4275c9
    apiVersion: v1 
4275c9
    kind: PersistentVolumeClaim
4275c9
    namespace: mbox # pvc namespace
4275c9
    name: postgres # pvc name to bound to
4275c9
  persistentVolumeReclaimPolicy: Retain
4275c9
  storageClassName: slow
4275c9
  volumeMode: Filesystem
4275c9
  ...
4275c9
```
4275c9
4275c9
Both `uid` and `resourceVersion` will need to be removed from the `claimRef` property if the PV needs to be rebound to another PVC:
4275c9
4275c9
```yaml
4275c9
claimRef:
4275c9
    apiVersion: v1 
4275c9
    kind: PersistentVolumeClaim
4275c9
    namespace: mbox-stg # new namesapce
4275c9
    name: postgres-stg # new pvc name
4275c9
    uid: 775c0823-47c1-46a2-b07c-612d59592430 # remove this
4275c9
    resourceVersion: '39235159' #remove this
4275c9
```
4275c9
4275c9
Both PVC and PV should have a `bound` status after a few seconds.
4275c9
4275c9
A note on volumes: recently created volumes may need a permission change the volume itself, the oficial openshift docs has a page dedicated to this problem and how to fix it: https://access.redhat.com/solutions/3508731
4275c9
4275c9
4275c9
## Deployment
4275c9
4275c9
There are three flavors of deployment:
4275c9
4275c9
* Development
4275c9
* Production: Root CA Only
4275c9
* Production: All Certificates
4275c9
4275c9
What differs each deployment flavor is the amount of required steps before the actual deployment process.
4275c9
4275c9
You can follow the upstream documentation once those preparation steps are done: https://mbbox-operator.readthedocs.io/en/latest/deployment-guide.html
4275c9
4275c9
### Development
4275c9
4275c9
Ideal for running MBBox locally and automated tests.
4275c9
4275c9
The only requirement is a running openshift cluster with admin access.
4275c9
4275c9
All certificates, incluing the Root CA will be self signed using openssl.
4275c9
4275c9
### Production: Root CA Only
4275c9
4275c9
This deployment path requires an openshift secret in the same namespace other components will be created, such as koji.
4275c9
4275c9
This secret should contain a root CA certificate and private key, this way the operator will create and sign all required certificates from this root CA instead of using a self signed one.
4275c9
4275c9
Secret format:
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: koji-hub-ca-cert
4275c9
  labels:
4275c9
    app: koji-hub
4275c9
data:
4275c9
  cert: -|
4275c9
    cert_in_base64_format
4275c9
  key: -|
4275c9
    key_in_base64_format
4275c9
```
4275c9
4275c9
You may also create it from the command line:
4275c9
4275c9
```sh
4275c9
oc create secret generic koji-hub-ca-cert \
4275c9
--from-file=cert=/ca.pem \
4275c9
--from-file=key=/key.pem
4275c9
```
4275c9
4275c9
You may then proceed in deployment MBBox.
4275c9
4275c9
### Production: All Certificates
4275c9
4275c9
Similar to the previous section but it needs all certificates and keys to be manually created.
4275c9
4275c9
#### [Koji-Hub] Root CA Secret
4275c9
4275c9
The root certifcate which all other certificates were generated/signed from.
4275c9
4275c9
We only need the certificate in this case.
4275c9
4275c9
Secret format:
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: koji-hub-ca-cert
4275c9
  labels:
4275c9
    app: koji-hub
4275c9
data:
4275c9
  cert: -|
4275c9
    cert_in_base64_format
4275c9
```
4275c9
4275c9
You may also create it from the command line:
4275c9
4275c9
```sh
4275c9
oc create secret generic koji-hub-ca-cert \
4275c9
--from-file=cert=/ca.pem
4275c9
```
4275c9
4275c9
#### [Koji-Hub] HTTPD Secret
4275c9
4275c9
Apache HTTPD certificate and private key.
4275c9
4275c9
**NOTES:**
4275c9
4275c9
* The certificate CN field must use the same value as the public hostname for koji;
4275c9
* The following subject altnames must be used:
4275c9
    * DNS:$KOJI_PUBLIC_HOSTNAME
4275c9
    * DNS:koji-hub
4275c9
    * DNS:koji-hub.$OPENSHIFT_NAMESPACE.svc
4275c9
    * DNS:koji-hub.$OPENSHIFT_NAMESPACE.svc.cluster
4275c9
4275c9
Secret format:
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: koji-hub-service-cert
4275c9
  labels:
4275c9
    app: koji-hub
4275c9
data:
4275c9
  tls.crt: -|
4275c9
    cert_in_base64_format
4275c9
  tls.key: -|
4275c9
    key_in_base64_format
4275c9
```
4275c9
4275c9
You may also create it from the command line:
4275c9
4275c9
```sh
4275c9
oc create secret generic koji-hub-service-cert \
4275c9
--from-file=cert=/cert.pem \
4275c9
--from-file=key=/key.pem
4275c9
```
4275c9
4275c9
#### [Koji-Hub] Web Client Secret
4275c9
4275c9
Koji-Web client secret for koji-hub API authentication.
4275c9
4275c9
**NOTES:**
4275c9
4275c9
* The `client.pem` file must contain BOTH private key and certificate;
4275c9
* The certificate `CN` field must use the same value used in `web_client_username`
4275c9
4275c9
Secret format:
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: koji-hub-web-client-cert
4275c9
  labels:
4275c9
    app: koji-hub
4275c9
data:
4275c9
  client.pem: -|
4275c9
    key_and_cert_in_base64_format
4275c9
```
4275c9
4275c9
You may also create it from the command line:
4275c9
4275c9
```sh
4275c9
oc create secret generic koji-hub-web-client-cert \
4275c9
--from-file=client.pem=/key_and_cert.pem
4275c9
```
4275c9
4275c9
#### [Koji-Hub] Admin Client Secret
4275c9
4275c9
Koji-Hub admin client secret for koji-hub API authentication.
4275c9
4275c9
This certificate is used in several admin level operations by the operator.
4275c9
4275c9
**NOTES:**
4275c9
4275c9
* The `client.pem` file must contain BOTH private key and certificate;
4275c9
* The certificate `CN` field must use the same value used in `admin_username`
4275c9
4275c9
Secret format:
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: koji-hub-admin-cert
4275c9
  labels:
4275c9
    app: koji-hub
4275c9
data:
4275c9
  client.pem: -|
4275c9
    key_and_cert_in_base64_format
4275c9
```
4275c9
4275c9
You may also create it from the command line:
4275c9
4275c9
```sh
4275c9
oc create secret generic koji-hub-admin-cert \
4275c9
--from-file=client.pem=/key_and_cert.pem
4275c9
```
4275c9
4275c9
#### [Koji-Builder] Client Secret
4275c9
4275c9
Koji-Builder client secret for koji-hub API authentication.
4275c9
4275c9
**NOTES:**
4275c9
4275c9
* The `client.pem` file must contain BOTH private key and certificate;
4275c9
* The certificate `CN` field must use the same value used in `host_name`
4275c9
4275c9
Secret format:
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: koji-builder-client-cert
4275c9
  labels:
4275c9
    app: koji-builder
4275c9
data:
4275c9
  client.pem: -|
4275c9
    key_and_cert_in_base64_format
4275c9
```
4275c9
4275c9
You may also create it from the command line:
4275c9
4275c9
```sh
4275c9
oc create secret generic koji-builder-client-cert \
4275c9
--from-file=client.pem=/key_and_cert.pem
4275c9
```
4275c9
4275c9
#### [Kojira] Client Secret
4275c9
4275c9
Kojira client secret for koji-hub API authentication.
4275c9
4275c9
**NOTES:**
4275c9
4275c9
* The `client.pem` file must contain BOTH private key and certificate;
4275c9
* The certificate `CN` field must use the same value used in `hub_username`
4275c9
4275c9
Secret format:
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: kojira-client-cert
4275c9
  labels:
4275c9
    app: kojira
4275c9
data:
4275c9
  client.pem: -|
4275c9
    key_and_cert_in_base64_format
4275c9
```
4275c9
4275c9
You may also create it from the command line:
4275c9
4275c9
```sh
4275c9
oc create secret generic kojira-client-cert \
4275c9
--from-file=client.pem=/key_and_cert.pem
4275c9
```
4275c9
4275c9
#### [MBS-Backend] Client Secret
4275c9
4275c9
MBS Backend client secret for koji-hub API authentication.
4275c9
4275c9
**NOTES:**
4275c9
4275c9
* The `client.pem` file must contain BOTH private key and certificate;
4275c9
* The certificate `CN` field must use the same value used in `hub_username`
4275c9
4275c9
Secret format:
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: mbs-client-cert
4275c9
  labels:
4275c9
    app: mbs-backend
4275c9
data:
4275c9
  client.pem: -|
4275c9
    key_and_cert_in_base64_format
4275c9
```
4275c9
4275c9
You may also create it from the command line:
4275c9
4275c9
```sh
4275c9
oc create secret generic mbs-client-cert \
4275c9
--from-file=client.pem=/key_and_cert.pem
4275c9
```
4275c9
4275c9
#### [MBS-Frontend] Client Secret
4275c9
4275c9
MBS Frontend client secret for koji-hub API authentication.
4275c9
4275c9
**NOTES:**
4275c9
4275c9
* The `client.pem` file must contain BOTH private key and certificate;
4275c9
* The certificate `CN` field must use the same value used in `hub_username`
4275c9
4275c9
Secret format:
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: mbs-frontend-client-cert
4275c9
  labels:
4275c9
    app: mbs-frontend
4275c9
data:
4275c9
  client.pem: -|
4275c9
    key_and_cert_in_base64_format
4275c9
```
4275c9
4275c9
You may also create it from the command line:
4275c9
4275c9
```sh
4275c9
oc create secret generic mbs-frontend-client-cert \
4275c9
--from-file=client.pem=/key_and_cert.pem
4275c9
```
4275c9
4275c9
#### [MBS-Frontend] HTTPD Secret
4275c9
4275c9
Apache HTTPD certificate and private key.
4275c9
4275c9
**NOTES:**
4275c9
4275c9
* The certificate CN field must use the same value as the public hostname for mbs-frontend;
4275c9
* The following subject altnames must be used:
4275c9
    * DNS:$MBS_FRONTEND_PUBLIC_HOSTNAME
4275c9
    * DNS:mbs-frontend
4275c9
    * DNS:mbs-frontend.$OPENSHIFT_NAMESPACE.svc
4275c9
    * DNS:mbs-frontend.$OPENSHIFT_NAMESPACE.svc.cluster
4275c9
4275c9
Secret format:
4275c9
4275c9
```yaml
4275c9
apiVersion: v1
4275c9
kind: Secret
4275c9
metadata:
4275c9
  name: mbs-frontend-service-cert
4275c9
  labels:
4275c9
    app: koji-hub
4275c9
data:
4275c9
  tls.crt: -|
4275c9
    cert_in_base64_format
4275c9
  tls.key: -|
4275c9
    key_in_base64_format
4275c9
```
4275c9
4275c9
You may also create it from the command line:
4275c9
4275c9
```sh
4275c9
oc create secret generic mbs-frontend-service-cert \
4275c9
--from-file=cert=/cert.pem \
4275c9
--from-file=key=/key.pem
4275c9
```