Skip to content

Commit

Permalink
Merge pull request #473 from sagikazarmark/kustomize
Browse files Browse the repository at this point in the history
Kustomize
  • Loading branch information
ese authored Sep 8, 2022
2 parents 0114ab6 + 88c73fc commit 78dcad4
Show file tree
Hide file tree
Showing 22 changed files with 12,672 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,4 @@ generate-crd:
-e CRD_TYPES_PATH=/go/src/$(PROJECT_PACKAGE)/api \
-e CRD_OUT_PATH=/go/src/$(PROJECT_PACKAGE)/manifests \
$(CODEGEN_IMAGE) update-crd.sh
cp -f manifests/databases.spotahome.com_redisfailovers.yaml manifests/kustomize/base
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Redis Operator creates/configures/manages redis-failovers atop Kubernetes.
Redis Operator is meant to be run on Kubernetes 1.19+.
All dependencies have been vendored, so there's no need to any additional download.

## Operator deployment on kubernetes
## Operator deployment on Kubernetes

In order to create Redis failovers inside a Kubernetes cluster, the operator has to be deployed. It can be done with [deployment](example/operator) or with the provided [Helm chart](charts/redisoperator).
In order to create Redis failovers inside a Kubernetes cluster, the operator has to be deployed.
It can be done with plain old [deployment](example/operator), using [Kustomize](manifests/kustomize) or with the provided [Helm chart](charts/redisoperator).

### Using the Helm chart

Expand Down Expand Up @@ -46,6 +47,45 @@ kubectl apply -f https://raw.githubusercontent.com/spotahome/redis-operator/mast

This will create a deployment named `redisoperator`.

### Using kustomize

The kustomize setup included in this repo is highly customizable using [components](https://kubectl.docs.kubernetes.io/guides/config_management/components/),
but it also comes with a few presets (in the form of overlays) supporting the most common use cases.

To install the operator with default settings and every necessary resource (including RBAC, service account, default resource limits, etc), install the `default` overlay:

```shell
kustomize build github.com/spotahome/redis-operator/manifests/kustomize/overlays/default
```

If you would like to customize RBAC or the service account used, you can install the `minimal` overlay.

Finally, you can install the `full` overlay if you want everything this operator has to offer, including Prometheus ServiceMonitor resources.

It's always a good practice to pin the version of the operator in your configuration to make sure you are not surprised by changes on the latest development branch:

```shell
kustomize build github.com/spotahome/redis-operator/manifests/kustomize/overlays/default?ref=v1.2.0
```

You can easily create your own config by creating a `kustomization.yaml` file
(for example to apply custom resource limits, to add custom labels or to customize the namespace):

```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: redis-operator

commonLabels:
foo: bar

resources:
- github.com/spotahome/redis-operator/manifests/kustomize/overlays/full
```
Take a look at the manifests inside [manifests/kustomize](manifests/kustomize) for more details.
## Usage
Once the operator is deployed inside a Kubernetes cluster, a new API will be accesible, so you'll be able to create, update and delete redisfailovers.
Expand Down
12,398 changes: 12,398 additions & 0 deletions manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions manifests/kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-operator
spec:
replicas: 1
strategy:
type: RollingUpdate
template:
spec:
containers:
- name: redis-operator
image: quay.io/spotahome/redis-operator:latest
imagePullPolicy: IfNotPresent
securityContext:
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
restartPolicy: Always
9 changes: 9 additions & 0 deletions manifests/kustomize/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

commonLabels:
app.kubernetes.io/name: redis-operator

resources:
- databases.spotahome.com_redisfailovers.yaml
- deployment.yaml
13 changes: 13 additions & 0 deletions manifests/kustomize/components/monitoring/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-operator
spec:
template:
spec:
containers:
- name: redis-operator
ports:
- name: metrics
containerPort: 9710
protocol: TCP
12 changes: 12 additions & 0 deletions manifests/kustomize/components/monitoring/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

resources:
- service.yaml
- servicemonitor.yaml

patchesStrategicMerge:
- deployment.yaml

configurations:
- kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
commonLabels:
- group: monitoring.coreos.com
version: v1
kind: ServiceMonitor
path: spec/selector/matchLabels
create: true
10 changes: 10 additions & 0 deletions manifests/kustomize/components/monitoring/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: redis-operator
spec:
type: ClusterIP
ports:
- name: metrics
port: 9710
protocol: TCP
8 changes: 8 additions & 0 deletions manifests/kustomize/components/monitoring/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: redis-operator
spec:
endpoints:
- port: metrics
interval: 15s
11 changes: 11 additions & 0 deletions manifests/kustomize/components/rbac-full/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: redis-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: redis-operator
subjects:
- kind: ServiceAccount
name: redis-operator
8 changes: 8 additions & 0 deletions manifests/kustomize/components/rbac-full/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-operator
spec:
template:
spec:
serviceAccountName: redis-operator
12 changes: 12 additions & 0 deletions manifests/kustomize/components/rbac-full/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

components:
- ../rbac/

resources:
- clusterrolebinding.yaml
- serviceaccount.yaml

patchesStrategicMerge:
- deployment.yaml
4 changes: 4 additions & 0 deletions manifests/kustomize/components/rbac-full/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: redis-operator
44 changes: 44 additions & 0 deletions manifests/kustomize/components/rbac/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: redis-operator
rules:
- apiGroups:
- databases.spotahome.com
resources:
- redisfailovers
- redisfailovers/finalizers
verbs:
- "*"
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- "*"
- apiGroups:
- ""
resources:
- pods
- services
- endpoints
- events
- configmaps
- secrets
- persistentvolumeclaims
- persistentvolumeclaims/finalizers
verbs:
- "*"
- apiGroups:
- apps
resources:
- deployments
- statefulsets
verbs:
- "*"
- apiGroups:
- policy
resources:
- poddisruptionbudgets
verbs:
- "*"
5 changes: 5 additions & 0 deletions manifests/kustomize/components/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

resources:
- clusterrole.yaml
16 changes: 16 additions & 0 deletions manifests/kustomize/components/resources/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-operator
spec:
template:
spec:
containers:
- name: redis-operator
resources:
limits:
# cpu: 100m
memory: 50Mi
requests:
cpu: 10m
memory: 50Mi
5 changes: 5 additions & 0 deletions manifests/kustomize/components/resources/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

patchesStrategicMerge:
- deployment.yaml
10 changes: 10 additions & 0 deletions manifests/kustomize/components/version/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

labels:
- pairs:
app.kubernetes.io/version: 1.1.1

images:
- name: quay.io/spotahome/redis-operator
newTag: v1.1.1
13 changes: 13 additions & 0 deletions manifests/kustomize/overlays/default/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

commonLabels:
app.kubernetes.io/name: redis-operator
app.kubernetes.io/instance: redis-operator

components:
- ../../components/resources/
- ../../components/version/

resources:
- ../minimal/
13 changes: 13 additions & 0 deletions manifests/kustomize/overlays/full/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

commonLabels:
app.kubernetes.io/name: redis-operator
app.kubernetes.io/instance: redis-operator

components:
- ../../components/monitoring/
- ../../components/version/

resources:
- ../default/
13 changes: 13 additions & 0 deletions manifests/kustomize/overlays/minimal/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

commonLabels:
app.kubernetes.io/name: redis-operator
app.kubernetes.io/instance: redis-operator

components:
- ../../components/rbac-full/
- ../../components/version/

resources:
- ../../base/

0 comments on commit 78dcad4

Please sign in to comment.