From 72b40a3c6627de3688792724642cb51ff10f7dc8 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Sun, 28 Aug 2022 15:20:16 -0500 Subject: [PATCH] Add Listen Port to Ingress --- docs/kubernetes.md | 7 ++++++- helm/easyhaproxy/Chart.yaml | 2 +- helm/easyhaproxy/templates/deployment.yaml | 5 +++++ helm/easyhaproxy/values.yaml | 2 ++ src/processor/__init__.py | 5 ++++- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/kubernetes.md b/docs/kubernetes.md index 9063a85..bc20b63 100644 --- a/docs/kubernetes.md +++ b/docs/kubernetes.md @@ -33,6 +33,8 @@ There are two ways to install EasyHAProxy in a Kubernetes cluster. You can use K 3.1. Using Kubernetes Manifest ```bash +kubectl create namespace easyhaproxy + kubectl apply -f \ https://raw.githubusercontent.com/haproxytech/kubernetes-ingress/master/deploy/haproxy-ingress-daemonset.yaml ``` @@ -45,7 +47,7 @@ Minimal configuration ```bash helm repo add byjg https://opensource.byjg.com/helm -helm repo update +helm repo update byjg kubectl create namespace easyhaproxy helm upgrade --install ingress byjg/easyhaproxy \ --namespace easyhaproxy \ @@ -68,6 +70,8 @@ easyhaproxy: easyhaproxy: DEBUG haproxy: DEBUG +listen_extra_ports: [] + # Make sure to create this masterNode: label: easyhaproxy/node @@ -120,6 +124,7 @@ Caveats: | easyhaproxy.letsencrypt | (optional) Boolean. It will request letsencript certificates for the ingresses domains. | false | true or false | easyhaproxy.redirect | (optional) Json. Specific a domain and its destination. | *empty* | {"domain":"redirect_url"} | easyhaproxy.mode | (optional) Set the HTTP mode for that connection. | http | http or tcp +| easyhaproxy.listen_port | (optional) Set the an additional port for that ingress | http | http or tcp **Important**: The annotations are per ingress and applied to all hosts in that ingress configuration. diff --git a/helm/easyhaproxy/Chart.yaml b/helm/easyhaproxy/Chart.yaml index 7bc7817..eb5db7d 100644 --- a/helm/easyhaproxy/Chart.yaml +++ b/helm/easyhaproxy/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.0 +version: 0.1.1 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/helm/easyhaproxy/templates/deployment.yaml b/helm/easyhaproxy/templates/deployment.yaml index df86012..23d518e 100644 --- a/helm/easyhaproxy/templates/deployment.yaml +++ b/helm/easyhaproxy/templates/deployment.yaml @@ -43,6 +43,11 @@ spec: - name: stats containerPort: 1936 hostPort: 1936 + {{ range .Values.listen_extra_ports }} + - name: extra_{{ . }} + containerPort: {{ . }} + hostPort: {{ . }} + {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} env: diff --git a/helm/easyhaproxy/values.yaml b/helm/easyhaproxy/values.yaml index 2bf5a1e..907fe91 100644 --- a/helm/easyhaproxy/values.yaml +++ b/helm/easyhaproxy/values.yaml @@ -58,6 +58,8 @@ easyhaproxy: easyhaproxy: DEBUG haproxy: DEBUG +listen_extra_ports: [] + # Make sure to create this masterNode: label: easyhaproxy/node diff --git a/src/processor/__init__.py b/src/processor/__init__.py index ed4733c..0aee377 100644 --- a/src/processor/__init__.py +++ b/src/processor/__init__.py @@ -158,6 +158,9 @@ class Kubernetes(ProcessorInterface): redirect_ssl = self._check_annotation(ingress.metadata.annotations, "easyhaproxy.redirect_ssl") redirect = self._check_annotation(ingress.metadata.annotations, "easyhaproxy.redirect") mode = self._check_annotation(ingress.metadata.annotations, "easyhaproxy.mode") + listen_port = self._check_annotation(ingress.metadata.annotations, "easyhaproxy.listen_port") + if listen_port is None: + listen_port = 80 data = {} data["creation_timestamp"] = ingress.metadata.creation_timestamp.strftime("%x %X") @@ -191,7 +194,7 @@ class Kubernetes(ProcessorInterface): port_number = rule.http.paths[0].backend.service.port.number definition = "easyhaproxy.%s_%s" % (rule.host.replace(".", "-"), port_number) rule_data["%s.host" % (definition)] = rule.host - rule_data["%s.port" % (definition)] = "80" + rule_data["%s.port" % (definition)] = listen_port rule_data["%s.localport" % (definition)] = port_number if rule.host in ssl_hosts: rule_data["%s.clone_to_ssl" % (definition)] = 'true'