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 ingress for model access #2536

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Parameter | Description | Default
`ingress.paths` | Ingress paths | `["/"]`
`ingress.hosts` | Ingress hostnames | `[cost-analyzer.local]`
`ingress.tls` | Ingress TLS configuration (YAML) | `[]`
`kubecostModel.ingress.*` | Same as ingress.*, but will create an ingress directly to the model | `{ enabled: false }`
`networkPolicy.enabled` | If true, create a NetworkPolicy to deny egress | `false`
`networkCosts.enabled` | If true, collect network allocation metrics [More info](http://docs.kubecost.com/network-allocation) | `false`
`networkCosts.podMonitor.enabled` | If true, a [PodMonitor](https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#podmonitor) for the network-cost daemonset is created | `false`
Expand Down
66 changes: 66 additions & 0 deletions cost-analyzer/templates/model-ingress-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{- if .Values.kubecostModel.ingress -}}
{{- if .Values.kubecostModel.ingress.enabled -}}
{{- $fullName := include "cost-analyzer.fullname" . -}}
{{- $serviceName := include "cost-analyzer.serviceName" . -}}
{{- $ingressPaths := .Values.kubecostModel.ingress.paths -}}
{{- $ingressPathType := .Values.kubecostModel.ingress.pathType -}}
{{- $apiV1 := false -}}
{{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare "^1.19-0" .Capabilities.KubeVersion.GitVersion) }}
{{- $apiV1 = true -}}
apiVersion: networking.k8s.io/v1
{{ else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
apiVersion: networking.k8s.io/v1beta1
{{ else }}
apiVersion: extensions/v1beta1
{{ end -}}
kind: Ingress
metadata:
name: {{ $fullName }}-model
namespace: {{ .Release.Namespace }}
labels:
{{ include "cost-analyzer.commonLabels" . | nindent 4 }}
{{- with .Values.kubecostModel.ingress.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.kubecostModel.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.kubecostModel.ingress.className }}
ingressClassName: {{ .Values.kubecostModel.ingress.className }}
{{- end }}
{{- if .Values.kubecostModel.ingress.tls }}
tls:
{{- range .Values.kubecostModel.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.kubecostModel.ingress.hosts }}
- host: {{ . | quote }}
http:
paths:
{{- range $ingressPaths }}
{{- if $apiV1 }}
- path: {{ . }}
pathType: {{ $ingressPathType }}
backend:
service:
name: {{ $serviceName }}
port:
name: tcp-model
{{- else }}
- path: {{ . }}
backend:
serviceName: {{ $serviceName }}
servicePort: tcp-model
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
20 changes: 20 additions & 0 deletions cost-analyzer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,26 @@ kubecostModel:
failureThreshold: 200
extraArgs: []

# creates an ingress directly to the model container, for API access
ingress:
enabled: false
# className: nginx
labels:
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
annotations:
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
paths: ["/"]
pathType: ImplementationSpecific
hosts:
- cost-analyzer-model.local
tls: []
# - secretName: cost-analyzer-model-tls
# hosts:
# - cost-analyzer-model.local


# Basic Kubecost ingress, more examples available at https://github.com/kubecost/docs/blob/main/ingress-examples.md
ingress:
enabled: false
Expand Down