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

feat(api): Replace fluentd deployment with statefulset #370

Conversation

deadlycoconuts
Copy link
Contributor

@deadlycoconuts deadlycoconuts commented Mar 6, 2024

Context

In order to make the Fluentd deployment used by a Turing router deployment (to flush logs to BigQuery) more robust to cluster autoscaling events, which may remove the node on which the one and only Fluentd pod is scheduled and cause the Turing routers to return errors, we need to increase the number of replicas of the Fluentd deployment from 1 to 2.

However, doing so involves replacing how Turing deploys the Fluentd deployment - from a Kubernetes Deployment resource to a StatefulSet. This is needed because deployments do not allow its pod replicas to specify volume/volume mount names that are different. This is crucial because the PVC that the current Fluentd pod uses is of the ReadWriteOnce type, which means that Fluentd replicas need to be scheduled on the same node in order to read/write on the same PVC. Other access mode exist - such as ReadOnlyMany and ReadWriteMany. However, ReadOnlyMany wouldn't allow Fluentd to write anything to the PVC, completely voiding the original purpose of even attaching a PVC to Fluentd, while ReadWriteMany isn't available in all managed Kubernetes services.

By replacing the Deployment with a StatefulSet, we are able to specify a generic name for any of the PVCs that will be spun up in tandem with the number of pods the StatefulSet controls. This allows us to increase the number of Fluentd pods to 2, which allows for better uptime of the Fluentd service, especially when we introduce other configurations such as PodDisruptionBudgets.

As we are increasing the number of Fluentd pods, we are also halving the amount of CPU and memory resources requested for each pod to keep the total amount of resources consumed the same as before.

Additional Changes

This PR also includes a tiny change to the pod disruption budget selector key used for Knative services (Turing routers, enrichers and ensemblers) from app to serving.knative.dev/service. This is done because the label value corresponding to the app key on these Knative service-managed pods have an additional suffix (e.g. -0) that indicates the revision number of the deployment.

While this isn't a problem in most instances, any manual edits made to the Knative service manifest would undoubtedly cause the revision number to be bumped (e.g. from 0 to 1), making the existing pod disruption budget resources created useless. This isn't the case however, for the label value corresponding to the serving.knative.dev/service key, which does not have the additional revision number suffix.

Main Modifications

  • api/turing/cluster/controller.go - Refactoring of the steps to deploy Fluentd as a stateful set instead of a deployment
  • api/turing/cluster/kubernetes_service.go - Refactoring of the Fluentd deployment spec to a statefulset spec
  • api/turing/cluster/servicebuilder/fluentd.go - Halving of Fluentd CPU and memory resources for each pod
  • api/turing/cluster/servicebuilder/service_builder.go - Addition of steps to configure PDBs differently for Fluentd
  • api/turing/service/router_deployment_service.go - Removal of steps needed to manually create/delete PVCs

@deadlycoconuts deadlycoconuts added the enhancement New feature or request label Mar 6, 2024
@deadlycoconuts deadlycoconuts self-assigned this Mar 6, 2024
@deadlycoconuts deadlycoconuts force-pushed the change_fluentd_deployment_to_stateful_set branch from 46901e4 to 24bf66a Compare March 8, 2024 10:32
@deadlycoconuts deadlycoconuts force-pushed the change_fluentd_deployment_to_stateful_set branch from a5acd4b to 222b95f Compare March 26, 2024 03:31
@deadlycoconuts deadlycoconuts marked this pull request as ready for review March 27, 2024 10:07
@deadlycoconuts deadlycoconuts force-pushed the change_fluentd_deployment_to_stateful_set branch from ce7c839 to e7bb62d Compare April 2, 2024 09:31
Copy link
Contributor

@leonlnj leonlnj left a comment

Choose a reason for hiding this comment

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

thanks, lgtm!

@deadlycoconuts
Copy link
Contributor Author

Thanks for the reviews everyone! Merging this now! 🚀

@deadlycoconuts deadlycoconuts merged commit 7515693 into caraml-dev:main Apr 3, 2024
12 checks passed
@deadlycoconuts deadlycoconuts deleted the change_fluentd_deployment_to_stateful_set branch May 7, 2024 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants