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

Add one or many sidecar container options in Kubegres YAML #30

Open
sloppycoder opened this issue Aug 7, 2021 · 10 comments
Open

Add one or many sidecar container options in Kubegres YAML #30

sloppycoder opened this issue Aug 7, 2021 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@sloppycoder
Copy link

Prometheus is very popular with Kuberentes users and it'll be helpful to be able to deploy the postgres_exporter along ith postgres databaes instances so that the metrics can be collected by Proemtheus.

@alex-arica
Copy link
Member

Thank you for your message.
If you would like to deploy a side container, it's only possible by creating your own custom container by extending Postgres container and then in your own custom container you can add anything you would like.

@alex-arica
Copy link
Member

Hello,
I have not heard from you. Is there an alternative method that you would suggest?

@alex-arica
Copy link
Member

I am closing this issue. If you would like to make a suggestion about an alternative solution, please do not hesitate to make a comment.

@LanDinh
Copy link

LanDinh commented Dec 17, 2021

Hi @alex-arica ! I just stumbled upon this as I was adding metrics to all third-party stuff that I use. The way postgres-exporter is usually deployed is as a container that is separate from the actual database, and you provide connection strings to point to the postgres database.

In the case of Kubernetes, this would be done by using sidecar containers, e.g:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  ...
spec:
  ...
  template:
    ...
    spec:
      ...
      containers:
      - name: postgres-main-instance
        ...
        - containerPort: ...
          name: ...
      - name: postgres-exporter
        ...
        - containerPort: <different port from main instance>
          name: metrics

Reasons to do it in a separate container:

  • It's not necessary to create a custom image
  • Even if the postgres server becomes unresponsive, the last state of the metrics is sill available, because it's isolated
  • The separate container is the typical way to do it - here's the quickstart guide from their github readme:
    # Start an example database
    docker run --net=host -it --rm -e POSTGRES_PASSWORD=password postgres
    # Connect to it
    docker run \
      --net=host \
      -e DATA_SOURCE_NAME="postgresql://postgres:password@localhost:5432/postgres?sslmode=disable" \
      quay.io/prometheuscommunity/postgres-exporter
    

Reasons to not deploy it in a separate Deployment, but attach it inside the StatefulSet by kubegres:

  • you need one instance per postgres replica, so you need to connect to the pods directly - and those might get killed & replaced etc.

So I think that the question here was: is it possible to specify such sidecar containers that get attached to the StatefulSet controlling the kubegres pods? If not, here's how I imagine that this could be implemented:

  • add an optional list of sidecars to the kubegres resource, that allows specifying image, port and args (environment variables would be a great plus, but are probably more work to implement). Specifying both the port number + name instead of only the number would also be a huge plus!
  • this list of sidecars gets added to the StatefulSet
  • the port specified will be used by the service to expose the endpoint for that container

And considering that monitoring is a must-have for production services, this would be a really nice feature!

@LanDinh
Copy link

LanDinh commented Dec 17, 2021

This would make kubegres fit really nicely into other production-ready environments in kubernetes:

  • kube-prometheus is the easiest way to add monitoring to all of kubernetes, and will automatically spin up prometheus for metric collection & grafana for dashboards for you
  • all that your pods need to do is expose prometheus metrics (in the case of postgres, this happens via postgres-exporter)
  • point your prometheus to scrape these metrics
  • download a dashboard for postgres from grafana (e.g. https://grafana.com/grafana/dashboards/9628)

-> look at all those pretty graphs that tell you about stuff like your database CPU & memory usage, number of transaction per time, etc. (you can click on the images in the dashboard that I linked to see an example of what you get out of the box if only your postgres instance exports prometheus metrics)

@alex-arica
Copy link
Member

@LanDinh Thank you for sharing this. I agree that for those who prefer the sidecar option, it would add value to be able to specify one or many sidecars in Kubegres YAML.

I am re-openning this issue and it will be about being able to specify one or many sidecars to Kubegres.

Thank you.

@alex-arica alex-arica reopened this Dec 20, 2021
@alex-arica alex-arica added the enhancement New feature or request label Dec 20, 2021
@alex-arica alex-arica changed the title Is there an option to deploy Prometheus postgres_exporter togehter with progres instances? Add one or many sidecar container options in Kubegres YAML Dec 20, 2021
@bm-skutzke
Copy link

Any news on this? The missing option for sidecar containers is currently the major reason for not using Kubegres in production. Anything else works pretty fine. I really like the simplicity of Kubegres compared to other much more complex operators. Many thanks for this awesome work!

@alex-arica
Copy link
Member

I agree that it will a useful feature.

If a developer is willing to implement this change, I am available to review their PR.

We decided to let the community to be more involved in the project and therefore until end of summer 2022, I will only make a code changes when it is required.

With this approach, we are hoping there would be additional developers involved in this project and more PRs submitted.

@CasperGN
Copy link
Contributor

CasperGN commented Mar 19, 2024

@alex-arica can you add either @jgmartinez or me as assigned to this and #89?
We would like to add the support for our OTEL setup. We’ll most likely take a stab at it during the following two weeks 👍

@alex-arica
Copy link
Member

@CasperGN I assigned it to you. From now, I think you can assign it to anyone else if required.

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

No branches or pull requests

5 participants