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

New version of zdm-proxy helm chart using StatefulSets #89

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9f32a90
initial collection of helm charts to deploy zdm into k8s
weideng1 Dec 14, 2022
9896ee1
added README file
weideng1 Dec 14, 2022
e842935
pull zdm-proxy docker image version from helm chart's AppVersion
weideng1 Dec 14, 2022
29b0b4d
fixed a bug so release name can be customized now
weideng1 Dec 14, 2022
3d46813
added a big more verification info in README
weideng1 Dec 15, 2022
0e765f3
added Cassandra Data Migrator (CDM) to the helm chart and adjusted hi…
weideng1 Dec 15, 2022
9647c87
use cdm image 2.10.3 to solve python3 dependency
weideng1 Dec 15, 2022
83a7cc6
modify README instructions for local dev machine
weideng1 Dec 15, 2022
bb8c038
changed README instructions to move secrets lifecycle outside of helm…
weideng1 Dec 15, 2022
461139e
address another small comment from Jim
weideng1 Dec 15, 2022
7235572
move ZDM_ORIGIN_PORT from configmap to secret, which is preset before…
weideng1 Dec 15, 2022
eb5c49b
mpromoted a bunch of values that should be user configurable to value…
weideng1 Dec 15, 2022
6eaf66f
fixed a quote bug in configmap
weideng1 Dec 15, 2022
286f7c9
fixed three issues Phil found in his tests
weideng1 Dec 15, 2022
a42d5e9
address Joao's comments to reduce zdm-proxy memory down to 2GB
weideng1 Dec 15, 2022
f58e7b3
Merge branch 'main' into k8s-helm
weideng1 Dec 16, 2022
5d52bd0
change cdm to pod instead of deployment, as it doesn't need to be aut…
weideng1 Dec 23, 2022
f86e2c8
fixed a bug caused by merging two commits
weideng1 Dec 23, 2022
6f57a02
switched k8s deployment to statefulsets for proxy pods #88
weideng1 Dec 28, 2022
e8dfd54
Merge branch 'main' into k8s-helm
weideng1 Dec 28, 2022
9f1affc
Merge branch 'main' into k8s-helm
weideng1 Jan 13, 2023
692a11b
remove CDM from helm chart
weideng1 Jan 18, 2023
4ef5754
remove deployment.yaml
weideng1 Jan 24, 2023
98636c4
revised helm chart according to John's comments on values.yaml best p…
weideng1 Jan 25, 2023
dd1c433
fix values in README.md that are no longer accurate
weideng1 Jan 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions k8s_helm_charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,31 @@ Usage:

```helm -n zdmproxy uninstall zdm-proxy```

```helm -n zdmproxy install --set proxy.resources.requests.cpu=1000m --set proxy.resources.requests.memory=2000Mi --set proxy.resources.limits.cpu=1000m --set proxy.resources.limits.memory=2000Mi --set cdm.resources.requests.cpu=1000m --set cdm.resources.requests.memory=2000Mi --set cdm.resources.limits.cpu=1000m --set cdm.resources.limits.memory=2000Mi zdm-proxy ./zdm```
```helm -n zdmproxy install --set resources.requests.cpu=1000m --set resources.requests.memory=2000Mi --set resources.limits.cpu=1000m --set resources.limits.memory=2000Mi zdm-proxy ./zdm```

4. Verify that all components are up and running.

```kubectl -n zdmproxy get svc,cm,secret,deploy,po -o wide --show-labels```
```kubectl -n zdmproxy get svc,ep,po,secret -o wide --show-labels```

You can also run ```kubectl -n zdmproxy logs pod/zdm-proxy-0``` to see if there are the following entries in the log, which means everything is working as expected:

You can also run ```kubectl -n zdmproxy logs pod/zdm-proxy-0-xxxxxxx``` to see if there are the following entries in the log, which means everything is working as expected:

```
time="2022-12-14T21:19:57Z" level=info msg="Proxy connected and ready to accept queries on 172.25.132.116:9042"
time="2022-12-14T21:19:57Z" level=info msg="Proxy started. Waiting for SIGINT/SIGTERM to shutdown."
```

5. When you're done, run helm uninstall to remove all objects.
5. Switch primary cluster to target (all proxy pods will automatically roll-restart after the change).

```helm -n zdmproxy upgrade zdm-proxy ./zdm --set primaryCluster=TARGET```

6. Scale out/in to different number of proxy pods.

```helm -n zdmproxy upgrade zdm-proxy ./zdm --set count=5```

Note: if you've already switched primary cluster to target, make sure you add ```--set primaryCluster=TARGET``` in this command line as well. An alternative is to directly edit zdm/values.yaml then run helm upgrade.

7. When you're done, run helm uninstall to remove all objects.


```helm -n zdmproxy uninstall zdm-proxy```
4 changes: 2 additions & 2 deletions k8s_helm_charts/zdm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 1.0.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "2.0.x"
appVersion: "2.1.x"
74 changes: 0 additions & 74 deletions k8s_helm_charts/zdm/templates/cdm.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions k8s_helm_charts/zdm/templates/configmap.yaml

This file was deleted.

8 changes: 4 additions & 4 deletions k8s_helm_charts/zdm/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{ $zdm_fullname := include "zdm.fullname" . -}}
{{- $zdm_labels := include "zdm.labels" . -}}
{{- $zdm_selectorLabels := include "zdm.selectorLabels" . -}}
{{- range $index := until (.Values.proxy.count | int) -}}
{{- range $index := until (.Values.count | int) -}}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -13,14 +13,14 @@ metadata:
app: {{ $zdm_fullname }}-{{ $index }}
role: zdmproxy
spec:
type: {{ $.Values.service.type }}
type: {{ $.Values.serviceType }}
ports:
- port: {{ $.Values.service.port | int }}
- port: {{ $.Values.servicePort | int }}
targetPort: 9042
protocol: TCP
name: cql
selector:
{{- $zdm_selectorLabels | nindent 4 }}
app: {{ $zdm_fullname }}-{{ $index }}
statefulset.kubernetes.io/pod-name: {{ $zdm_fullname }}-{{ $index }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you trying to match a per-pod label?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsanda The reason for us to create individual services and match them 1:1 at pod level is because unlike C*, zdm-proxy processes don't have gossip protocol to detect/notify topology changes among themselves; whatever set of IP addresses and their respective ordinal index (see here) specified at the start of the proxy process is going to stuck for the rest of its lifecycle. To allow dynamical IP address change to the pods due to reschedule/cordon/crash, we decided to for N number of proxies, implement N number of services, and them map 1-on-1. Given that pods managed by k8s Deployment object doesn't have a static pod name, we switched to using StatefulSets. In StatefulSets, each pod has a unique/static pod-name that we can map the service to. This will allow orderly rolling restart of the zdm-proxy pods to happen.

---
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,71 @@

# calculate a variable that contains all proxy service addresses
{{ $service_addresses := "" -}}
{{- range $index := until (.Values.proxy.count | int) -}}
{{- range $index := until (.Values.count | int) -}}
{{- $service_addresses = printf "%s,$(%s_%s_SERVICE_HOST)" $service_addresses ($zdm_fullname | upper | replace "-" "_") ($index | toString) -}}
{{- end -}}
{{- $service_addresses = $service_addresses | trimPrefix "," -}}

weideng1 marked this conversation as resolved.
Show resolved Hide resolved
{{- range $index := until (.Values.proxy.count | int) -}}
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
labels:
{{- $zdm_labels | nindent 4 }}
app: {{ $zdm_fullname }}-{{ $index }}
name: {{ $zdm_fullname }}-{{ $index }}
app: {{ $zdm_fullname }}
name: {{ $zdm_fullname }}
namespace: {{ $.Values.namespace }}
spec:
replicas: 1
serviceName: {{ $zdm_fullname }}
replicas: {{ $.Values.count | int }}
selector:
matchLabels:
{{- $zdm_selectorLabels | nindent 6 }}
app: {{ $zdm_fullname }}-{{ $index }}
app: {{ $zdm_fullname }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider these recommended labels from the k8s docs.

https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/

template:
metadata:
labels:
{{- $zdm_selectorLabels | nindent 8 }}
app: {{ $zdm_fullname }}-{{ $index }}
app: {{ $zdm_fullname }}
spec:
containers:
- image: "{{ $.Values.proxy.image.repository }}:{{ $.Values.proxy.image.tag | default $.Chart.AppVersion }}"
name: {{ $zdm_fullname }}-{{ $index }}
- image: "{{ $.Values.imageRepository }}:{{ $.Values.imageTag | default $.Chart.AppVersion }}"
name: {{ $zdm_fullname }}
command:
- sh
- "-c"
- "ZDM_PROXY_TOPOLOGY_INDEX=`echo ${HOSTNAME##*-}` /main"
Comment on lines +38 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's surprising that you're specifying a command here vs just passing in arguments to the command specified in the Docker image (or relying on arguments there).

Comment on lines +38 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to populate an environment variable with a fieldRef from metadata.name. See https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it looks like you're extracting the ordinal index which is not available to the pod directly. It's frustrating that this isn't available. (I see the link to kubernetes/kubernetes#40651 as well)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradfordcp Yes exactly. That was the route I explored and ended up using the workaround as you pointed out. Should we resolve this comment?

livenessProbe:
httpGet:
path: /health/liveness
port: httpproxy
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /health/readiness
port: httpproxy
initialDelaySeconds: 10
periodSeconds: 10
ports:
- name: httpproxy
containerPort: 14001
protocol: TCP
- name: cql
containerPort: 9042
protocol: TCP
resources:
weideng1 marked this conversation as resolved.
Show resolved Hide resolved
requests:
memory: {{ $.Values.proxy.resources.requests.memory | quote }}
cpu: {{ $.Values.proxy.resources.requests.cpu | quote }}
limits:
memory: {{ $.Values.proxy.resources.limits.memory | quote }}
cpu: {{ $.Values.proxy.resources.limits.cpu | quote }}
envFrom:
- configMapRef:
name: {{ $zdm_fullname }}
{{- toYaml .Values.resources | nindent 10 }}
env:
- name: ZDM_PRIMARY_CLUSTER
value: {{ $.Values.primaryCluster | upper | quote }}
- name: ZDM_READ_MODE
value: {{ $.Values.readMode | upper | quote }}
- name: ZDM_LOG_LEVEL
value: {{ $.Values.logLevel | upper | quote }}
- name: ZDM_PROXY_MAX_CLIENT_CONNECTIONS
value: {{ $.Values.maxClientConnections | quote }}
- name: ZDM_METRICS_ENABLED
value: {{ $.Values.metricsEnabled | quote }}
- name: ZDM_PROXY_LISTEN_ADDRESS
valueFrom:
fieldRef:
Expand All @@ -57,8 +82,6 @@ spec:
fieldPath: status.podIP
- name: ZDM_METRICS_PORT
value: "14001"
- name: ZDM_PROXY_TOPOLOGY_INDEX
value: {{ $index | quote }}
- name: ZDM_PROXY_TOPOLOGY_ADDRESSES
value: {{ $service_addresses }}
- name: ZDM_TARGET_SECURE_CONNECT_BUNDLE_PATH
Expand Down Expand Up @@ -93,8 +116,6 @@ spec:
secretKeyRef:
name: zdmproxy
key: target_password
ports:
- containerPort: 9042
volumeMounts:
- name: scb
mountPath: "/tmp/scb"
Expand All @@ -106,5 +127,3 @@ spec:
items:
- key: secure-connect-target.zip
path: target.zip
---
{{- end -}}
76 changes: 39 additions & 37 deletions k8s_helm_charts/zdm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,47 @@
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

# namespace to deploy zdm objects in
namespace: zdmproxy

proxy:
count: 3
logLevel: "INFO"
# two options: PRIMARY_ONLY and ASYNC_READS_ON_SECONDARY
readMode: "PRIMARY_ONLY"
# two options: ORIGIN and TARGET
primaryCluster: "ORIGIN"
maxClientConnections: "1000"
metricsEnabled: "true"
resources:
limits:
cpu: 4000m
memory: 2048Mi
requests:
cpu: 4000m
memory: 2048Mi
image:
repository: datastax/zdm-proxy
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""

cdm:
resources:
limits:
cpu: 16000m
memory: 32768Mi
requests:
cpu: 16000m
memory: 32768Mi
image:
repository: datastax/cassandra-data-migrator
tag: 2.10.3
# count is the number of zdm proxy pods (and corresponding services)
count: 3

# logLevel is logging level for zdm proxy, available options are: PANIC, FATAL, ERROR, WARN or WARNING, INFO, DEBUG and TRACE
logLevel: "INFO"

# readMode has two options: PRIMARY_ONLY and ASYNC_READS_ON_SECONDARY
readMode: "PRIMARY_ONLY"

# primaryCluster has two options: ORIGIN and TARGET
primaryCluster: "ORIGIN"

# maxClientConnections is the limit on maximum number of client connections per proxy
maxClientConnections: "1000"

# metricsEnabled is whether to enable metrics/http port on proxy
metricsEnabled: "true"

# resources request and limit for zdm proxy pods
resources:
limits:
cpu: 4000m
memory: 2048Mi
requests:
cpu: 4000m
memory: 2048Mi

# imageRepository is the dockerhub repository to pull zdm-proxy image from
imageRepository: datastax/zdm-proxy

# imageTag defines the tag on dockerhub repo for pulling zdm-proxy image, it overrides the image tag whose default is the chart appVersion.
imageTag: ""

# serviceType is the type of service used for zdm-proxy pod's associated CQL service
serviceType: ClusterIP

# servicePort is the CQL port exposed to the rest of the k8s cluster from the zdm-proxy service
servicePort: 9942

nameOverride: ""
fullnameOverride: ""

service:
type: ClusterIP
port: 9942