From 14b84a79db0d134838be14eaa0b3ad01f5f8c93d Mon Sep 17 00:00:00 2001 From: Vasyl Saienko Date: Sat, 14 Sep 2024 15:48:32 +0000 Subject: [PATCH] [memcached] Change deployment type to statefulset For effective cache use all endpoints should be specified explicitly as memcache client use specific algorithm to identify on which cache server key is stored based on servers availability and key name. If memcached deployed behind the service unless same key is stored on all memcached instances clients will always got cache misses and will require to use heavy calls to database. So in the end all keys will be stored on all memcached instances. Furthermore delete operations such as revoke token or remove keystone group call logic in service to remove data from cache if Loadbalancer is used this functionality can't work as we can't remove keys from all backends behind LB with single call. Change-Id: I253cfa2740fed5e1c70ced7308a489568e0f10b9 --- memcached/Chart.yaml | 2 +- .../{deployment.yaml => statefulset.yaml} | 30 ++++++++++++------- memcached/values.yaml | 24 ++++++++++++++- releasenotes/notes/memcached.yaml | 1 + 4 files changed, 45 insertions(+), 12 deletions(-) rename memcached/templates/{deployment.yaml => statefulset.yaml} (77%) diff --git a/memcached/Chart.yaml b/memcached/Chart.yaml index 8263c2ab3..76f2bc73a 100644 --- a/memcached/Chart.yaml +++ b/memcached/Chart.yaml @@ -15,6 +15,6 @@ apiVersion: v1 appVersion: v1.5.5 description: OpenStack-Helm Memcached name: memcached -version: 0.1.15 +version: 0.1.16 home: https://github.com/memcached/memcached ... diff --git a/memcached/templates/deployment.yaml b/memcached/templates/statefulset.yaml similarity index 77% rename from memcached/templates/deployment.yaml rename to memcached/templates/statefulset.yaml index b3d12eaf3..f9dd19580 100644 --- a/memcached/templates/deployment.yaml +++ b/memcached/templates/statefulset.yaml @@ -18,7 +18,18 @@ limitations under the License. {{- $_ := set . "deployment_name" .Release.Name }} {{- end }} -{{- if .Values.manifests.deployment }} +{{- define "memcachedProbeTemplate" }} +tcpSocket: + port: {{ tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} +{{- end }} + +{{- define "exporterProbeTemplate" }} +httpGet: + path: /metrics + port: {{ tuple "oslo_cache" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} +{{- end }} + +{{- if .Values.manifests.statefulset }} {{- $envAll := . }} {{- $rcControllerName := printf "%s-%s" $envAll.deployment_name "memcached" }} @@ -27,7 +38,7 @@ limitations under the License. {{ tuple $envAll "memcached" $rcControllerName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }} --- apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: name: {{ $rcControllerName | quote }} annotations: @@ -35,7 +46,9 @@ metadata: labels: {{ tuple $envAll "memcached" "server" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} spec: + podManagementPolicy: Parallel replicas: {{ .Values.pod.replicas.server }} + serviceName: "{{ tuple "oslo_cache" "internal" . | include "helm-toolkit.endpoints.hostname_short_endpoint_lookup" }}" selector: matchLabels: {{ tuple $envAll "memcached" "server" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 6 }} @@ -79,9 +92,8 @@ spec: - /tmp/memcached.sh ports: - containerPort: {{ tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} - readinessProbe: - tcpSocket: - port: {{ tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} +{{ dict "envAll" $envAll "component" "memcached" "container" "memcached" "type" "readiness" "probeTemplate" (include "memcachedProbeTemplate" $envAll | fromYaml) | include "helm-toolkit.snippets.kubernetes_probe" | indent 10 }} +{{ dict "envAll" $envAll "component" "memcached" "container" "memcached" "type" "liveness" "probeTemplate" (include "memcachedProbeTemplate" $envAll | fromYaml) | include "helm-toolkit.snippets.kubernetes_probe" | indent 10 }} volumeMounts: - name: pod-tmp mountPath: /tmp @@ -91,8 +103,7 @@ spec: readOnly: true {{- if .Values.monitoring.prometheus.enabled }} - name: memcached-exporter - image: {{ .Values.images.tags.prometheus_memcached_exporter }} - imagePullPolicy: {{ .Values.images.pull_policy }} +{{ tuple $envAll "prometheus_memcached_exporter" | include "helm-toolkit.snippets.image" | indent 10 }} {{ tuple $envAll $envAll.Values.pod.resources.prometheus_memcached_exporter | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} {{ dict "envAll" $envAll "application" "server" "container" "memcached_exporter" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }} command: @@ -101,9 +112,8 @@ spec: ports: - name: metrics containerPort: {{ tuple "oslo_cache" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} - readinessProbe: - tcpSocket: - port: {{ tuple "oslo_cache" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} +{{ dict "envAll" $envAll "component" "memcached" "container" "memcached_exporter" "type" "readiness" "probeTemplate" (include "exporterProbeTemplate" $envAll | fromYaml) | include "helm-toolkit.snippets.kubernetes_probe" | indent 10 }} +{{ dict "envAll" $envAll "component" "memcached" "container" "memcached_exporter" "type" "liveness" "probeTemplate" (include "exporterProbeTemplate" $envAll | fromYaml) | include "helm-toolkit.snippets.kubernetes_probe" | indent 10 }} volumeMounts: - name: pod-tmp mountPath: /tmp diff --git a/memcached/values.yaml b/memcached/values.yaml index f2e6d8fd2..7c0102e5c 100644 --- a/memcached/values.yaml +++ b/memcached/values.yaml @@ -139,7 +139,7 @@ labels: manifests: configmap_bin: true - deployment: true + statefulset: true job_image_repo_sync: true network_policy: false service: true @@ -157,6 +157,28 @@ pod: memcached_exporter: allowPrivilegeEscalation: false readOnlyRootFilesystem: true + probes: + memcached: + memcached: + readiness: + enabled: True + params: + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 5 + memcached_exporter: + liveness: + enabled: True + params: + initialDelaySeconds: 15 + periodSeconds: 60 + timeoutSeconds: 10 + readiness: + enabled: True + params: + initialDelaySeconds: 5 + periodSeconds: 60 + timeoutSeconds: 10 affinity: anti: topologyKey: diff --git a/releasenotes/notes/memcached.yaml b/releasenotes/notes/memcached.yaml index 9b3b939af..6554a5b68 100644 --- a/releasenotes/notes/memcached.yaml +++ b/releasenotes/notes/memcached.yaml @@ -16,4 +16,5 @@ memcached: - 0.1.13 Replace node-role.kubernetes.io/master with control-plane - 0.1.14 Use quay.io/airshipit/kubernetes-entrypoint:latest-ubuntu_focal by default - 0.1.15 Allow to pass additional service parameters + - 0.1.16 Change deployment type to statefulset ...