exposecontroller

by Olli

Helm chartv1.0.5App v1.0.5Verified publisher

Controller for automatically exposing services. A more stable version of Jenkins-X exposecontroller.

About this chart

exposecontroller

Automatically expose services creating ingress rules or modifying services to use kubernetes nodePort or loadBalancer service types

This is a fork from the dead project https://github.com/jenkins-x/exposecontroller in order to solve many problems

Deployment

From helm repository

helm repo add olli-ai https://olli-ai.github.io/helm-charts/
helm upgrade --install exposecontroller olli-ai/exposecontroller

Using Helm

helm upgrade --install exposecontroller ./deploy/helm-chart/exposecontroller

Manual

# Create roles and service accounts
kubectl apply -f https://raw.githubusercontent.com/olli-ai/exposecontroller/master/deploy/rbac.yaml
# Create actual deployment
kubectl apply -f https://raw.githubusercontent.com/olli-ai/exposecontroller/master/deploy/deployment.yaml

In Jenkins-X environments

export VERSION=latest
# set the repository and version
sed '/\(- \|  \)name: exposecontroller/{n;N;d}' -i env/requirements.yaml
sed "s#\( *\)\(- \|  \)name: exposecontroller#\0\n\1  repository: https://olli-ai.github.io/helm-charts/\n\1  version: $VERSION#" \
  -i env/requirements.yaml
# add a name prefix for the ingress
sed -i 's/^\( *\)urltemplate:.*/\0\n\1namePrefix: exposed-/' env/values.yaml

In Jenkins-X applications for preview

export VERSION=latest
# set the repository and version
sed '/\(- \|  \)name: exposecontroller/{n;N;d}' -i charts/preview/requirements.yaml
sed "s#\( *\)\(- \|  \)name: exposecontroller#\0\n\1  repository: https://olli-ai.github.io/helm-charts/\n\1  version: $VERSION#" \
  -i charts/preview/requirements.yaml
# add a name prefix for the ingress
sed -i 's/^\( *\)urltemplate:.*/\0\n\1namePrefix: exposed-/' charts/preview/values.yaml

Differences with the original project

  • Update everything: the project was based on a very old version of golang and kubernetes, it didn't even have go mod.
  • Give up openshift: the openshift library hasn't been updated for 2 years, so give up it's support.
  • Test everything: there was almost no test, and definitely nothing critical was tested. Yes, something that is supposed to make public all your services was not tested.
  • Fix various bugs everywhere in the code.
  • Fix incoherent annotations.
  • Fix several severe bugs in ingress exposer:
    • ingresses were not properly updated when already existing, especially TLS configuration was not updated
    • the fabric8.io/ingress.annotations annotation was parsed using split, so spaces would be kept, an extra newline would result in panic, and it was impossible to set a multiline annotation
    • old ingresses would never be removed when changing the name of the ingress, or when the service is unexposed in run mode

Usage

You can expose any service with the annotation

metadata:
  annoations:
    fabric8.io/expose: "true"

The available exposers are:

The default and most versatile exposer is the Ingress exposer with nginx class. You can configure ingress annotations to your need:

metadata:
  annoations:
    fabric8.io/ingress.annotations: |
      kubernetes.io/ingress.class: nginx
      # SSL redirection
      nginx.ingress.kubernetes.io/ssl-redirect: "true"
      # basic auth
      nginx.ingress.kubernetes.io/auth-type: basic
      nginx.ingress.kubernetes.io/auth-secret: jx-basic-auth
      # auth through URL
      nginx.ingress.kubernetes.io/auth-url: http://my-auth-service/check
      nginx.ingress.kubernetes.io/auth-signin: https://my-auth-service.my-domain.com/singin?rd=https%3A%2F%2F$http_host$escaped_request_uri
      # Dynamic CORS Allow-Origin
      nginx.ingress.kubernetes.io/configuration-snippet: |
        # Check that the origin is allowed
        if ($http_origin ~ '\.my-domain\.com$') {
          set $allow_origin $http_origin;
        }
        if ($http_origin ~ '://localhost(:\d+)?$') {
          set $allow_origin $http_origin;
        }
        # Set CORS headers
        add_header 'Access-Control-Allow-Origin' $allow_origin always;
        add_header 'Access-Control-Allow-Credentials' 'true' always;
        add_header 'Access-Control-Allow-Methods' 'PUT, GET, POST, OPTIONS, DELETE' always;
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization' always;
        # Directly return before authentication in case of OPTIONS request
        if ($request_method = 'OPTIONS') {
          return 204;
        }

Helm configuration

You can configure the controller through helm values.

Helm parameterArgumentDefaultDescription
clean--cleanfalseClean exposed ingresses created by a previous run
daemon--daemonfalseRun as a daemon, exposing any cleaning any created or updated service
watchNamespaces--watch-namespaces""The namespace(s) to watch and expose services from
watchCurrentNamespace--watch-current-namespacetrueWatch the same namespace as the controller
config.exposer--exposer"ingress"The exposer to use, "ingress", "loadbalancer", "nodeport", "ambassador"
config.domain--domainThe domain to expose the services with
config.http--httpfalseExpose the URL with HTTP protocol even if HTTPS is vailable
config.internalDomainThe domain to expose services with the annotation fabric8.io/use.internal.domain: "true"
config.pathModeThe mode for the ingress paths. If "path", the services are exposed with the same domain but with / paths
config.ingressClassThe ingress class for ingresses
config.urltemplate"{{.Service}}.{{.Namespace}}.{{.Domain}}"The format for ingress host, if no path mode
config.tlsSecretNameThe name of an existing secret for TLS certificate
config.tlsacmefalseUse ACME to generate ingress TLS certificates
config.tlsUseWildcardfalseACME TLS certificates should use wildcard domain
config.namePrefix--name-prefix""The prefix to use for the created ingresses
config.extravaluesExtra YAML config
timeout--timeout"5m"The timeout for non-daemon run
resyncPeriod--resync-period"30m"The resync period for the service watcher
nameOverride{.Chart.Name}Overrides the name used in the label selector and the default name of the resources
fullnameOverride{.Release.Name}-{.Values.nameOverride}Overrides the name of the resources
annotationsThe annotations to pass to the job or deployment
argsAn array of extra arguments to pass to the controller
resources100m CPU / 128Mi RAMConfigures the resources of the pod
nodeSelectorConfigures the nodeSelector of the pod
tolerationsConfigures the tolerations of the pod
affinityConfigures the affinity of the pod

Service annotations

You can further configure the ingress by adding those annotations to the service.

Service annotationDefaultDescription
fabric8.io/expose"true" to expose this service
fabric8.io/ingress.nameservice's nameThe name of the ingress generated by the controller
fabric8.io/host.nameGenerated from URL templateThe hostname to use in the ingress
fabric8.io/exposePortfirst port availableThe port of the service to expose
fabric8.io/ingress.path"/"The path to use in the ingress
fabric8.io/path.modeThe mode for the ingres path. If "path", the services is exposed with the same domain but with <namespace>/<service> path
fabric8.io/ingress.annotationsAnnotations to pass to the ingress, YAML format
fabric8.io/use.internal.domainIf "true", uses the internal domain instead of the normal domain
jenkins-x.io/skip.tlsIf "true", ignores TLS configuration of the ambassador annotation
fabric8.io/exposeURLCreated by the controller, writes the URL to access to the exposed service
fabric8.io/exposeHostNameAsThe name of the annotation where the controller should write the exposed host

Export info to configmaps

You can export the exposed URL to configMaps by adding annotations in those configMaps.

| ConfigMap annotation | Description | |-------------------------------------------------

Deploy exposecontroller with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has exposecontroller on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartexposecontroller is pinned at v1.0.5 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply