diff --git a/examples/ingress-one-to-many.jsonnet b/examples/ingress-one-to-many.jsonnet index f5774af480c2b9133c4e052e3550c865d1d3aeec..96b28d418d73e7aab8a9e373a002a2bc9d932321 100644 --- a/examples/ingress-one-to-many.jsonnet +++ b/examples/ingress-one-to-many.jsonnet @@ -1,9 +1,17 @@ -local k = import 'ksonnet/ksonnet.beta.3/k.libsonnet'; -local secret = k.core.v1.secret; -local ingress = k.extensions.v1beta1.ingress; -local ingressTls = ingress.mixin.spec.tlsType; -local ingressRule = ingress.mixin.spec.rulesType; -local httpIngressPath = ingressRule.mixin.http.pathsType; +local ingress(name, namespace, rules) = { + apiVersion: 'networking.k8s.io/v1', + kind: 'Ingress', + metadata: { + name: name, + namespace: namespace, + annotations: { + 'nginx.ingress.kubernetes.io/auth-type': 'basic', + 'nginx.ingress.kubernetes.io/auth-secret': 'basic-auth', + 'nginx.ingress.kubernetes.io/auth-realm': 'Authentication Required', + }, + }, + spec: { rules: rules }, +}; local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + @@ -37,44 +45,65 @@ local kp = }, // Create one ingress object that routes to each individual application ingress+:: { - 'kube-prometheus': - ingress.new() + - ingress.mixin.metadata.withName('prometheus-k8s') + - ingress.mixin.metadata.withNamespace($._config.namespace) + - ingress.mixin.metadata.withAnnotations({ - 'nginx.ingress.kubernetes.io/auth-type': 'basic', - 'nginx.ingress.kubernetes.io/auth-secret': 'basic-auth', - 'nginx.ingress.kubernetes.io/auth-realm': 'Authentication Required', - }) + - ingress.mixin.spec.withRules([ - ingressRule.new() + - ingressRule.withHost('prometheus.dev.kepler-ops.io') + - ingressRule.mixin.http.withPaths( - httpIngressPath.new() + - httpIngressPath.mixin.backend.withServiceName('prometheus-k8s') + - httpIngressPath.mixin.backend.withServicePort('web') - ) , - ingressRule.withHost('alertmanager.example.com') + - ingressRule.mixin.http.withPaths( - httpIngressPath.new() + - httpIngressPath.mixin.backend.withServiceName('alertmanager-main') + - httpIngressPath.mixin.backend.withServicePort('web') - ), - ingressRule.withHost('grafana.example.com') + - ingressRule.mixin.http.withPaths( - httpIngressPath.new() + - httpIngressPath.mixin.backend.withServiceName('grafana') + - httpIngressPath.mixin.backend.withServicePort('http') - )] - ), + 'kube-prometheus': ingress( + 'kube-prometheus', + $._config.namespace, + [{ + host: 'alertmanager.example.com', + http: { + paths: [{ + backend: { + service: { + name: 'alertmanager-main', + port: 'web', + }, + }, + }], + }, + }, + { + host: 'grafana.example.com', + http: { + paths: [{ + backend: { + service: { + name: 'grafana', + port: 'http', + }, + }, + }], + }, + }, + { + host: 'alertmanager.example.com', + http: { + paths: [{ + backend: { + service: { + name: 'prometheus-k8s', + port: 'web', + }, + }, + }], + }, + },] + ), + }, } + { // Create basic auth secret - replace 'auth' file with your own ingress+:: { - 'basic-auth-secret': - secret.new('basic-auth', { auth: std.base64(importstr 'auth') }) + - secret.mixin.metadata.withNamespace($._config.namespace), - }, + 'basic-auth-secret': { + apiVersion: 'v1', + kind: 'Secret', + metadata: { + name: 'basic-auth', + namespace: $._config.namespace, + }, + data: { auth: std.base64(importstr 'auth') }, + type: 'Opaque', + }, + }, }; { [name + '-ingress']: kp.ingress[name] for name in std.objectFields(kp.ingress) }