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]: Not using Nginx class name #67

Closed
guy-frontegg opened this issue Nov 7, 2024 · 13 comments · Fixed by #70
Closed

[FEAT]: Not using Nginx class name #67

guy-frontegg opened this issue Nov 7, 2024 · 13 comments · Fixed by #70
Labels
enhancement New feature or request

Comments

@guy-frontegg
Copy link

Description

Hey All,
Great work on Keep, and thank you for open-source it.

We are using Nginx as an ingress controller, yet it has a different name. In the helm chart, if the ClassName is not Nginx, you lose all the configuration that makes Keep work.

Before creating a whole new ingress just for that, do you maybe have another solution?

And what is the importance of a WebSocket for Keep? should we enable it?

Thank you

Additional Information

No response

@guy-frontegg guy-frontegg added the enhancement New feature or request label Nov 7, 2024
@shahargl
Copy link
Member

shahargl commented Nov 8, 2024

Hey @guy-frontegg, thanks!

Per your nginx-different-class-name, can you send some another helm configuration which do it? I’ll try to implement it even today. If not - I’ll think on smth.

Regarding web socket - it is for live updates without refreshing the page. Imagine new alert arrive and you want to see it on the frontend without refreshing the page.

@guy-frontegg
Copy link
Author

Thank you for your answer.

We simply need to provide a different className since we have more than one. For example we will use alb. I suggest basing it on a property like useNginx and letting us set the class name. (I hope I understand you correctly)

@guy-frontegg
Copy link
Author

Hi @shahargl ,

Anything you need from me?

@shahargl
Copy link
Member

shahargl commented Nov 11, 2024

@guy-frontegg somehow missed your response, sorry for that.

you can use global.ingress.className to control the ingress className.
in nginx-ingress (I'll change it to just ingress) you can see that:

spec:
  ingressClassName: {{ .Values.global.ingress.className }}

So just deploy with helm install ... --set global.ingress.className==alb

My concern is that for every ingress (e.g. alb) different adjustments would be needed.

@shahargl
Copy link
Member

I've merged the renaming (#69)

@guy-frontegg
Copy link
Author

guy-frontegg commented Nov 11, 2024

i tied to create a PR but it's not allowed
please look at this ingress yaml

the ingressClassName points to the ingress controller you want to use and we have more than one. With current state in your helm template our ingressClassName must be named nginx to get the configutaion

{{- if .Values.global.ingress.enabled }}
{{- $fullName := include "keep.fullname" . }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ $fullName }}-ingress
  labels:
    {{- include "keep.labels" . | nindent 4 }}
  annotations:
    {{- if eq .Values.global.ingress.type "nginx" }}
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-buffering: "off"
    nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
    nginx.ingress.kubernetes.io/use-http2: "false"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      if ($request_uri ~* ^({{ .Values.global.ingress.websocketPrefix }}|{{ .Values.global.ingress.backendPrefix }}|{{ .Values.global.ingress.frontendPrefix }})(/|$)(.*)) {
        rewrite ^({{ .Values.global.ingress.websocketPrefix }}|{{ .Values.global.ingress.backendPrefix }}|{{ .Values.global.ingress.frontendPrefix }})(/|$)(.*) /$3 break;
      }
    nginx.ingress.kubernetes.io/server-snippet: |
      {{- if $.Values.websocket.enabled }}
      location ^~ {{ .Values.global.ingress.websocketPrefix }} {
        rewrite ^{{ .Values.global.ingress.websocketPrefix }}(/|$)(.*) /$2 break;
        proxy_pass http://{{ $fullName }}-websocket.{{ .Release.Namespace }}.svc.cluster.local:{{ $.Values.websocket.service.port }};
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_cache_bypass $http_upgrade;
      }
      {{- end }}
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/use-regex: "true"
    {{- end }}
    {{- with .Values.global.ingress.annotations }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
spec:
  ingressClassName: {{ .Values.global.ingress.className }}
  {{- if .Values.global.ingress.tls }}
  tls:
    {{- range .Values.global.ingress.tls }}
    - hosts:
        {{- range .hosts }}
        - {{ . | quote }}
        {{- end }}
      secretName: {{ .secretName }}
    {{- end }}
  {{- end }}
  rules:
    {{- if .Values.global.ingress.hosts }}
    {{- range .Values.global.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
        {{- if $.Values.websocket.enabled }}
        - path: {{ $.Values.global.ingress.websocketPrefix }}(/|$)(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: {{ $fullName }}-websocket
              port:
                number: {{ $.Values.websocket.service.port }}
        {{- end }}
        {{- if $.Values.backend.enabled }}
        - path: {{ $.Values.global.ingress.backendPrefix }}(/|$)(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: {{ $fullName }}-backend
              port:
                number: {{ $.Values.backend.service.port }}
        {{- end }}
        - path: {{ $.Values.global.ingress.frontendPrefix }}(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: {{ $fullName }}-frontend
              port:
                number: {{ $.Values.frontend.service.port }}
    {{- end }}
    {{- else }}
    - http:
        paths:
        {{- if $.Values.websocket.enabled }}
        - path: {{ $.Values.global.ingress.websocketPrefix }}(/|$)(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: {{ $fullName }}-websocket
              port:
                number: {{ $.Values.websocket.service.port }}
        {{- end }}
        {{- if $.Values.backend.enabled }}
        - path: {{ $.Values.global.ingress.backendPrefix }}(/|$)(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: {{ $fullName }}-backend
              port:
                number: {{ $.Values.backend.service.port }}
        {{- end }}
        - path: {{ $.Values.global.ingress.frontendPrefix }}(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: {{ $fullName }}-frontend
              port:
                number: {{ $.Values.frontend.service.port }}
    {{- end }}
{{- end }}

@guy-frontegg
Copy link
Author

Hey @shahargl ,

Did you delete the last comment?

@shahargl
Copy link
Member

@guy-frontegg I'm still struggling to understand what's the problem.

If you specify global.ingress.className other than nginx, you'll get what you need.

For example, by default it uses nginx:

helm template keep . -s templates/ingress.yaml

---
# Source: keep/templates/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: keep-ingress
  labels:
    helm.sh/chart: keep-0.1.34
    app.kubernetes.io/name: keep
    app.kubernetes.io/instance: keep
    app.kubernetes.io/version: "0.28.4"
    app.kubernetes.io/managed-by: Helm
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-buffering: "off"
    nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
    nginx.ingress.kubernetes.io/use-http2: "false"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      if ($request_uri ~* ^(/websocket|/v2|/)(/|$)(.*)) {
        rewrite ^(/websocket|/v2|/)(/|$)(.*) /$3 break;
      }
    nginx.ingress.kubernetes.io/server-snippet: |
      location ^~ /websocket {
        rewrite ^/websocket(/|$)(.*) /$2 break;
        proxy_pass http://keep-websocket.default.svc.cluster.local:6001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_cache_bypass $http_upgrade;
      }
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  ingressClassName: nginx
  rules:
    - http:
        paths:
        - path: /websocket(/|$)(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: keep-websocket
              port:
                number: 6001
        - path: /v2(/|$)(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: keep-backend
              port:
                number: 8080
        - path: /(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: keep-frontend
              port:
                number: 3000

But when I speficy another class name I get what you want:

helm template keep . -s templates/ingress.yaml --set global.ingress.className=someotherclass

---
# Source: keep/templates/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: keep-ingress
  labels:
    helm.sh/chart: keep-0.1.34
    app.kubernetes.io/name: keep
    app.kubernetes.io/instance: keep
    app.kubernetes.io/version: "0.28.4"
    app.kubernetes.io/managed-by: Helm
  annotations:
spec:
  ingressClassName: someotherclass
  rules:
    - http:
        paths:
        - path: /websocket(/|$)(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: keep-websocket
              port:
                number: 6001
        - path: /v2(/|$)(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: keep-backend
              port:
                number: 8080
        - path: /(.*)
          pathType: ImplementationSpecific
          backend:
            service:
              name: keep-frontend
              port:
                number: 3000

@shahargl
Copy link
Member

@guy-frontegg yea because I thought I understand what's the problem but while debugging it I find out I didn't ^^

@shahargl
Copy link
Member

Oh, you DO want nginx configuration, but for other class name.

@shahargl
Copy link
Member

Fixing.

@guy-frontegg
Copy link
Author

Yes,
I could have done it but you don't allow PR's :)

@shahargl
Copy link
Member

Yes, I could have done it but you don't allow PR's :)

We are welcoming PR's! I'll check why you didn't manage to create one :(
Meanwhile - merged.

@guy-frontegg

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 a pull request may close this issue.

2 participants