Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement(helm): Allow deploying as a DaemonSet #1658

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions deploy/charts/cerbos/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{{- $tlsDisabled := (eq (include "cerbos.tlsSecretName" .) "None") -}}
{{- $defaultHubDriverEnabled := (eq (include "cerbos.defaultHubDriverEnabled" .) "yes") -}}
apiVersion: apps/v1
{{- if eq .Values.type "deployment" }}
kind: Deployment
{{- else if eq .Values.type "daemonset" }}
kind: DaemonSet
{{- else }}
{{- fail "valid values for .Values.type are deployment or daemonset" }}
{{- end}}
metadata:
name: {{ include "cerbos.fullname" . }}
labels:
Expand All @@ -12,7 +18,9 @@ metadata:
{{- end }}
spec:
{{- if not .Values.autoscaling.enabled }}
{{- if eq .Values.type "deployment" }}
replicas: {{ .Values.replicaCount }}
{{- end }}
{{- end }}
selector:
matchLabels:
Expand Down Expand Up @@ -42,6 +50,9 @@ spec:
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: {{- .Values.priorityClassName }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
{{- with .Values.securityContext }}
Expand Down
2 changes: 1 addition & 1 deletion deploy/charts/cerbos/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.autoscaling.enabled }}
{{- if and .Values.autoscaling.enabled (eq .Values.type "deployment") }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
Expand Down
5 changes: 5 additions & 0 deletions deploy/charts/cerbos/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ spec:
{{- with .Values.service.loadBalancerIP }}
loadBalancerIP: {{ . }}
{{- end }}
{{- if .Values.service.internalTrafficPolicy }}
internalTrafficPolicy: {{ .Values.service.internalTrafficPolicy }}
{{- else if eq .Values.type "daemonset" }}
internalTrafficPolicy: Local
{{- end }}
ports:
- port: {{ .Values.service.httpPort }}
targetPort: http
Expand Down
9 changes: 9 additions & 0 deletions deploy/charts/cerbos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ envFrom: []
certManager:
certSpec: {}

# Kubernetes workload type to use. Valid values are `deployment` or `daemonset`.
type: deployment

# PriorityClassName to set on deployed pods
priorityClassName: ""

# Cerbos service settings.
service:
type: ClusterIP
Expand All @@ -117,6 +123,9 @@ service:
annotations: {}
clusterIP: null
loadBalancerIP: null
# Set the internalTrafficPolicy. If this is unset, and .Values.type
# is set to daemonset, this will default to "Local"
internalTrafficPolicy: ""

# Cerbos deployment settings.
cerbos:
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/modules/deployment/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ image:sidecar_deployment.png[Sidecar model,role="center-img"]
* Each application instance gets its own Cerbos instance — ensuring high performance and availability.
* Upgrades to Cerbos would require a rolling update to all the application instances.
* Policy updates could take slightly longer to propagate to all the individual application instances — resulting in a period where both the old and new policies are in effect at the same time.

== DaemonSet model

image:daemonset_deployment.png[DaemonSet model,role="center-img"]

* Each cluster node gets its own Cerbos instance — ensuring high performance and efficient resource usage.
* Policy updates must roll out to nodes individually — resulting in a period where both the old and new policies are in effect at the same time.
* When deployed as a daemonset the service `internalTrafficPolicy` defaults to `Local`. This causes all requests to the service to be forced to the local node for minimum latency. Upgrades to Cerbos could result in application seeing a short outage to the cerbos instance on their own node, client retries may be neccessary. If this is unacceptable you can set `service.internalTrafficPolicy` to `Cluster`. You may be able to improve availability via the `service.kubernetes.io/topology-mode: Auto` annotation.
5 changes: 5 additions & 0 deletions docs/modules/deployment/pages/k8s-daemonset.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include::ROOT:partial$attributes.adoc[]

= Deploy Cerbos as DaemonSet

You can use the xref:ROOT:installation/helm.adoc[Cerbos Helm chart] to deploy Cerbos as a daemonset inside your Kubernetes cluster. Refer to the xref:ROOT:installation/helm.adoc[Helm chart instructions] for more details.